/* Test TimeStampTZ with no zone set */ public void testNoZone() { int year = 2000, month = 1, date = 10, hour = 11, minute = 21, second = 31; Integer tsId = null; java.util.Calendar originalCal = null, dbCal = null; EntityManager em = createEntityManager("timestamptz"); beginTransaction(em); try { TStamp ts = new TStamp(); originalCal = java.util.Calendar.getInstance(); originalCal.set(year, month, date, hour, minute, second); ts.setNoZone(originalCal); em.persist(ts); em.flush(); tsId = ts.getId(); commitTransaction(em); } catch (Exception e) { e.printStackTrace(); rollbackTransaction(em); } finally { clearCache(); dbCal = em.find(TStamp.class, tsId).getNoZone(); closeEntityManager(em); } assertEquals("The date retrived from db is not the one set to the child ", dbCal, originalCal); assertTrue("The year is not macth", year == dbCal.get(java.util.Calendar.YEAR)); assertTrue("The month is not match", month == dbCal.get(java.util.Calendar.MONTH)); assertTrue("The date is not match", date == dbCal.get(java.util.Calendar.DATE)); assertTrue("The hour is not match", hour == dbCal.get(java.util.Calendar.HOUR)); assertTrue("The minute is not match", minute == dbCal.get(java.util.Calendar.MINUTE)); assertTrue("The second is not match", second == dbCal.get(java.util.Calendar.SECOND)); }
/* Test TimeStampLTZ */ public void testTimeStampLTZ() { int year = 2000, month = 3, date = 21, hour = 11, minute = 45, second = 50; Integer tsId = null; Calendar originalCal = null, dbCal = null; String zoneId = "America/Los_Angeles"; EntityManager em = createEntityManager("timestamptz"); beginTransaction(em); try { TStamp ts = new TStamp(); originalCal = Calendar.getInstance(TimeZone.getTimeZone(zoneId)); originalCal.set(Calendar.AM_PM, Calendar.AM); originalCal.set(year, month, date, hour, minute, second); originalCal.set(Calendar.MILLISECOND, 0); ts.setTsLTZ(originalCal); em.persist(ts); em.flush(); tsId = ts.getId(); commitTransaction(em); } catch (Exception e) { e.printStackTrace(); rollbackTransaction(em); } finally { clearCache(); dbCal = em.find(TStamp.class, tsId).getTsLTZ(); closeEntityManager(em); } assertTrue("The year is not macth", year == dbCal.get(java.util.Calendar.YEAR)); assertTrue("The month is not match", month == dbCal.get(java.util.Calendar.MONTH)); assertTrue("The date is not match", date == dbCal.get(java.util.Calendar.DATE)); int hourDiffFromDB = dbCal.get(Calendar.HOUR_OF_DAY) - originalCal.get(Calendar.HOUR_OF_DAY); int hourDiffFromZone = (dbCal.get(Calendar.ZONE_OFFSET) - originalCal.get(Calendar.ZONE_OFFSET)) / 3600000; assertTrue("The hour is not match", hourDiffFromDB == hourDiffFromZone); assertTrue("The minute is not match", minute == dbCal.get(java.util.Calendar.MINUTE)); assertTrue("The second is not match", second == dbCal.get(java.util.Calendar.SECOND)); }