Search in sources :

Example 11 with JDateTime

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

the class JDateTimeConverterTest method testConversion.

@Test
public void testConversion() {
    assertNull(jDateTimeConverter.convert(null));
    assertEquals(new JDateTime(2010, 10, 10), jDateTimeConverter.convert(new JDateTime(2010, 10, 10)));
    assertEquals(new JDateTime(123456), jDateTimeConverter.convert(Integer.valueOf(123456)));
    assertEquals(new JDateTime(2010, 10, 20, 10, 11, 12, 456), jDateTimeConverter.convert("2010-10-20 10:11:12.456"));
}
Also used : JDateTime(jodd.datetime.JDateTime) Test(org.junit.Test)

Example 12 with JDateTime

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

the class JDateTimeConverterTest method testLoadFromStoreTo.

@Test
public void testLoadFromStoreTo() {
    Calendar c = Calendar.getInstance();
    c.set(2001, 0, 1, 2, 3, 4);
    c.set(Calendar.MILLISECOND, 500);
    JDateTime jdt = Convert.toJDateTime(c);
    assertEquals("2001-01-01 02:03:04.500", jdt.toString());
    Calendar c1 = Convert.toCalendar(jdt);
    assertEquals(2001, c1.get(Calendar.YEAR));
    assertEquals(0, c1.get(Calendar.MONTH));
    assertEquals(1, c1.get(Calendar.DAY_OF_MONTH));
    assertEquals(2, c1.get(Calendar.HOUR_OF_DAY));
    assertEquals(3, c1.get(Calendar.MINUTE));
    assertEquals(4, c1.get(Calendar.SECOND));
    assertEquals(500, c1.get(Calendar.MILLISECOND));
    GregorianCalendar gc = new GregorianCalendar(2002, 5, 2, 3, 4, 5);
    gc.set(GregorianCalendar.MILLISECOND, 600);
    jdt = Convert.toJDateTime(gc);
    assertEquals("2002-06-02 03:04:05.600", jdt.toString());
    GregorianCalendar gc1 = (GregorianCalendar) Convert.toCalendar(jdt);
    assertEquals(2002, gc1.get(GregorianCalendar.YEAR));
    assertEquals(5, gc1.get(GregorianCalendar.MONTH));
    assertEquals(2, gc1.get(GregorianCalendar.DAY_OF_MONTH));
    assertEquals(3, gc1.get(GregorianCalendar.HOUR_OF_DAY));
    assertEquals(4, gc1.get(GregorianCalendar.MINUTE));
    assertEquals(5, gc1.get(GregorianCalendar.SECOND));
    assertEquals(600, gc1.get(GregorianCalendar.MILLISECOND));
    Date d = new Date(101, 2, 3, 4, 5, 6);
    jdt = Convert.toJDateTime(d);
    assertEquals("2001-03-03 04:05:06.000", jdt.toString());
    Date d2 = Convert.toDate(jdt);
    assertEquals(101, d2.getYear());
    assertEquals(2, d2.getMonth());
    assertEquals(3, d2.getDate());
    assertEquals(4, d2.getHours());
    assertEquals(5, d2.getMinutes());
    assertEquals(6, d2.getSeconds());
    JDateTime gt_new = new JDateTime(2003, 6, 5, 4, 3, 2, 100);
    jdt.setJulianDate(gt_new.getJulianDate());
    assertEquals("2003-06-05 04:03:02.100", jdt.toString());
    JDateTime gt2 = jdt.clone();
    assertEquals(2003, gt2.getYear());
    assertEquals(6, gt2.getMonth());
    assertEquals(5, gt2.getDay());
    assertEquals(4, gt2.getHour());
    assertEquals(3, gt2.getMinute());
    assertEquals(2, gt2.getSecond());
    assertEquals(100, gt2.getMillisecond());
    java.sql.Date sd = new java.sql.Date(123, 4, 5);
    jdt = Convert.toJDateTime(sd);
    assertEquals("2023-05-05 00:00:00.000", jdt.toString());
    java.sql.Date sd2 = new java.sql.Date(1, 2, 3);
    SqlDateConverter sqlDateConverter = new SqlDateConverter();
    sd2 = sqlDateConverter.convert(jdt);
    assertEquals(123, sd2.getYear());
    assertEquals(4, sd2.getMonth());
    assertEquals(5, sd2.getDate());
    Timestamp st = new Timestamp(123, 4, 5, 6, 7, 8, 500000000);
    jdt = Convert.toJDateTime(st);
    assertEquals("2023-05-05 06:07:08.500", jdt.toString());
    SqlTimestampConverter sqlTimestampConverter = new SqlTimestampConverter();
    Timestamp st2 = sqlTimestampConverter.convert(jdt);
    assertEquals(123, st2.getYear());
    assertEquals(4, st2.getMonth());
    assertEquals(5, st2.getDate());
    assertEquals(6, st2.getHours());
    assertEquals(7, st2.getMinutes());
    assertEquals(8, st2.getSeconds());
    assertEquals(500, st2.getNanos() / 1000000);
}
Also used : SqlTimestampConverter(jodd.typeconverter.impl.SqlTimestampConverter) SqlDateConverter(jodd.typeconverter.impl.SqlDateConverter) Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) JDateTime(jodd.datetime.JDateTime) GregorianCalendar(java.util.GregorianCalendar) Timestamp(java.sql.Timestamp) Date(java.util.Date) Test(org.junit.Test)

Example 13 with JDateTime

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

the class SqlDateConverterTest method testJDateTime2SqlDate.

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

Example 14 with JDateTime

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

the class SqlTimestampConverterTest method testJDateTime2Timestamp.

@Test
public void testJDateTime2Timestamp() {
    JDateTime jdt = new JDateTime(time);
    Timestamp timestamp = sqlTimestampConverter.convert(jdt);
    assertEquals(time, timestamp.getTime());
}
Also used : JDateTime(jodd.datetime.JDateTime) Timestamp(java.sql.Timestamp) Test(org.junit.Test)

Example 15 with JDateTime

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

the class ProxyInfoTest method testProxyInfo_createNotRightAfterTheMethod.

@Test
public void testProxyInfo_createNotRightAfterTheMethod() {
    ProxyProxetta proxetta = ProxyProxetta.withAspects(aspects());
    //proxetta.setDebugFolder(SystemUtil.userHome());
    DateDao dateDateProxy = (DateDao) proxetta.builder(DateDao.class).newInstance();
    JDateTime jDateTime = dateDateProxy.currentTime();
    assertNotNull(jDateTime);
}
Also used : ProxyProxetta(jodd.proxetta.impl.ProxyProxetta) JDateTime(jodd.datetime.JDateTime) DateDao(jodd.proxetta.data.DateDao) 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