use of jodd.datetime.JDateTime in project jodd by oblac.
the class TimeBeforeConstraintTest method testIsValid.
@Test
public void testIsValid() {
JDateTime time = new JDateTime("2011-05-01 10:11:12.344");
TimeBeforeConstraint constraint = new TimeBeforeConstraint(time.clone());
assertFalse("result must be true when validate time which is equal to constraint time", constraint.isValid(mockContext(), time.clone()));
assertTrue("result must be false when validate time which is less than constraint time", constraint.isValid(mockContext(), time.clone().subMinute(1)));
assertFalse("result must be true when validate time which is greater than constraint time", constraint.isValid(mockContext(), time.clone().addMinute(1)));
}
use of jodd.datetime.JDateTime in project jodd by oblac.
the class TimeBeforeConstraintTest method testSetTime.
@Test
public void testSetTime() {
TimeBeforeConstraint timeBeforeConstraint = new TimeBeforeConstraint();
JDateTime time = new JDateTime();
timeBeforeConstraint.setTime(time);
assertEquals("method must return the same time as was given to set method", timeBeforeConstraint.getTime(), time);
}
use of jodd.datetime.JDateTime in project hive by apache.
the class NanoTimeUtils method getTimestamp.
public static Timestamp getTimestamp(NanoTime nt, boolean skipConversion) {
int julianDay = nt.getJulianDay();
long nanosOfDay = nt.getTimeOfDayNanos();
long remainder = nanosOfDay;
julianDay += remainder / NANOS_PER_DAY;
remainder %= NANOS_PER_DAY;
if (remainder < 0) {
remainder += NANOS_PER_DAY;
julianDay--;
}
JDateTime jDateTime = new JDateTime((double) julianDay);
Calendar calendar = getCalendar(skipConversion);
calendar.set(Calendar.YEAR, jDateTime.getYear());
// java calendar index starting at 1.
calendar.set(Calendar.MONTH, jDateTime.getMonth() - 1);
calendar.set(Calendar.DAY_OF_MONTH, jDateTime.getDay());
int hour = (int) (remainder / (NANOS_PER_HOUR));
remainder = remainder % (NANOS_PER_HOUR);
int minutes = (int) (remainder / (NANOS_PER_MINUTE));
remainder = remainder % (NANOS_PER_MINUTE);
int seconds = (int) (remainder / (NANOS_PER_SECOND));
long nanos = remainder % NANOS_PER_SECOND;
calendar.set(Calendar.HOUR_OF_DAY, hour);
calendar.set(Calendar.MINUTE, minutes);
calendar.set(Calendar.SECOND, seconds);
Timestamp ts = new Timestamp(calendar.getTimeInMillis());
ts.setNanos((int) nanos);
return ts;
}
use of jodd.datetime.JDateTime in project hive by apache.
the class NanoTimeUtils method getNanoTime.
public static NanoTime getNanoTime(Timestamp ts, boolean skipConversion) {
Calendar calendar = getCalendar(skipConversion);
calendar.setTime(ts);
int year = calendar.get(Calendar.YEAR);
if (calendar.get(Calendar.ERA) == GregorianCalendar.BC) {
year = 1 - year;
}
JDateTime jDateTime = new JDateTime(year, // java calendar index starting at 1.
calendar.get(Calendar.MONTH) + 1, calendar.get(Calendar.DAY_OF_MONTH));
int days = jDateTime.getJulianDayNumber();
long hour = calendar.get(Calendar.HOUR_OF_DAY);
long minute = calendar.get(Calendar.MINUTE);
long second = calendar.get(Calendar.SECOND);
long nanos = ts.getNanos();
long nanosOfDay = nanos + NANOS_PER_SECOND * second + NANOS_PER_MINUTE * minute + NANOS_PER_HOUR * hour;
return new NanoTime(days, nanosOfDay);
}
use of jodd.datetime.JDateTime in project my_curd by qinyou.
the class ExcelHelper method buildExcelData.
/**
* @param sheet
* @param head
* @param dataList
*/
private void buildExcelData(Sheet sheet, ExcelHead head, List<?> dataList) {
List<ExcelColumn> excelColumns = head.getColumns();
Map<String, Map> excelHeadConvertMap = head.getColumnsConvertMap();
// 将表结构转换成Map
Map<Integer, String> excelHeadMap = convertExcelHeadToMap(excelColumns);
// 从第几行开始插入数据
int startRow = head.getRowCount();
int order = 1;
for (Object obj : dataList) {
Row row = sheet.createRow(startRow++);
for (int j = 0; j < excelColumns.size(); j++) {
Cell cell = row.createCell(j);
cell.setCellType(excelColumns.get(j).getType());
String fieldName = excelHeadMap.get(j);
if (fieldName != null) {
Object valueObject = BeanUtil.getProperty(obj, fieldName);
// 如果存在需要转换的字段信息,则进行转换
if (excelHeadConvertMap != null && excelHeadConvertMap.get(fieldName) != null) {
valueObject = excelHeadConvertMap.get(fieldName).get(valueObject);
}
if (valueObject == null) {
cell.setCellValue("");
} else if (valueObject instanceof Integer) {
cell.setCellValue((Integer) valueObject);
} else if (valueObject instanceof String) {
cell.setCellValue((String) valueObject);
} else if (valueObject instanceof Date) {
cell.setCellValue(new JDateTime((Date) valueObject).toString("YYYY-MM-DD"));
} else {
cell.setCellValue(valueObject.toString());
}
} else {
cell.setCellValue(order++);
}
}
}
}
Aggregations