-
-
Notifications
You must be signed in to change notification settings - Fork 30.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
24:00 Hour in DateTime #54636
Comments
Short: from the python doc: "class datetime.datetime(year, month, day[, hour[, minute[, second[, from http://en.wikipedia.org/wiki/ISO_8601 : "ISO 8601 uses the 24-hour clock system. The basic format is
The use of 24:00 is very comfortable when using hourly datasets, the Actually in another part of Python SQLlite's date and time functions accept and outputs the 24:00. Adding some Python to an existing database made me aware of the problem. |
+1 Note that in Python, semi-open intervals are favored, but specifying the last hour of the day is awkward when using datetime (as OP mentioned) and impossible using just time. Using closed intervals is not a good work-around in many cases because it requires the user to be explicit about precision: is the last hour [23:00-23:59], [23:00:00-23:59:00], or [23:00:00.999999-23:59:00.999999]? I offer to write the patch for the C implementation if someone comes up with a patch for datetime.py including tests. |
I was writing tests for this issue, when something struck me: ok, datetime(year, month, day, 24) is valid. But is datetime(year, month, day, 24, 1) valid? Or datetime(year, month, day, 24, 0, 0, 1)? I would say those aren't valid, although that makes checking forvalid hour values slightly weird (as in not straightforward): 24 is valid if minutes, seconds and microseconds are all 0, but invalid otherwise. What do you think? |
On Sun, Nov 21, 2010 at 7:24 PM, Rodrigo Bernardo Pimentel wrote:
Indeed anything beyond 24:0:0 is invalid ingo |
On Sun, Nov 21, 2010 at 1:24 PM, Rodrigo Bernardo Pimentel
As you make progress on the patch, you will face more questions. For On your original question, I feel that hour=24 should be allowed |
Well, if all that's wanted is for hour==24 to be legal on input, with the datetime object itself being automatically normalized at creation time, then the choices seem simple: e.g.,
The latter, since the two datetime objects would be indistinguishable...
I'd say yes, provided that any minute, second or subsecond fields are all zero. FWIW, I'm in the camp that says hour==24 should only be legal if all values for smaller time units are zero. If a datetime object created with 'hour==24' doesn't immediately normalize itself, then I agree there are going to be a lot of hairy questions... |
On Sun, Nov 21, 2010 at 3:48 PM, Mark Dickinson <[email protected]> wrote:
What about time objects? If we take the "normalized at creation time" |
Yes, I guess that would follow. That wouldn't bother me too much. :-) |
Is there still interest in pursuing this? Normalizing out of bounds arguments to datetime constructor is easy, but rather pointless. It is trivial to implement this functionality using existing timedelta constructor: def normdatetime(Y, M, D, h, m, s):
return datetime(Y, M, D) + timedelta(hours=h, minutes=m, seconds=s) It would be much more interesting to allow datetime objects to store ISO 8601 data without loss of information. It may be important to some applications that datetime(Y, M, D, 24).date() is date(Y, M, D) rather than the next day. Other applications may want to distinguish between datetime(Y, M, D, 24) and datetime(Y, M, D) + timedelta(1) in some other ways. For leap seconds accounting, normalizing ISO 8601 timestamps with seconds=60 to the next minute is certainly wrong. An application that is unfortunate enough to record data during a leap second would clearly want to distinguish that data from data recorded a second later. I believe that from practical applications point of view, it would be best to allow storing hour=24 and second=60 in datetime structure and order the resulting objects in the same way as ISO 8601 strings are ordered alphabetically. In other words, Y-M-D 24:00 < Y-M-D+1 00:00 and Y-M-D 23:59:60 < Y-M-D+1 00:00:00. There is no sane choice for subtraction operation involving these special values or for adding timedeltas to them. It is probably best to raise an exception in those cases. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: