514 points · by rdpintqogeogsaa · 5y ago · 172 comments
https://stackoverflow.com/questions/127803/how-do-i-parse-an...
Parsing ISO 8601 formatted dates doesn't result in naive Python datetimes:
>>> datetime.fromisoformat("2021-10-24T20:17:41+02:00")
datetime.datetime(2021, 10, 24, 20, 17, 41, tzinfo=datetime.timezone(datetime.timedelta(seconds=7200)))from dateutil.parser import isoparse
> By mutual agreement of the partners in information interchange, the character [T] may be omitted in applications where there is no risk of confusing a date and time of day representation with others defined in this International Standard
[1] The actual ISO standard is not freely available, but the Library of Congress has free draft standards: https://www.loc.gov/standards/datetime/iso-tc154-wg5_n0038_i... https://www.loc.gov/standards/datetime/iso-tc154-wg5_n0039_i...
Regardless, ISO 8601 has generally discouraged using spaces within expressions. From ISO 8601:2004, section 3.4.1:
> Unless explicitly allowed by this International Standard the character "space" shall not be used in the representations.
Similarly, from ISO 8601:2019-1, section 3.2.1:
> The character "space" shall not be used in the expressions.
However, through looser interpretation of the standard, "2021-10-24 11:02:03Z" could be allowed if treated as a date representation followed by a space followed by a time representation (note that the formal time representation in ISO 8601:2019-1 is T11:02:03Z, but it allows omission of T for extended format as per 5.3.5).
That is, unless it's in a regulated industry that is required by law to follow the actual standard. Then it disobeys the law most of the time, and "disobey" the market the rest of the time and everything breaks. Also, it leaves the people with a secret law that nobody can know the consequences.
The ISO governance should be changed ASAP. It was never good, and nowadays it's a disaster.
Industries that are more reliant on ISO or other non-free standards are surely worse off because of it.
Yes, and? The draft standard is the pretty much everyone actually uses. For most purposes it's the "real" one.
It honestly seems like a racket. Businesses collaborate to write a standard that costs hundreds of dollars, and then brand new small businesses can’t afford to assert that they follow them.
Though iso isn't really spending its own money from what I can tell, so I don't see where their costs are coming from.
Historically, the purpose was to pay for printing & distribution. That makes no sense today, but that was its historical justification.
It reminds me of scientific journals that do nothing but charge money for other people’s work. It reeks of rent seeking.
https://catalog.nfpa.org/NFPA-70-National-Electrical-Code-wi...
In democracies it seems taxpayer money can only be had for purposes that please some fraction of the legislators.
There are only two possible representations for which "T" is required: hh or hhmm in 'basic' format (i.e. no ":" separator). The former could be confused with a two-digit century, the latter could be confused with a four-digit year. Adding "T" to hh or hhmm solves this.
Any of the following eliminates the "risk of confusion":
- 'extended' format (hh:mm)
- decimal fraction (hhmm,m or hh,h; see 5.3.1.4);
- UTC designator (hhmmZ or hhZ; see 5.3.3), or;
- time shift (hhmm±hhmm, hhmm±hh, hh±hhmm, or hh±hh; see 5.3.4).
Also worth noting: hhmmss in 'basic' format (i.e. no ":" separator) does not pose a risk of confusion, as YYYYMM in 'basic' format (i.e. no "-" separator) is not permitted by the spec.2022-05-01T16:00+1000
…but tomorrow’s government abolishes daylight savings time, your birthday event has to change to:
2022-05-01T16:00+0900.
If you’d just said:
2022-05-01T16:00 Asia/Eastern_Siberia
…you’d be fine and everyone will show up at the right time.
For the birthday party example: it's not a given that I want to reschedule it when the local time zone changes (maybe I want to meet before sundown so we can sit outside? in that case, I would want to adjust the local time, keeping the solar timethe same). Sometimes of course, it is desirable (think of the opening hours of a shop, for example), but that's a separate use case.
Similarly with online events involving international guests: if you move an event to keep the local time unchanged, this change might create conflicts on other people's calendars. It's not necessarily the desired outcome.
Another problem with including a time zone name is that not everybody has the same version of the time zone database. At worst, that means that different people will have different interpretations of which point in time is being described. At best, the result will only be eventually consistent.
Look up the Japanese calendar, if you want some fun: https://en.m.wikipedia.org/wiki/Date_and_time_notation_in_Ja...
My birthday party begins next year on May 1st when both our Siberian clocks say it is 4pm.
Then why support timezones at all? UTC-only is a much simpler way to denote fixed points in time; symbolic timezones are needed when you want to denote a human-friendly local timestamp. Numerical offsets are the worst of both worlds.
https://github.com/kstenerud/concise-encoding/blob/master/ce...
https://github.com/kstenerud/concise-encoding/blob/master/ct...
ISO 8601 and RFC 3339 are only useful for times in the past (which works fine for most internet protocols because they're only interested in recording events).
Using a date format for precise time types doesn't make much sense because human readable date formats are inherently tied to orbital mechanics[1] (days) and social constructs (timezones, calendars, laws, etc). Better to just record seconds from an epoch.
I see you mention leap seconds in your specification, but you don't address how to handle time in the future given that leap seconds can't be predicted more than 6mo in advance. This is a key feature of TAI -- no synchronization to earth's orbital mechanics. No leap seconds to keep the sun overhead at noon. This means your time spec will likely be off by seconds when using dates more than 6mo out. It seems like your format is also only useful for recording past dates.
[1] TAI is still tied to earth's frame of reference, of course. At some point when we get more serious about space, timestamps will need to include location and velocity. This is already a problem even on the scale of earth satellites and I don't think anyone's yet created a standard.
- The text format is designed for human reading and input. Nobody is going to understand TAI, or bother to look it up. They're going to enter time like they see on their clock.
- Special time representations like TAI require a bunch of complicated machinery to convert to/from a human-friendly format. It's complicated, requires regular maintenance, and implementations have varying levels of buggy. Keeping it human-friendly in the first place eliminates this whole class of problems.
- Leap seconds are already a thing because of the above two reasons, and they're not going away since we're not going to change humanity's understanding of time to something more precise.
We're perfectly capable of handling future dates beyond 6 months without using TAI (and keeping our clocks in sync well enough to be on time).
How does it handle leading zeros in the year, like Long Now likes to do? https://blog.longnow.org/02013/12/31/long-now-years-five-dig...
But beside that this would make sense when everyone involoved is living in the same timezone, but when coordinating internationally (which tends to be the main focus when the ISO is involved) we really do not want such changes to happen automatically. Everyone in the local timezone is likely to be aware of time changes so they know they have to adapt, but everyone in another timezone might have almost no way of knowing. For them, an event starting at a different (UTC) time is a rescheduling, no matter if it is caused by some timezone adjustment or not. So hiding this behind some tzdb change instead of sending out new dates would most likely mean that they appear at the wrong time.
Also including offsets ensures that the person writing the time knows the right offset. In the last year, I had quite some meetings where the host wanted to be nice and send the time in the local timezone for every participant. Since only timezone names and no offsets were included and the host mostly assumed that their local DST rules apply globally, this resulted in a giant mess. Especially after people informed them about errors, so the times switched back and forth between times assuming DST or not assuming DST. Without seeing the offset, there was no way of knowing which time was actually intended. If a UTC offset is given, most local people can relatively easily verify that it is the expected offset but even more importantly, you can independently convert it to the right zone no matter what the author thought.
Eg: Work at the local library is always 9 to 5 (again “local time”) and you mean precisely one hour after work lets up, regardless of whatever daylight savings or time zone changes occur between now and then.
You need to use either a naive date-time representation coupled with the additional context (“my time”) or use something like lat/long. Or you’re lucky and you live in or near enough to a major metropolis that has its own TZDB entry and it’s virtually impossible for your local time to diverge from that TZ, so you can use that instead (eg you live just outside NYC proper so you use America/New_York as your time zone).
If it's really at 2022-05-01T16:00+1000, then it doesn't matter what DST policy changes occur.
1/ my birthday party will start when my watch shows this local time and date
2/ my local time and date are dictated by the legislative body responsible for this geographic area.
It’s ugly whatever you do, unless you use coordinates to specify your time zone (then it’s just hell to decode).
However, you can use CSS to select the fixed-width variant for digits. This is a perfect example of a use case for:
* {
font-variant-numeric: tabular-nums;
}Or is it "infinite": as in, the spec allows for 8-digits years, 10, etc.?
Consider that +002021001 could represent:
a) "Oct 1, 202" as a calendar date (proleptic Gregorian), in 'basic' format (i.e. no "-" separator), 5 digits for year.
b) "Jan 1, 2021" as an ordinal date, 'basic' format (i.e. no "-" separator), 6 digits for year.
All experience thus far suggests "No." We'll be using all of these formats, plus some new ones.
So I gave them a project to do parsing a file with contemporary dates in. Then towards the end I quietly supplied them with a similar file containing dates from the year 10000+.
Whether or not the devs of years past felt it similarly unlikely that their software would live to the year 2000 as we do the year 10000, I don’t know. But it was a fun exercise!
For long timescales (geological deep time) I believe using SI units are more appropriate: https://en.wikipedia.org/wiki/Year#SI_prefix_multipliers
https://html.spec.whatwg.org/multipage/common-microsyntaxes....
I often come across a string and don’t recognize the format and would love to just supply a bunch of examples and make a best guess.
Also, I read through that RFC several times and didn't find where it allows replacing 'Z' with space. Can anyone else find it?
> NOTE: ISO 8601 defines date and time separated by "T". Applications using this syntax may choose, for the sake of readability, to specify a full-date and full-time separated by (say) a space character.
Seems to contradict sections 5.2 and 5.5 in spirit...
https://docs.microsoft.com/en-us/sysinternals/downloads/stre...
filenames that are reserved names on windows (like NUL) or contain characters that are reserved on windows are refused with "Invalid filename", even on platforms and filesystems that don't have the same limitations
this might be desirable for enforcing portability in extensions, but the thing isn't mentioned in the documentation[1] for the api so you had to know about it beforehand (like most extension devs, probably) or find out the hard way when some of your downloads unexpectedly fail (like me)
i was using it on linux in a personal extension i wrote, and i thought it was silly that i had to add extra code to further sanitize and mangle the filenames for an OS i don't even use
[1] https://developer.chrome.com/docs/extensions/reference/downl...
[1] '꞉' (U+A789). On my Windows systems the default typeface renders this identically to a regular colon.
Applications using this syntax may choose, for the sake of
readability, to specify a full-date and full-time separated by
(say) a space character.
Is separating it by a tab valid? A tilde? An underscore, as this website shows? Since this is so underspecified, there will be receivers that accept only T, and others that accept the T and some arbitrarily chosen character set. The ABNF only allows T.I don't know how a standard that was specifically written to resolve the issues resulting from such ambiguities ended up with such a crucial issue.
It says the list isn't exhaustive, but I'm just curious how often others actually embed the timezone rather than just passing around UTC.
However, for the forward looking/scheduling one one, if you want it to keep the same time across timezone/DST policy changes, you need to the full on timezone designator (i.e. America/New_York), not just the offset or short, ambiguous timezone code (EST).
There's no allowance in ISO 8601 for this, so you need a side channel like another field to communicate this. I've seen other date formats do something like 2021-10-11T12:13:14[America/New_York] to allow for this. Once you do this, it probably makes sense to elide the offset to avoid the risk of consfusing mismatches between it and the timezone.
I have a meeting on June 13th 2026 at 15:00 london time.
This could be 2026-06-13 14:00:00 Z
But if the U.K. drops summer time, or makes it double summer time, the meeting will still be 1500 london time, but the UTC time might change to 1500Z or 1300Z
That said, I wish the page had actually taken the local time into account. As in your case the times on the page are in my current timezone (CEST) so the "Z", "00:00", "+00:00" is basically just decoration.
~~Even worse, in the intersection we have formats like %h:%m:%s+Z and %h:%m:%s+02:00 that show the same time simultaneously.~~
Edit: it is correct now.
%F %T %z
(Ie %Y-%m-%d %H:%M:%S %z)
Though adding nanoseconds is also recommended.
You can live test according to Linux man-pages project, release 4.14 at emil.fi/p/strftime (sorry about the css, it seems it's broken a little bit, you can use the "use desktop site" selection to have it behave better).
> which does not match calendar year everywhere
Yes, this is the reason that ISO-8601 ranges are not sufficient and a Quarter indicator is necessary.I agree that this feature makes quarter indicator necessary. But it also makes it required that the string is something more complex.
Representations of seasons, quarters, etc. is one of many types of extensions included in Part 2.
These extensions are always used in "YYYY-MM" format (and always include the "-"). For the "MM" field, you use the numbers 21-41 inclusive. The numbers represent, in order, spring, summer, autumn, and winter, in 3 ways: independent of hemisphere (21-24), northern hemisphere specifically (25-28), southern hemisphere specifically (29-32); quarters 1-4 (33-36), quadrimesters 1-3 (37-39), and finally, semestrals 1-2 (40-41).
The numbers 1 to 12 are already used to represent months in formats such as YYYY-MM, so starting this list higher than 12 allows these (certainly rare) representations to coexist. e.g. "2021-12" represents "October, 2021" and "2021-29" represents "Spring, Southern Hemisphere, 2021".
Allowing DIN 5008 simply acknowledges reality. Not acknowledging reality is a good way to make people decide that whatever is telling them they're doing it wrong is just "ivory tower" nonsense and should all be ignored at best, possibly actively opposed.
This may or may not be a problem you need to worry about in your API depending on use and clients. For example, if you're only ever sending times and not accepting them, you can just define that the epoch you return is based on UTC or locally and let clients real with it.
If you don't care about pre-epoch times, then it's a compact and fine representation for the DB, single they all have easy conversion functions to their internal formats