[ftputil] Converting 12am and 12pm to 24-clock format

Stefan Schwarzer sschwarzer at sschwarzer.net
Sat May 9 14:27:47 CEST 2009


Hello,

I've always used to think that if you have a 12-hour time with
"PM" at the end, you could add 12 hours to get to 24-hour clock
(e. g. 01:23PM -> 13:23). In ftputil, the MS parser for directory
lines assumes this.

Now, reading the Wikipedia article on 12-hour clock [1], it seems
that things are different for the hour 12:

"""
Time in digital equipment

If a 12-hour time format is set, Microsoft Windows and Office
applications denote noon by "12 pm" and midnight by "12 am".
"""

So "12:23PM" -> 12:23 and "12:23AM" -> 00:23, right? Is that also
true for the listings of Microsoft FTP server products? I hope
there aren't any changes to the date to apply at 12:xxAM. So I'd
have these conversions from date/time strings to Python time
tuples:

04-17-09 12:08AM -> (2009, 4, 17, 0, 8, 0, ...)
04-17-09 12:08PM -> (2009, 4, 17, 12, 8, 0, ...)

Can anyone confirm this (or not), please?

Assuming that I understand the Wikipedia article correctly and
things are also like this for Microsoft's FTP server, I'd patch
ftp_stat.py thusly:

$ svn di ftp_stat.py
Index: ftp_stat.py
===================================================================
--- ftp_stat.py (revision 861)
+++ ftp_stat.py (working copy)
@@ -232,7 +232,9 @@
             hour, minute = int(hour), int(minute)
         except (ValueError, IndexError):
             raise ftp_error.ParserError("invalid time string '%s'" % time_)
-        if am_pm == 'P':
+        if am_pm == 'A' and hour == 12:
+            hour = 0
+        if am_pm == 'P' and hour != 12:
             hour = hour + 12
         st_mtime = time.mktime( (year, month, day,
                                  hour, minute, 0, 0, 0, -1) )

Do you agree?

It would be nice if I got an answer soon, so I could include this
fix in an ftputil 2.4.1 release on this weekend. :-)

[1] http://en.wikipedia.org/wiki/12-hour_clock#Time_in_digital_equipment

Best regards,
Stefan




More information about the ftputil mailing list