Issue Details (XML | Word | Printable)

Key: NET-51
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: Unassigned
Reporter: Dieter Müller
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
Commons Net

NTFTPEntryParser wrong parsing of timestamp 12:24 PM

Created: 20/Feb/04 01:47 AM   Updated: 20/Sep/07 05:31 AM
Return to search
Component/s: None
Affects Version/s: 1.1
Fix Version/s: None

Time Tracking:
Not Specified

File Attachments:
  Size
Text File CalendarBug.py 2004-03-10 11:08 AM Steve Cohen 0.6 kB
Text File jakarta-commons-net_bug-27085.diff 2004-03-10 02:58 AM Brian Cox 2 kB
Environment:
Operating System: other
Platform: Other

Bugzilla Id: 27085


 Description  « Hide
e.g. raw Data: "02-19-04 12:24PM 10728307 FAUSLSILVS.00001"
will result in date: Fri Feb 20 00:24:00 CET 2004
but should be: Thu Feb 19 12:24:00 CET 2004.

Yours,
Dieter Müller



 All   Comments   Work Log   Change History   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
Brian Cox added a comment - 10/Mar/04 02:55 AM
As far as I can tell, the acceptable range of values for the HOUR field of the
java.util.Calendar instance returned by Calendar.getInstance() is 0 to 11. The
parseFTPEntry method of NTFTPEntryParser feeds the parsed hour component of the
FTP entry's timestamp as-is to the Calendar's HOUR field, which causes the
resulting Calendar value to "skip ahead" 12 hours from the intended value.
Note that, for example, raw data:

"02-19-04 12:24AM 10728307 FAUSLSILVS.00001"

results in Thu Feb 19 12:24:00 2004 rather than Thu Feb 19 00:24:00 2004.


Brian Cox added a comment - 10/Mar/04 02:58 AM
Created an attachment (id=10726)
Filter the parsed hour component to the range 0 .. 11; Add test cases for hour component of 12AM and 12PM

Steve Cohen added a comment - 10/Mar/04 11:08 AM
Created an attachment (id=10738)
Jython script illustrating bug in java.Calendar

Steve Cohen added a comment - 10/Mar/04 11:13 AM
I think you're right; I think this is a bug in java, or at least an undocumented feature since the
0-11 requirement for Calendar.HOUR is not in the javadocs. I just attached a jython script
demonstrating this. (Jython is great for testing java classes this way). The script creates a
Calendar, clears it, then sets its fields one by one. After each set the internals of the Calendar
are printed out. All looks well until getTime() is called, after which the internals are messed up.

I will shortly commit a fix to this problem. The fix will replace the use of Calendar.HOUR with
Calendar.HOUR_OF_DAY which is much more reliable. But I have to do all the work myself,
which sort of defeats the whole purpose of Calendar.

I wonder how long this has been around.


Steve Cohen added a comment - 10/Mar/04 11:40 AM
changed to figure 12:00 am and pm manually, and use Calendar.HOUR_OF_DAY instead of
Calendar.HOUR, due to what appears to be a bug in java.Calendar.

Steve Cohen added a comment - 10/Mar/04 11:41 AM
also note that test updated to check for this. Previously this problem wasn't tested.