A datetime library for Rust
153 points by refi64
153 points by refi64
Jiff is pronounced like “gif” with a soft “g,” as in “gem.”
That's very funny.
As a Go developer, can someone explain to me why this is not part of Rust's standard library? This is not a criticism, I know languages have different philosophies, I'd just like to understand better the rationale for not adding things like datetime, random, base64, etc. to the standard library. I know finding a definite design is hard and once it's committed to the standard library, it's forever, but wouldn't it be better for the ecosystem to rely on an official (or at least officially blessed, like letting jiff live as a separate repo but part of the Rust Foundation) implementation for basic building blocks? I know I always get a particular thrill when something is added to the Go stdlib and I can remove an external dependency (HTTP router improvements, or UUIDs for the last examples I have in mind)
An early version of the time crate actually used to be shipped as part of the Rust distribution prior to Rust 1.0. That's ancient history now, but we explicitly kicked it out of the distribution because we knew it was a huge and complex domain whose modeling is difficult to get right. What if we had standardized on it? No good. What if we waited a few years and standardized instead on chrono? Still no good. (You can see more of my thoughts on why in Jiff's comparison and design documentation.)
It really wasn't until the Temporal folks invested many person years of effort into modeling the domain that I think we've arrived at a real nice answer to the question of, "How does one design a datetime library?" But that only happened recently. Jiff really wouldn't be what it is without it.
Is Jiff the final answer? Who knows. 1.0 was just released. It's already used in production across many applications, but we'll see what happens as more folks adopt it.
Also, Jiff is way bigger and more complex than Go's standard library time package. By an order of magnitude at minimum. There are lots of reasons for this:
time.Time is like a jiff::Timestamp combined with some kind of ZonedDateTime.Span that combines calendar and physical time units all into one type.time package doesn't support this at all.There's probably more stuff too. But that's from a quick look (and memory, since I used to use Go a lot).
In principle it would be nice for something like Jiff to be in std. But its API surface area makes it a huge risk. I don't want to release Jiff 2.0, but I can if the need really arises.
I'm not a user of this, but having both used an implemented APIs for working with time in a few languages, including some that went through standardisation: The above is 100% the correct approach.
Handling time is incredibly hard. Even the lowest level is not trivial. Timeouts are hard to make non-racy. Absolute timeouts give early wake if you're preempted in between reading the time and calculating the displacement. Relative ones can lead to missed wakes if you're preempted during the API call. More importantly, what is your timeout relative to? Wall clock time? What happens if the local clock is wrong and NTP sets it to an hour in the past? Monotonic time? Current-thread runnable time? Different approaches have different tradeoffs. There's a huge amount written about this core part (POSIX made a mess of it and then fixed it in some APIs, inconsistently).
But all of that is, comparatively, the easy bit. Representing time in a way that you can communicate to users is incredibly hard because the right solution depends a lot on the domain. Want to show the current time to the user? That's not too bad, you can find the time-zone correction and it mostly works. Want to show them an historical time in their current time zone? Now it gets fun, because a load of calendars have discontinuities. For example, the late Russian move to the Gregorian calendar meant that the October Revolution happened on November 7 in the new calendar: should you show November 7 (consistent with the current time) or October 25 (consistent with the date accounting at the time)? Even simple things like scheduling meetings and accounting for daylight-saving times require storing things as a calendar date and adjusting for each occurrence, whereas things like nightly CI jobs are fine to schedule in UTC (or UNIX Epoch time). And that's just the smallest edge of the problem.
I don't think I've ever seen a good API for handling all of this but I've seen numerous bad ones. And they're all exploring different parts of the design space to find new bad ideas that looked like great ideas until they came into contact with the wrong use case. Rushing to standardise time APIs is a well-known recipe for disaster.
What if we had standardized on it? No good. What if we waited a few years and standardized instead on chrono? Still no good.
I don't know how/if deprecations live in Rust's stdlib, but could something like datetime -> datetime::v2 -> datetime::v3 have been useful for the ecosystem as a whole? Even if they end up being deprecated, they still exist forever in the stdlib and a clear migration path could be made possible (like Go did with encoding/json -> encoding/json/v2)
Jiff is way bigger and more complex than Go's standard library time package
Yeah, the comparison was not the best, it indeed covers a lot more than Go's time. I guess it's more of a general question regarding "basic" (in the sense of "expected", not that they're necessarily easy to implement) building blocks: maybe Jiff would be to big to add to Rust's stdlib (although Temporal is somewhat part of JS stdlib haha) but I'd imagine some more "bare" version, or some types/traits would make sense as a standard
Rust's design was heavily informed by the Python world's experience with batteries-included standard libraries, where "stdlib is where packages go to die" and, by the time of the Python 2.7→3.0 break, the standard library had grown urllib and urllib2, and everyone was advising newcomers to ignore those and use Requests, which has its own urllib3, the developers of which are adamant must never become part of the standard library.
(And it's not just urllib. That's just the one that most visibly had multiple iterations.)
Among other things, they're already stuck with deprecated methods on the Error trait forever, and an MPSC queue that has become a compatibility wrapper around a vendored copy of one of the two MPMC queues that people pull in off crates.io. (crossbeam-channel)
As things like the http crate demonstrate, it's possible to standardize without putting things in std, and the acceptance criteria for std is more or less "Either things that the language syntax itself needs to depend on (like the Future trait that async and await depend on) or simple functionality that winds up being in every non-trivial codebase (like how std::sync::LazyLock is a std-ification of once-cell which, along with its precursor, lazy-static, has more than 100% penetration when you consider the codebases which depend on both.)
Hell, a bunch of crates exist outside std, not because the Rust team doesn't maintain them, but so they and the toolchain can bump versions independently.
Prematurely putting things in std won't cause them to stop changing (you just get the Python/Java dynamic of experienced people advising newbies not to use the standard library") and is a misaligned solution for allowing discovery of the current best implementation.
an MPSC queue that has become a compatibility wrapper around a vendored copy of [..] crossbeam-channel
I would count this (and hashbrown) as successful examples of std being improved while remaining compatible, by making good use of better libraries that were developed in a less constrained context outside std. But yes I agree that compatible upgrades are not necessarily possible if the guaranteed API itself is bad or imposes bad compromises that prevent the implementation from being improved.
What’s more awkward, and (I think?) peculiar to Rust is the way improvements get stuck in nightly: often there’s no way to get early access to the improvements in stable Rust, because language restrictions prevent third-party crates from providing them, and there’s nothing like “from future import” to selectively opt in to unstable features, and the language developers don’t feel the pain so much because they always have access to nightly features.
Successful in the sense that Rust provides strong enough isolation that it could be done.
A complete and utter failure in that the API is still MPSC and, even when I started using Rust in v1.0, I could never see a use for such a thing. The blog posts about it seemed to be exercises in "Here's how to tie your architecture in knots to prove that an MPSC queue will suffice where an MPMC or SPMC queue is really what's needed".
Generally, when asymmetry is involved, I'm much more likely to be using a work-stealing SPMC configuration for a CPU-bound worker pool... possibly with completion signalled via a Tokio oneshot.
What’s more awkward, and (I think?) peculiar to Rust is the way improvements get stuck in nightly: often there’s no way to get early access to the improvements in stable Rust, because language restrictions prevent third-party crates from providing them, and there’s nothing like “from future import” to selectively opt in to unstable features, and the language developers don’t feel the pain so much because they always have access to nightly features.
The world of web browsers learned from Firefox being forced by uptake to start implementing -webkit-prefixed CSS properties as de facto standard APIs. Rust is just following the browser developers' lead in switching to only offering not-yet-stability-promised APIs in nightly/canary builds to make sure downstream developers can't force their hand again.
or at least officially blessed, like letting jiff live as a separate repo but part of the Rust Foundation
I think this is the way to go; for example the regex crate lives at rust-lang/regex. Maybe after a few years once the 1.0 release has proven itself, the jiff maintainer (and the Rust Project itself) would be interested in making a similar move? ;-)
Really the whole argument comes down to the thing you mentioned, about how lifting into std means committing to indefinite support. In case of datetime libraries, the design is far from settled, as can be gleamed from the fact that there's IIRC 3 competing third party crates, all with very different API styles.
Because Rust has a stability guarantee, and libstd doesn't support versioning, so nothing can ever be removed or changed in there.
This means that every bad API stays forever. DateTime especially is an incredibly difficult one to get right. Given that this is yet another crate made because all the other crates weren't good enough, the old first try that would have landed in std would be the worst of them all.
Instead of having std with bad APIs and telling people not to use them and use crates instead, Rust skips the first step and goes for crates directly.
Second issue is that there's one std for everyone, and one size doesn't fit all. Embedded and WASM folks usually wouldn't want to bundle a time zone database. People targeting specific platforms may want to use the OSs' preferred date APIs.
Because cargo and the internet are good enough now that something not being in the standard library isn't a problem any more. The whole of crates.io is in essence the standard library, but versioned so mistakes don't become forever-mistakes, and with only marginally more friction to use. You just have to run cargo add jiff to add a dependency. It's one of those things where new tools/infrastructure have erased a cost so much it completely changes the value calculus in a field, but people are still sticking to the solutions to the old constraints. Python etc. had big batteries-included standard libraries because downloading libraries and managing dependencies was a pain in the arse back then (among other reasons), and that was their solution. But in Rust, the extended standard library is just one command away, it's easy, fast, neat and tidy, so who cares if it's not actually in the compiler? It almost doesn't matter.
It does make me wonder whether Rust actually needed a standard library at all. Maybe std, or large parts of it (maybe note core), could have been versioned too and thrown up on crates.io. That would be an interesting experiment.
Does Cargo solve the ecosystem fragmentation issue? In Go at some point there used to be multiple concurrent UUID libraries (google/uuid, satori/go.uuid, gofrs/uuid and more) so depending on one or the other meant that your code wasn’t directly compatible with dependencies using another one (the ecosystem eventually regrouped on google/uuid, I just use it as an example). That’s why I was strongly in favor of it being added to the stdlib (even if just the basic type UUID was added it would have been enough for UUID libs to build on top in a compatible way).
I’m guessing this problem happens with Rust/Cargo too? Or does Cargo make it easier to find the pseudo-official library, most adopted in the ecosystem?
I have fairly harsh opinions on this. People love to point at Python and Java (old Date APIs), and they are right. But Rust throws out baby with the bathwater.
The issue is not that stdlib gets stagnant. They can always introduce new or versioned APIs. The issue is Hyrum's law and the baggage of maintaining stuff that comes with. At some point people rely on thing, whether within stdlib or outside. Rust folks wanted to be able to shrug and say 'not our poblem', which is why things like regex and data time are not included.
Even Emacs manages to deprecate and remove stuff over standard decade long period. Why can't Rust?
Why can't Rust?
I think at least one reason is historical. Back when Rust 1.0 released, the selling point was that Rust is no longer an unstable experimental language, you won't have to rewrite your software to appease API or language changes, you can start using it now and we won't pull stuff under your feet unless we have a really good reason to (like unsoundness). This promise got Rust its first commercial usage, and personally I don't think backing down on it without a very good explanation would be wise.
Maybe I worded it wrong and didn't emphasize enough.
There is still an stdlib. People still rely on it. They still need it to be backwards compatible. And there will still be breakages and improvements because that is the nature of things. Nothing lasts forever.
Except, these things are not called stdlib. These APIs come from libs outside stdlib. They are de-facto standardised because more of less whole ecosystem relies on them cf. rand, regex. I would call this shadow-stdlib. Just by not calling stdlib language devs are able to shrug off the responsibility of maintaining them, keeping them alive and backwards compatible. Internet getting better and sorting crates by popularity is not the answer for a developer's peace of mind just using stdlib features and sleeping well knowing there won't be left pad, quality issue, crypto scam or hijack on next update of the lib. That is what makes a good stdlib worth its maintenance burden.
The problem is that Rusts standard libraries do not act like normal crates (I think there might be some ongoing efforts to reduce their weirdness, but I'm not sure); they get versioned and distributed in precompiled form along with the rest of the Rust toolchain because they're more integrated with the compiler and use internal features. For example, core uses #![feature(lang_items)] to define 182 (according to a quick grep) definitions that rustc needs to know about. As a consequence, unlike normal crates you cannot use multiple versions of a standard library simultaneously, and specifically have to use the ones that matches your toolchain.
A commonly used library like rand not being distributed the same way doesn't mean it doesn't get maintained nor that it doesn't care about backwards compatibility. But it means that if a new, backwards incompatible API really is needed, it's not as big of a problem as e.g. in Python. You can continue using the old version (which ofc can still receive updates) even if a dependency already uses the new one.
Just by not calling stdlib language devs are able to shrug off the responsibility of maintaining them, keeping them alive and backwards compatible.
Often, the stdlib language devs do maintain them. It really is just about allowing mixing and matching different toolchain and library versions so libraries can do a major version bump without leaving old toolchains behind or multiplying the size of the standard library's documented API surface, and users can bump their toolchain without breaking their code.
See, for example, efforts to move packages like regex under https://crates.io/users/rust-lang-owner on crates.io.
...and when there's confidence that a solution has API-stabilized and its use become ubiquitous, you get things like std::sync::LazyLock as a std-ification of once-cell to hopefully eventually phase out the greater-than-100% (i.e. sometimes both) appearance of once-cell and its precursor lazy-static in dependency trees for non-trivial projects.
(Likewise, that's why we don't see implementation delegation (i.e. non-trait inheritance) in the language itself. The delegate crate it still trying to climb its way to enough "market penetration" to demonstrate that it represents a design that should be blessed as "the one true approach" by the standard library.)
When it's not something like the Future trait, where a language construct depends on it, the standard library takes a "use crates.io to trial-run it and see if one approach wins out so far over the others as to reassure us that blessing it is low risk" approach to growing new features.)
It makes it a little easier, you can see how popular a crate is on crates.io.. But that's still kind of a problem I suppose. Although, it's probably a better state of affairs than the wrong uuid library being brought into std, and then the ecosystem being fragmented anyway between people using the standard library and people using the superior alternative.
Rust will always need some kind of standard library, for "lang items" if nothing else. That is, part of the language itself uses code from the standard library. This is mostly super low-level stuff like having a definition of the Copy trait, but still.
Now could Rust have had a standard library that doesn't know anything about filesystems, networks or hash functions? Yes, absolutely. Whether it would've been preferable to the world we're in, I can't say.
Rust does have a standard library without filesystem, networks, or hash functions: core https://doc.rust-lang.org/stable/core/index.html
std is already a convenience layer over (essentially) libc and malloc on top of core.
and even then, the convenience layer over malloc lives in the alloc crate and is just re-exported by std
The answer is sort of in your question; historically, Rust has been somewhat allergic to adding much in the way of opinionated APIs into the stdlib (speaking as a total outsider / third party observer). This has started to relax a bit in recent years, from what I've seen.
Date/time is hard, though. It means different things to different people. I might just want to increment timestamp by a day. Does that take into account timezones and leap years? Do I need to pull the tzdb from files? Or embed it in? Where are those files located? Should I add a trait for reading that info, or should it be a filesystem side effect? Who updates them? When should they be read? In memory cache? Should embedded RTC mechanisms use these types, or should they roll their own? Does this need to be so general that all third party date libs can implement traits for the standard types? Does it need to handle formatting as localized strings? Or just a format library? Which calendars should it support? Just the Gregorian? Does it link in all the strings too? Or pull from a localization database?
The list of design considerations is so great. There's probably a subset of functionality that could be standardized. And IMO rust has done well to keep it at what exists now - instants and durations, for the most part.
FWIW random number generation is actually in the process of being added: https://github.com/rust-lang/rust/issues/130703.
The jiff API is really good. If we could send it back in time a couple of decades to the designers if business-y languages like Java and C#, many many bugs would be prevented.
I just want to add the credit should really be given to the Temporal folks. Jiff stands on the shoulders of giants.
Funnily, (and IIRC) Temporal itself took a lot of inspiration from Java 8's new DateTime API. Java folks themselves wished they could send the new stuff back in time to avoid bugs :)
Which in turn is heavily based on Java's library.
It's really JSR310 that did the heavy work of modelling the different domains and needs, and finally getting programming languages to move from date types that mix unix timestamps and calendar times, and towards dedicated ZonedDateTime, LocalDateTime, Instant, Duration, and Period.
It's interesting to see someone build a datetime library nowadays without reading the entire JSR310 discussion first, because that's the perfect explanation for why this exact API is required.
Do you know where I can find the JSR310 discussion? I looked but floundered through a sea of Oracle pages. I did see this: https://jcp.org/aboutJava/communityprocess/pfd/jsr310/JSR-310-guide.html
I did review the java.time API. And I'm aware of its influence on Temporal. Its zoned datetime interchange format, for example, inspired RFC 9557. But Temporal was the most direct influence on me. Notably, it is the Temporal folks who invented (AFAIK) the single duration type that combines calendar and time units. java.time has two separate types for this. If you review the Temporal and Jiff APIs, you should see even more influence. For example: https://burntsushi.net/jiff/#inspiration
Temporal itself, of course, also stands on the shoulders of giants. :-) No disagreement there!
absolutely, and to Joda Time - but Jiff's is even better because it gets to build on the better facilities Rust provides :)
let d1 = civil::date(2024, 7, 30);
let d2 = d1 + 2.days();
Brings a tear to my eye. I love it.
I notice the docs say to open on the issue tracker if you want no-std support, but my use case is silly, so I'll just mention it here for now: a one-off clock I built for my kids on an rpi pico; it runs on embassy, grabs the time via NTP every now and then, and sets some light colors based upon the local in-timezone time. It needs limited timezone awareness, which right now I build in statically using chrono:
[env]
DEFMT_LOG = "debug"
CHRONO_TZ_TIMEZONE_FILTER = "(UTC|US/.*)"
I have no need to rewrite the project but I prefer the jiff interface to the Chrono interface and would love to be able to use it in the future. But these are just fun home hacks, not production stuff. If I were to redo it I'd probably build it as a matter-over-thread and that might remove some of the need for a tz database, though.
I think you'd probably want this: https://docs.rs/jiff/latest/jiff/tz/macro.get.html
It's designed for use in core-only environments. :-)
That’s cool! But I have a question. They docs say:
Callers should only call this macro once for each unique IANA time zone identifier you need. Otherwise, multiple copies of the same embedded time zone data could appear in your binary. There are no correctness issues with this, but it could make your binary bigger than it needs to be.
Shouldn’t the linker take care of uniquing constant data in the executable?
Congratulations! I appreciate the care that went into make this a release you feel you can support indefinitely.
Sidebar: I think it would be fun to use wasm to make the examples runnable.
We're migrating to this at work, off of chrono; we have to deal with a significant part of the full spectrum of date complexity (civil dates, civil datetimes, time zones). I haven't been touching it myself but my coworker who has quite likes the API design.
Congratulations! The blog post and all of the additional linked documentation is fantastic.
The Olsen IANA database wants you to use a nearby major city, with the theory that that's more robust than political boundaries and you're probably economically tied to that city anyway, and thus it is more future proof. But I wonder if this actually is any better in practice than just using the officially defined names.
OK, imagine you're in northern New York State and you are recording an appointment in your computer calendar for 9am at November 1, 2027. Officially, your time zone is US Eastern; that's what the canonical source the tz database actually pulls from, the US DOT's timezone dataset. But using the tz thing, you'd store this as 2027-11-01 T 09:00:00 in America/New_York.
OK great, it all works pretty well. Even if Congress decides their first order of business is to change the rules of daylight saving again, effective immediately, your calendar will still send the reminder at the right time when it comes. Robustness in a way that UTC timestamp fails! yay Civil::DateTime!
But... what if some of the different political ideas we sometimes have up here takes root and we split with downstate? Congress refuses to accept us as the 51st state.... but the Canadians, having their own different political ideas at the same time, welcome us into the province of Ontario. And as part of this political drama, they redefine their daylight saving to align with the UK instead, which is a week offset from the US, and since we're with them now....
Well, that's awkward, my doctor appointment just shifted by one hour! I gotta go update my timezone from America/New_York to the new political reality of America/Toronto. Of course, this kind of secession means US/Eastern wouldn't work, so the city at least isn't worse but I'm also not so sure it is actually better in terms of robustness in the presence of political changes.
I think maybe the ideal thing would be to to store my appointment not with a major city name, but just with the latitude and longitude and look up the timezone from a region database. Or at least, store it like America/Watertown_No_Not_South_Dakota_The_Other_One_No_Not_Massachusetts_Either_The_One_That_Is_Currently_In_New_York_But_We_Cant_Use_State_Names_Because_We_Might_Be_Part_Of_Ontario_If_The_Weird_Unlikely_Political_Ideas_Take_Root
I'm just kinda spitballing, obviously the practical thing is to just use the database as we have it, but this scenario does bother me given that one of the tz's stated goals is:
Be robust in the presence of political changes. For example, names are typically not tied to countries, to avoid incompatibilities when countries change their name (e.g., Swaziland→Eswatini) or when locations change countries (e.g., Hong Kong from UK colony to China). There is no requirement that every country or national capital must have a timezone name.
and it just doesn't really work for me specifically.
You don't have to invent weird future hypotheticals, you can just see what happened this year when British Columbia, Alberta and Manitoba decided on basically 4 months notice to... just continue on DST, thereby implicitely implementing new timezones.
The IANA TZ project was on top of things, but of course they rely on stuff like... actual legislation, something the provincial governments were pretty lax in providing in a timely manner. And then the same governments were miffed when guidance was given to set clocks onto a US timezone further East, because no-one knew exactly what they wanted the new timezone to be called.
Aren't you storing timezones in a user-configurable place anyway? The real value of city-as-zone over zone-as-zone is that users simply don't know their own time zone. What does a person in Arizona choose? Or Indiana?
If the War comes and all of a sudden Potsdam NY is part of the Greater Canadian Sphere of Influence, then the user will have to go into settings and change their time zone, but that's going to be so far down their list of problems that it simply doesn't matter if they show up to their doctor's appointment an hour early.
Aren't you storing timezones in a user-configurable place anyway?
I'm thinking about something kinda like Google Calendar and such, where the users wouldn't be able to configure the server, but might add their own events to the database. How do you store their events in the most reliable way?
I think as a practical matter, given the computer ecosystem we have, the tz name is the best realistic option. But I think ideally, you'd be better off storing the actual location (or approximation thereof) and doing a lookup from that to tz database.
To tie back up to the OP link as this is directly related to API design:
A ZonedDateTime combines a Timestamp, a civil::DateTime and a TimeZone to represent a specific instant in time in a specific geographic location.
They say "specific geographic location", but the API actually stores an IANA Time Zone Database identifier, not a specific location. The linked doc say this is a preferred constructor because, "POSIX TZ strings cannot capture the full complexity of time zone rules".
But my argument is that tz also cannot capture the full complexity of time zone rules. An actual geographic location would likely be better (though again, perhaps impractical compared to tz in the computing ecosystem). It reminds me of when D was trying to be unicode correct by default and tried to push auto-decode to UTF-32, so multi-unit chars would just work. But there's still "characters" made out of several code points so it didn't actually solve the problem and brought on its own complexity.
What does a person in Arizona choose?
America/Denver when you're on the reservation.... is this really any clearer than "Mountain time ([X] observe daylight saving) - current time XX:YY"? Is it remotely robust to political changes considering the tribal government can change their clocks independently of both the states of Arizona and Colorado? (There is actually an identifier "Navajo" but it is just a link for backward compatibility.)
the user will have to go into settings and change their time zone
It might not be that simple though... my calendar has events on it in multiple time zones. Day job has offices in both NYC and London, and depending on whom I'm meeting, the time zone for that event will be one of those cities (this is why I'm so familiar with the US/UK DST difference!). And in the hypothetical NNY secession, if the event is stored only as America/New_York, some of those need updates, and some of them don't.
So I can't just change the setting, I gotta audit every event in the future and update each one. (This might be easy depending on what's in the database, like update if tz == NY && calendar != "work" would probably do it, but whelp, calendar provider doesn't let me run custom update filters like that so i guess im just clicking a lot.) Whereas if it stored the location, it would automatically adjust when the tz database is updated to account for the new political outcomes.
but that's going to be so far down their list of problems that it simply doesn't matter if they show up to their doctor's appointment an hour early.
Indeed.
But, the timezone names avoid state and country names based on the theory that cities are more long-lived. I agree with you that if New York State were to split, or the United States were to collapse, this whole argument would seem pretty unimportant... just the tz database has a design goal to try to be robust in the face of these anyway!
They say "specific geographic location", but the API actually stores an IANA Time Zone Database identifier, not a specific location. The linked doc say this is a preferred constructor because, "POSIX TZ strings cannot capture the full complexity of time zone rules".
You've hinted at it in a few places, but this falls under "all models are wrong, but some are useful." The IANA Time Zone Database identifier is a model for a geographic location. Arguably, it's a model whose target audience is programmers.
This might help: https://www.iana.org/time-zones/theory#scope
Indeed, that's the page I quoted in the first post (though a different section of it, i quoted the first bullet point under the following heading), that they are trying to "be robust in the presence of political changes". I get that as a practical matter, they wanted to draw the line somewhere, especially since the tz database's names actually comes from 1993, where being several megabytes smaller mattered a lot more than they do now, and I get the Rust (and other language) libraries using it because it is what's actually there.... but it still bugs me.
Just doing conversions between the Windows timezone names and the tz names feels like a lossy conversion.
Just doing conversions between the Windows timezone names and the tz names feels like a lossy conversion.
Yeah. CLDR collects a huge amount of knowledge about this kind of thing. The CLDR notes on time zone name formatting and conversion say:
Note: Not all Unicode time zones have equivalent Windows TZID mappings. Also, not all Windows TZIDs have equivalent Unicode time zones. For example, there is no equivalent Windows zone for Unicode time zone "Australia/Lord_Howe", and there is no equivalent Unicode time zone for Windows zone "E. Europe Standard Time" (as of CLDR 25 release).
But I think ideally, you'd be better off storing the actual location (or approximation thereof) and doing a lookup from that to tz database.
Right. Ideally TZ names should be more like an implementation detail, not something users normally have to deal with.
The reason that the Olson database avoided state names in north america is because TZ boundaries often don’t coincide with state boundaries, and in the past often moved around. Indiana is the most complicated instance, and it’s a better example than hypotheticals about New York breaking up.
Day job has offices in both NYC and London, and depending on whom I'm meeting, the time zone for that event will be one of those cities (this is why I'm so familiar with the US/UK DST difference!). And in the hypothetical NNY secession, if the event is stored only as America/New_York, some of those need updates, and some of them don't.
The solution to this kind of quandary is to record the locations (plural) of all the participants, probably with a primary location chosen by the convenor. The calendar app should normally display an event with all the relevant local times so that it’s easy to see if a multi-continent meeting is at a reasonable time for all participants without manually consulting a world clock. Then when TZ boundaries change or DST rules change, the software can automatically identify which meetings are affected and exactly which need manual attention (ie when different participants have different time changes), without a bunch of false positives caused by imprecise data or false negatives due to incomplete data. This should not be much more work for the convenor because the calendar app should usually know where the participants are, because it usually knows their travel plans.
I have an old essay which fleshes out this idea of appointments that are resilient to TZ changes largely inspired by the horrible Microsoft Exchange calendar fuxups caused by its data model being unable to handle the 2007 north american timezone changes.
Indiana is the most complicated instance, and it’s a better example than hypotheticals about New York breaking up.
Indeed, I just don't know Indiana personally, but I see they let the counties decide and that makes a lot of sens to me too. I believe Kentucky also does it that way, I drove down there many years ago with a garmin gps and it actually annoyed me how many times the time displayed on that thing changed, it was like "arrival estimate 3:30, 15 miles away, current time 2:10" just cuz i happened to be crossing another time zone boundary in the middle of the state. Usually, when I travel, I just pay attention to my old school wristwatch which is more consistent lol.
Really, time zones themselves are an awkward quantization of a continuous spectrum in the first place... but like I said in the other comment just now, I get they have to draw the line somewhere as a practical matter. ... hey your essay has " My silly "sunrise time" idea involves changing the clock by a minute or so most nights. " nice lol kinda the same idea there too.
The solution to this kind of quandary is to record the locations (plural) of all the participants, probably with a primary location chosen by the convenor.
Yeah, that seems reasonable to me. In fact in your essay "The time of an event in the future should be recorded in local time coupled with the event's location. The location is used to look up the timezone, and the timezone data determines the UTC offset." Indeed, I think we agree on that.
And I know about the repeated hour but i didn't consider that in thinking about this... and that Xinjiang example you had too. Golly, even when you think you have a perfect solution there's something else :)
thanks for the link though, I think your essay is pretty reasonable.
... and that Xinjiang example you had too
A sad footnote: that timezone oddity has been suppressed since I wrote the essay.
I'm thinking about something kinda like Google Calendar and such, where the users wouldn't be able to configure the server, but might add their own events to the database. How do you store their events in the most reliable way?
And in any case, in the end the users will find a way to break the system. This reminded me of a story tangential to the question:
An exchange student travelled across a few timezones to study in a foreign university. For some reason the other tenants in the apartment building never respected the student's reservations of the laundry room.
Well, turns out said student did not use NTP, and did not care about configuring timezones. Instead, they just adjusted the HH:MM value of the local clock so it read right. The issue was that the computer still reported the timezone of their home country to websites/applications. The applications were kind enough to translate entered/displayed times between timezones so that they read correct in the user's local time. Or in this case everything was offset by some hours and a half compared to their next door neighbor.
I'm sure that "and a half" saved a lot of conflict and accusations, since it was really obvious something was wrong when a screenshot showed reservations starting/ending at :30 instead of :00