cal.setTimeZone(TimeZone.getTimeZone("GMT"));
Timestamp ts = new Timestamp(cal.getTimeInMillis());
ts.setNanos(1);
//(1*60*60 + 1*60 + 1) * 10e9 + 1
NanoTime nt = NanoTimeUtils.getNanoTime(ts);
Assert.assertEquals(nt.getTimeOfDayNanos(), 3661000000001L);
//case 2: 23:59:59.999999999
cal = Calendar.getInstance();
cal.set(Calendar.YEAR, 1968);
cal.set(Calendar.MONTH, Calendar.MAY);
cal.set(Calendar.DAY_OF_MONTH, 23);
cal.set(Calendar.HOUR_OF_DAY, 23);
cal.set(Calendar.MINUTE, 59);
cal.set(Calendar.SECOND, 59);
cal.setTimeZone(TimeZone.getTimeZone("GMT"));
ts = new Timestamp(cal.getTimeInMillis());
ts.setNanos(999999999);
//(23*60*60 + 59*60 + 59)*10e9 + 999999999
nt = NanoTimeUtils.getNanoTime(ts);
Assert.assertEquals(nt.getTimeOfDayNanos(), 86399999999999L);
//case 3: verify the difference.
Calendar cal2 = Calendar.getInstance();
cal2.set(Calendar.YEAR, 1968);
cal2.set(Calendar.MONTH, Calendar.MAY);
cal2.set(Calendar.DAY_OF_MONTH, 23);
cal2.set(Calendar.HOUR_OF_DAY, 0);
cal2.set(Calendar.MINUTE, 10);
cal2.set(Calendar.SECOND, 0);
cal2.setTimeZone(TimeZone.getTimeZone("GMT"));
Timestamp ts2 = new Timestamp(cal2.getTimeInMillis());
ts2.setNanos(10);
Calendar cal1 = Calendar.getInstance();
cal1.set(Calendar.YEAR, 1968);
cal1.set(Calendar.MONTH, Calendar.MAY);
cal1.set(Calendar.DAY_OF_MONTH, 23);
cal1.set(Calendar.HOUR_OF_DAY, 0);
cal1.set(Calendar.MINUTE, 0);
cal1.set(Calendar.SECOND, 0);
cal1.setTimeZone(TimeZone.getTimeZone("GMT"));
Timestamp ts1 = new Timestamp(cal1.getTimeInMillis());
ts1.setNanos(1);
NanoTime n2 = NanoTimeUtils.getNanoTime(ts2);
NanoTime n1 = NanoTimeUtils.getNanoTime(ts1);
Assert.assertEquals(n2.getTimeOfDayNanos() - n1.getTimeOfDayNanos(), 600000000009L);
}