Search in sources :

Example 21 with JDateTime

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)));
}
Also used : JDateTime(jodd.datetime.JDateTime) Test(org.junit.Test)

Example 22 with JDateTime

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);
}
Also used : JDateTime(jodd.datetime.JDateTime) Test(org.junit.Test)

Example 23 with JDateTime

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;
}
Also used : Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) JDateTime(jodd.datetime.JDateTime) Timestamp(java.sql.Timestamp)

Example 24 with JDateTime

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);
}
Also used : Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) JDateTime(jodd.datetime.JDateTime)

Example 25 with JDateTime

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++);
            }
        }
    }
}
Also used : JDateTime(jodd.datetime.JDateTime)

Aggregations

JDateTime (jodd.datetime.JDateTime)38 Test (org.junit.Test)28 Calendar (java.util.Calendar)10 GregorianCalendar (java.util.GregorianCalendar)8 Date (java.util.Date)6 Timestamp (java.sql.Timestamp)5 BigDecimal (java.math.BigDecimal)3 BigInteger (java.math.BigInteger)2 Time (java.sql.Time)2 DbSession (jodd.db.DbSession)2 CellReference (org.apache.poi.hssf.util.CellReference)2 XSSFWorkbook (org.apache.poi.xssf.usermodel.XSSFWorkbook)2 File (java.io.File)1 Date (java.sql.Date)1 DateFormat (java.text.DateFormat)1 SimpleDateFormat (java.text.SimpleDateFormat)1 DateTimeStamp (jodd.datetime.DateTimeStamp)1 DbThreadSession (jodd.db.DbThreadSession)1 Area (jodd.json.model.cat.Area)1 Event (jodd.json.model.cat.Event)1