Re: Discrepancy in current hour
On Mar 20, 8:54 pm, Lew <no...@lewscanon.com> wrote:
Rhino wrote:
public void testGetCurrentHour12() {
//TODO: why does this method return 9 (PM) when it is actually 8 in
this time zone right now?
int currentHour = dateTimeUtils.getCurrentHour12HourClock();
int expectedHour = 8;
assertTrue("The actual hour (12 hour clock), " + currentHour + ",
does not equal the expected hour, " + expectedHour,
currentHour==expectedHour);
}
Just out of curiosity, if you put, just after the declaration of
'expectedHour', the line
Calendar calinst = Calendar.getInstance()
int calendarHour = calinst.get( Calendar.HOUR );
what does it give you?
While we're at it, what do
calinst.getTimeZone.getDisplayName()
and
calinst.getTimeZone.getOffset( calinst.getTimeInMillis() )
return?
After changing the expected result to one hour later than it actually
is, I amended the test case as follows:
-----------------------------------
public void testGetCurrentHour12() {
//TODO: why does this method return 9 (PM) when it is actually 8 in
this time zone right now?
int currentHour = dateTimeUtils.getCurrentHour12HourClock();
int expectedHour = 12;
assertTrue("The actual hour (12 hour clock), " + currentHour + ",
does not equal the expected hour, " + expectedHour,
currentHour==expectedHour); //$NON-NLS-1$ //$NON-NLS-2$
Calendar calinst = Calendar.getInstance();
int calendarHour = calinst.get( Calendar.HOUR );
System.out.println("calendarHour: " + calendarHour);
System.out.println("calinst.getTimeZone().getDisplayName() is: " +
calinst.getTimeZone().getDisplayName());
System.out.println("calinst.getTimeZone().getOffset(calinst.getTimeInMillis=
())
is: " + calinst.getTimeZone().getOffset( calinst.getTimeInMillis() ));
}
-----------------------------------
The result from executing it is:
-----------------------------------
calendarHour: 0
calinst.getTimeZone().getDisplayName() is: Eastern Standard Time
calinst.getTimeZone().getOffset(calinst.getTimeInMillis()) is:
-14400000
-----------------------------------
Are we agreed that these test cases are okay?
I wonder why you write a utility method to get the current hour when the
standard API already provides a one-line way to do so.
I must have missed that way in the standard API. Can you remind what
it is? I'm not sure which class you're thinking of....
--
Rhino