Search in sources :

Example 6 with JDateTime

use of jodd.datetime.JDateTime in project jodd by oblac.

the class CalendarConverterTest method testJDateTime2Calendar.

@Test
public void testJDateTime2Calendar() {
    JDateTime jdt = new JDateTime(time);
    Calendar calendar = calendarConverter.convert(jdt);
    assertEquals(time, calendar.getTimeInMillis());
}
Also used : Calendar(java.util.Calendar) JDateTime(jodd.datetime.JDateTime) Test(org.junit.Test)

Example 7 with JDateTime

use of jodd.datetime.JDateTime in project jodd by oblac.

the class CalendarConverterTest method testCalendarDate.

@Test
public void testCalendarDate() {
    JDateTime jdt = new JDateTime();
    CalendarConverter calendarConverter = new CalendarConverter();
    Calendar gc = calendarConverter.convert(jdt);
    DateFormat df = new SimpleDateFormat();
    assertEquals(df.format(gc.getTime()), df.format(Convert.toDate(jdt)));
}
Also used : CalendarConverter(jodd.typeconverter.impl.CalendarConverter) Calendar(java.util.Calendar) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) JDateTime(jodd.datetime.JDateTime) SimpleDateFormat(java.text.SimpleDateFormat) Test(org.junit.Test)

Example 8 with JDateTime

use of jodd.datetime.JDateTime in project jodd by oblac.

the class ConvertTest method testAllConversions.

@Test
public void testAllConversions() {
    assertEquals(new BigDecimal("11.2"), Convert.toBigDecimal("11.2"));
    assertNull(Convert.toBigDecimal(null));
    assertEquals(new BigInteger("123456789"), Convert.toBigInteger("123456789"));
    assertEquals(Boolean.TRUE, Convert.toBoolean(("true")));
    assertEquals(true, Convert.toBooleanValue("true", false));
    assertEquals(false, Convert.toBooleanValue(null, false));
    assertEquals(true, Convert.toBooleanValue("true"));
    assertEquals(false, Convert.toBooleanValue(null));
    assertNotNull(Convert.toCalendar((new JDateTime())));
    assertEquals(Character.valueOf('A'), Convert.toCharacter("A"));
    assertEquals('A', Convert.toCharValue("A", ' '));
    assertEquals('A', Convert.toCharValue("A"));
    assertEquals(Integer.class, Convert.toClass("java.lang.Integer"));
    assertEquals(Integer.class, Convert.toClassArray("java.lang.Integer")[0]);
    assertEquals(1, Convert.toClassArray("java.lang.Integer").length);
    assertNotNull(Convert.toDate(new JDateTime()));
    assertEquals(173, Convert.toIntValue("173"));
    assertEquals(173, Convert.toLongValue("173"));
    assertEquals(173, Convert.toShortValue("173"));
    assertEquals(17, Convert.toByteValue("17"));
    assertEquals(1.0d, Convert.toDouble("1").doubleValue(), 0.005);
    assertEquals(1.0d, Convert.toDoubleValue("1", 0), 0.005);
    assertEquals(1.0d, Convert.toDoubleValue("1"), 0.005);
    assertEquals(1.0f, Convert.toFloat("1").floatValue(), 0.005);
    assertEquals(1.0f, Convert.toFloatValue("1", 0), 0.005);
    assertEquals(1.0f, Convert.toFloat("1").floatValue(), 0.005);
    assertEquals(1.0f, Convert.toFloatValue("1"), 0.005);
    assertEquals(12, Convert.toInteger("12").intValue());
    assertNotNull(Convert.toJDateTime(new GregorianCalendar()));
    assertEquals(555, Convert.toLong("555").longValue());
    assertEquals(555, Convert.toShort("555").shortValue());
    assertEquals(55, Convert.toByte("55").byteValue());
    assertNotNull(Convert.toString("555"));
}
Also used : JDateTime(jodd.datetime.JDateTime) GregorianCalendar(java.util.GregorianCalendar) BigInteger(java.math.BigInteger) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 9 with JDateTime

use of jodd.datetime.JDateTime in project jodd by oblac.

the class DateConverterTest method testJDateTime2Date.

@Test
public void testJDateTime2Date() {
    JDateTime jdt = new JDateTime(time);
    Date date = dateConverter.convert(jdt);
    assertEquals(time, date.getTime());
}
Also used : JDateTime(jodd.datetime.JDateTime) Date(java.util.Date) Test(org.junit.Test)

Example 10 with JDateTime

use of jodd.datetime.JDateTime in project jodd by oblac.

the class JDateTimeConverterTest method testDate2JDateTime.

@Test
public void testDate2JDateTime() {
    Date date = new Date(time);
    JDateTime jdt = jDateTimeConverter.convert(date);
    assertEquals(time, jdt.getTimeInMillis());
}
Also used : JDateTime(jodd.datetime.JDateTime) Date(java.util.Date) Test(org.junit.Test)

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