Skip Menu |

This queue is for tickets about the Date-Manip CPAN distribution.

Report information
The Basics
Id: 91919
Status: resolved
Priority: 0/
Queue: Date-Manip

People
Owner: Nobody in particular
Requestors: EDAVIS [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: 6.42
Fixed in: (no value)



Subject: ParseDate to accept redundant 'am' and 'pm' when there is no ambiguity
At the moment '1:00pm' can be parsed, and so can '13:00', but '13:00pm' fails. I suggest that when 'pm' is given but 12 <= hh < 24, it be treated the same as if 'pm' had not been given. So '13:00pm' is the same as '13:00'. Note that '24:00pm' will continue to fail since it is not clear what this means. For 'am' we currently have an odd situation where '01:05am' is accepted but '00:05am' is not. I suggest that when hh == 0 the 'am' suffix should be allowed. Other cases should not change, in particular '13:00am' makes no sense.
I'm sorry, but the purpose of Date::Manip is to find valid dates. I've never seen any standard or even common-use practice where either: 13:00 PM 00:30 AM are valid. It would be easy to add support for this of course, but since I consider both of these invalid, I do not plan to do so. If you have software that is producing these times, I'm afraid that the proper solution is for you to sanitize the data before passing it to Date::Manip (probably by stripping out the AM/PM part). If you know of a standard that allows these dates, by all means send it to me and I'll reevaluate, but for now, sanitizing is the best option.
Thanks for your reply. Times such as these are not generated by any program, but they may be entered by people, particularly non-programmers. Date::Manip parses a great variety of date and time formats, including those which are possibly ambiguous or over-specified, and it does its best to cope with what the user entered provided it can be unambiguously converted to a date and time. I suggest that '13:00pm' is such an unambiguous string - we all understand what was intended. It is a bit peculiar that '01:00am' is allowed but '00:59am' is not, surely?
P.S. in my usage, Date::Manip *is* the date sanitizer, and I consider that its most useful feature!
Show quoted text
> It is a bit peculiar that '01:00am' is allowed but '00:59am' is not, > surely?
In 12-hour time, there is no 00 hour, so the fact that 00:59 doesn't exist in 12-hour time is not peculiar... it's expected. Likewise the fact that 13:00 doesn't exist in 12-hour time isn't peculiar either. These 'peculiarities' are simply pare of the definition of how the time is to be expressed. My goal with Date::Manip 6.xx is to handle every valid date operation. Given a valid date, I want to do every possible (or at least, every possible common) operation with it. But what if I have an invalid date? What is 5 hours after -03:00? I don't know because '-03:00' is not a valid date. It is true that I can reasonably guess what is meant by both '00:59 AM' and '13:00 PM'... but that doesn't change the fact that neither refer to valid dates. What you are asking for, in essence, is for me to extend Date::Manip to accept an invalid date and guess/infer/determine what valid date was being referred to. That's an operation that I have never set out to do, and one that I'm not terribly interested in. There's too much ambiguity in that problem. If a user supplies the date '13:00 PM', then, IMO, the correct response should be that your program says "Hey, that's not a valid time. Try again.". If you want to try to guess what the user was meaning, be my guess, but with very few exceptions (such as the one you present), you're not going to be able to do so. So, although I understand your suggestion (and as I said, it would actually be pretty easy to add), it's not something that I consider a valid extension of Date::Manip, so I'm going to pass on it.
Show quoted text
>In 12-hour time, there is no 00 hour,
Right, but these are not 12-hour times, they are 24-hour times where the user has redundantly added 'am' or 'pm' saying whether it is before or after noon. This is similar to saying ParseDate "2014-01-08 Wednesday" Here the user has given a well-known date format, but has redundantly added the information that this is a Wednesday, even though that could be inferred from the date. Date::Manip accepts this, rightly IMHO, and it rejects cases like "2014-01-08 Thursday" where the extra information conflicts with what's known. Similarly, 13:00 is a valid time, expressed in the 24 hour clock; 'pm' redundantly states that it is after midday. If the extra redundant information is consistent with what's already given it should be accepted; otherwise the string is invalid.