4 ms·
> # The local system timezone > LocalDateTime, Here’s my feedback: one should essentially never use “local” time. I would even argue that the existence
by amluto 3y ago
> # The local system timezone
> LocalDateTime,
Here’s my feedback: one should essentially never use “local” time. I would even argue that the existence of systemwide local time is a historical mistake.
Why would you ever want to use the “local” timezone of the system on which you are running? If the user is literally sitting in front of a monitor plugged in to the machine, it might be appropriate (but it should be a per-user setting). But if the user is using X forwarding or ssh or a remote desktop, you have no idea what timezone the user is in. (And this was common in the mainframe era!) If you’re servicing a request over the network, you don’t want local time.
The only sort of legitimate use for “local” time I can think of is compatibility with libc and it’s horrible time API.
You can’t even tell what local time means without getenv, which is a footgun.
So maybe LocalDateTime should be called LibcCompatLocalDateTime.
- jncfhnb 3y agoImagine having the audacity to run software on the machine in front of you
- ahartmetz 3y agoYou shouldn't do that, it's bad for some business models.
- cm2187 3y agoThen how do you express that something must happen at a date in the future at 4pm local time? If you use UTC based on today's expectation of daylight savings, they may have changed by the time this date happens.
- amluto 3y agoYou start by figuring out what you’re even trying to do. For example, I read your comment three times, and I don’t know what you mean by “4 pm local time”. I don’t even have what I would consider to be a credible guess.
- jcranmer 3y agoSchedule an event to occur at 4pm every day, say in crontab.
- amluto 3y agoWorks great until you have an office in a different time zone. The whole concept of a computer belonging to a timezone works to some extent when that computer has a single human tenant, but it falls apart pretty quickly when the scope broadens.
- jcranmer 3y agoIf I'm scheduling a meeting, then yes, I am going to want to schedule the meeting using a specific time zone, which may or may not be my local time zone at that moment. But if I'm scheduling when I want my computer to reboot, I want that to be a fixed in time zone in my local time zone. And if I subsequently change my local time zone, I want it to remain at that time in the new local time zone, not the old one. Yes, local time zones don't always make sense. But that is a far cry from saying they never make sense!
- amluto 3y agoI don’t know about you, but I have computers that aren’t in the same time zone I’m it. I probably want them to reboot at night where I am, not where they are. But yes, “reboot a laptop at 2am” is in the general category of alarm clock use cases, where a time (but not a date!) with a separately determined time zone makes sense. The OP mentioned LocalDateTime, which doesn’t make sense for this use case.
- falserum 3y agoInstant in history -> GMT+0/UTC Future shedule for humans to coordinate (contracts, meetings) -> ZonedDateTime Personal alarm that should be kept in sync with the sun (e.g. go to sleep) -> LocalDateTime What’s good example/purpose for OffsetDateTime?
- CJefferson 3y agoWhat is your alternative? I suspect 99.999% of computer and phone users want the time of their local device. Do you want them all to have to explicitly set their time zone?
- adrian_b 3y agoSince the appearance of computer networks, all operating systems require during installation an explicit setting of the time zone. This includes Windows and any operating system that chooses to keep the time as local time, because even those need to be able to convert the local time to other time zones. The users who buy a computer with a preinstalled operating system may not see this, but someone has explicitly set their time zone. Because the time zone must be set anyway, it is always better to use inside programs a time that is either UTC or TAI and convert it only for presentation purpose. For purposes like storing the time at which future events are scheduled, if they are established in local time, so the future correct conversion is yet unknown, a distinct type must be used and that must be a structure with 3 members, date, time of the day and time zone. It must not be a time expressed in seconds or other time units, as it may be used for UTC or TAI.
- CJefferson 3y agoWindows 11 does not require setting timezone. I just did it in a VM to check I wasn't confused. Neither do android or iPhones.
- jraph 3y agoAny Android install I did myself in VMs or on a phone asked me for the timezone. (lineage and derivative). Maybe it could guess from the GSM network though. My dumb phone also does, though in terms of UTC offset + DST offset.
- MereInterest 3y agoBecause the local time is the thing that you have immediate access to, with no additional conversions applied. Every conversion requires an external source of information. Converting from local time to time zone requires measuring the system clock drift. Converting from time zone to UTC requires knowing which time zone you are in. Converting from UNIX timestamp to UTC requires measurements of the earth’s rotation to know how many leap seconds to add. I’d propose going in the opposite direction: All timestamps should indicate which clock they were produced from. There is no such thing as a global clock, only conversions between your local clock and the UTC clock.
- amluto 3y ago> Because the local time is the thing that you have immediate access to, with no additional conversions applied. Only in the sense that BIOS systems historically programmed non-DST-aware local time into the RTC. Other than that, you actually have no-conversion-needed access to UTC or something UTC-like. Linux mostly tracks the conversion from the hardware clock (TSC, for example) to UTC. NTP gives UTC, and GPS gives something that is a lot closer to UTC than to local time.
- MereInterest 3y ago> Only in the sense that BIOS systems historically programmed non-DST-aware local time into the RTC I would love to hear proposals on how, at a hardware level, you would track Daylight Saving Time. Not just how a Daylight Saving Time correction would be applied, but also how the hardware would receive updates to dates at which DST is observed, within which geographic borders, and how to handle conflicting updates for locations where the geographic borders are contested. > you actually have no-conversion-needed access to UTC or something UTC-like No, you don't. You may have access to an API that has already applied conversions when by the time a result it returned to you, but that is significantly different than having direct access to a universal clock. (And assumes that such a universal clock even exists.) Your clock is a hardware-based oscillator, with a counter for the integer number of oscillations that has occurred. You do not have a UTC clock. You have an experimentally-determined and infrequently-updated conversion between your clock and the UTC clock. > NTP gives UTC No, it doesn't. NTP gives an approximation to UTC, and is only available when you have a network connection available. The accuracy of that approximation depends on quality of that network connection, and whether it has asymmetric delays. > GPS gives something that is a lot closer to UTC than to local time While true, this is only available for devices that have GPS capabilities, in a location without sharp elevation changes that would delay GPS signals. Everything has a conversion factor. Everything. If you record the original measurement and the conversion factor used, you can recover from errors in the conversion. If you only record the measurement after conversion factors have been applied, you cannot.
- bongodongobob 3y agoSettle down. Most people aren't running or accessing things globally. Local time is perfectly acceptable for a list of obvious reasons.
- make3 3y ago... a huge fraction of Python code runs on servers everywhere
- azinman2 3y agoAnd a bunch isn’t. Time is hard no matter what. Having a variety of types and options is a good thing, as long as everything is explicit and convertible. The wonder if obj-c/swift do well here with NSDate/Date representing a moment in time separate from any calendar/time zone… although the name is confusing for what it represents.
- bongodongobob 3y agoWhich is exactly what you use time zones for.
- coldtea 3y ago>But if the user is using X forwarding or ssh or a remote desktop, you have no idea what timezone the user is in. Perhaps I don't care, and I want to present things from the point of view of the server's location?