News for hackers. Stuff that matters.
Re:Why is subtracting these two times in 1927 giving a stran... by rkagerer on Monday November 02, 2020 @09:19AM (#24968328)
The suggestions to use UTC are good, but that doesn't completely immunize you from all the weirdness of time.

e.g. UTC still has leap seconds kludged in from time to time "because the Earth's rotation speed varies in response to climatic and geological events" [1]. There's been talk of redefining it at some point to remove them.

GPS Time or Precision Time Protocol may be suitable when you need to measure events on a continuous scale.

Leap smeared time used by Google and AWS is also an interesting topic [2].

[1] https://en.m.wikipedia.org/wiki/Leap_second

[2] https://developers.google.com/time/smear

Re:Why is subtracting these two times in 1927 giving a stran... by em500 on Monday November 02, 2020 @10:03AM (#24968819)
UTC or Unix epoch are good for datetimes in the past, e.g. for logging events. They're not good for future datetimes, e.g. for recording appointments.

Because in case of local timezone policy changes, in the vast majority of cases the intention is for the future event to stay constant in the local timezone, and be changed in UTC / epoch. If for example you made the mistake of storing store opening hours in UTC and translate it to local time in the UI, you will be showing the wrong time.

For appointments, you need both the datetime and the location/timezone. In case of cross-timezone appointments, e.g. virtual meetings, if there are timezone policy changes the issue cannot be resolved without rescheduling the event for some participants.

Re:Why is subtracting these two times in 1927 giving a stran... by Joker_vD on Monday November 02, 2020 @10:12AM (#24968910)
And for the event in the past, respectively, you need datetime and the then-effective offset, not timezone, if you want to know the "what was the local time on the actual physical wall clock?". Unless you're sure the tzdata were correct when the timestamp was taken, and your current tzdata have correct historical info, you can't just take UTC timestamp+timezone and convert it to local time. And I've seen enough machines that had deliberately wrong timezones for some time.
Re:Why is subtracting these two times in 1927 giving a stran... by kevinmgranger on Monday November 02, 2020 @10:29AM (#24969110)
Doesn't the olson DB track when offsets changed based on UTC time, and thus UTC timestamp+timezone is enough?

(If your datetime library handles historical information in the DB correctly, that is!)

Re:Why is subtracting these two times in 1927 giving a stran... by Joker_vD on Monday November 02, 2020 @10:36AM (#24969217)
It does, but, eh, I mean, read the accepted answer: apparently, the past is rather unpredictable.
Re:Why is subtracting these two times in 1927 giving a stran... by klodolph on Monday November 02, 2020 @01:06PM (#24971038)
> UTC or Unix epoch are good for datetimes in the past, e.g. for logging events.

Unix epoch is known not to be good enough for some scientific applications :-/

Re:Why is subtracting these two times in 1927 giving a stran... by egsmi on Monday November 02, 2020 @04:03PM (#24973314)
That's interesting. Can you point to an example? Is it a resolution problem?
Re:Why is subtracting these two times in 1927 giving a stran... by klodolph on Monday November 02, 2020 @04:13PM (#24973423)
It’s a resolution problem if you want to measure something within 1s, which is fairly tame and reasonable.

Like, let's say you’re measuring the time between two events, and you’re logging a stream of them. If you use Unix timestamp, the timer will jump during a leap second.

This is because a day in Unix time is always exactly 86,400 “seconds”, but an actual civil day may be from 86,399 to 86,401 seconds. (It has never been 86,399 seconds, but it “could” be.)

So you should probably be using TAI. UTC is theoretically good enough but it is inconvenient to use because of the leap seconds. Unix time is a bit broken.

It is actually very easy to use TAI. You just need a GPS receiver. TAI is a fixed offset from GPS time (TAI = GPS + 19 seconds).

Re:Why is subtracting these two times in 1927 giving a stran... by dahart on Monday November 02, 2020 @09:35AM (#24968505)
Apparently days are slightly longer now (up to 0.06 microseconds) just in the last 10 year because of the enormous dam in China. 1 leap second every 16M years, I wonder if that’s enough to care about right now? https://en.wikipedia.org/wiki/Three_Gorges_Dam#Terrestrial_i...

Time smear is an interesting concept. Once enough of the world’s clocks are synced to online sources, I wonder if we should consider using that kind of idea to smear away daylight savings time over the whole year. Not sure it’s a great idea, but maybe it would be possible to set the sunrise to be 7am every day.

Re:Why is subtracting these two times in 1927 giving a stran... by fanf2 on Monday November 02, 2020 @10:02AM (#24968793)
One of the earlier proposals for DST suggested shifting by 20 minutes four times in spring and back four times in autumn. Counting hours from sunrise or sunset (instead of noon) was common in the ancient world. (They were often rubber hours so there were always 12 hours of day and 12 of night regardless of the season.)

Some years ago I sketched a way to do smoothed DST based on when the sun rises. The trick is to avoid time zone differences due to differences in latitude (as well as longitude). I chose to use sunrise at the nearest tropic as the benchmark, which gives you a gradual DST adjustment of about an hour and a half between winter and summer, changing by up to a minute or two each day. http://catless.ncl.ac.uk/Risks/search?query=Sunrise+time+Fin...

Re:Why is subtracting these two times in 1927 giving a stran... by dahart on Monday November 02, 2020 @11:09AM (#24969615)
Yes exactly, I like this proposal! "The essential idea is that our clocks should be set using sunrise as a benchmark instead of noon." Are you pursuing it, and did you get any valuable feedback?
Re:Why is subtracting these two times in 1927 giving a stran... by fanf2 on Monday November 02, 2020 @11:39AM (#24969975)
Well, it was originally intended as satire (hence the reference to Jonathan Swift in the subject line) - even though its logic makes some kind of sense, it is completely impractical :-) I do have a bit of sketchy software that compares various times (local apparent solar time, local mean solar time, standard/daylight time, smoothed sunrise-based time, times of sunrise/noon/sunset) but I have never found a good enough reference for the astronomical calculations to be happy with it.
Re:Why is subtracting these two times in 1927 giving a stran... by dahart on Monday November 02, 2020 @11:55AM (#24970203)
Oh jeez, hahaha whoosh, the joke went totally over my head - is that whole publication satire? Do you think it's becoming more likely to be practical over time? I'd guess it's still impractical, but the percent of the world's online-connected clocks has definitely skyrocketed in the last 10 years with the proliferation of smart phones...
Re:Why is subtracting these two times in 1927 giving a stran... by fanf2 on Monday November 02, 2020 @01:34PM (#24971410)
RISKS is mostly sensible though it has a sense of humour especially around the 1st April :-)

RISKS is one of the oldest mailing lists, since 1985, worth subscribing if you have an interest in computer systems security.

Re:Why is subtracting these two times in 1927 giving a stran... by Someone on Monday November 02, 2020 @11:52AM (#24970147)
Would that work well with zoom meetings where participants aren’t on the same latitude? I would think the difference in time of sunrise between them varies during the year (https://en.wikipedia.org/wiki/Sunrise_equation). If so, repeated appointments would have to move for at least one of them. In itself that isn’t problematic, but if one also has appointments with people on the same latitude, non-overlapping events might start overlapping over time.

Also, why stop at sunrise, and discriminate against sunset? Do what the Romans did: always have 12 hours between sunrise and sunset and 12 between sunset and sunrise (https://en.wikipedia.org/wiki/Roman_timekeeping#Variation) :-)

Re:Why is subtracting these two times in 1927 giving a stran... by dahart on Monday November 02, 2020 @12:04PM (#24970323)
Oh yeah, I never even thought about latitudinal time zones! It could be a checkerboard. Or maybe we need diagonal stripes and not vertical stripes. Now I need to plot the isolines of sunrise on the globe... looks like I'm not getting anything done today... thanks! ;) Or I guess we could entrust the Google cloud to keep time and sync all the calendars.

12 hours of sun is a crazy idea, now that's some time smear. It'd be funny to try that in Iceland or Svalbard, where you'd end up with days where 12 hours are divided into 10 minutes... or worse, some days with no hours at all!

Re:Why is subtracting these two times in 1927 giving a stran... by Someone on Monday November 02, 2020 @04:58PM (#24973928)
“Isolines of sunrise on the globe” don’t exist/change with time of year. It’s more like there’s a “sunrise line” that runs around the globe, changing slowly with a one year period (ignoring lots of smaller effects)

If you really want to complicate things, a real “7 ‘o clock at local sunrise” clock should also be affected by local mountains.

If you really, really want to complicate things, include cloud cover, too, an require that sunrise must be observed (Muslims require that for the new moon to determine the end of Ramadan (https://en.wikipedia.org/wiki/Ramadan#Eid))

Re:Why is subtracting these two times in 1927 giving a stran... by dahart on Wednesday November 04, 2020 @09:23AM (#24989284)
Huh? The sunrise line is what I was talking about.

The rest of that is hilarious. I have no interest to complicate things in those ways, but if you think those are good ideas, you should go for it! Propose them to your local government and try to get them to switch.

Re:Why is subtracting these two times in 1927 giving a stran... by dmurray on Monday November 02, 2020 @12:34PM (#24970697)
> Now I need to plot the isolines of sunrise on the globe... looks like I'm not getting anything done today... thanks! ;)

You can try different times on this page, for one:

https://www.timeanddate.com/worldclock/sunearth.html

Re:Why is subtracting these two times in 1927 giving a stran... by dahart on Monday November 02, 2020 @01:11PM (#24971092)
Yes! There they are, the diagonal time zones. I don't know why I didn't check there. This website is so amazingly good, I keep referencing the interactive annual sunrise/sunset charts at different locations, just didn't think to check the world map. For some reason I feel like maybe the pastel colors and cartoony graphics make me frequently under-estimate how serious and thorough the charts and apps are here, but I am a big fan. Maybe time to donate.
Re:Why is subtracting these two times in 1927 giving a stran... by tzs on Monday November 02, 2020 @12:12PM (#24970431)
Zoom meeting with people in significantly different latitudes would be like meetings now with people in significantly different longitudes. The same mechanisms we use to cope with the latter should work with the former.
Re:Why is subtracting these two times in 1927 giving a stran... by Someone on Monday November 02, 2020 @04:42PM (#24973765)
Time zones (even if daylight saving time switches aren’t synchronized) are a tamed version of synchronizing every clock with local sunrise. Things such as “Let’s meet next month, same time” wouldn’t make sense anymore.

Everybody would have to know what location a meeting is scheduled in. “An hour after sunrise in London” would be the same for everyone, but if you also meetings “two hours after sunrise in Madrid” and “three hours after sunrise in Paris”, how much time there is between them will vary during the year.

Re:Why is subtracting these two times in 1927 giving a stran... by tzs on Monday November 02, 2020 @12:04PM (#24970318)
I think it could work to have a dual time system, with a worldwide time (probably UTC) used when you are trying to coordinate things with people who are not in your general region and a regional time based on sunrise (which I'd put at 6 AM, probably).

Most people would have their clocks/watches/devices display regional time, or both regional and world time.

Things like business hours, school hours, meal times, regional transit schedules, and other things that mostly just involve coordinating with people in the region would use regional time.

For most people in a region, this would allow them to operate on a schedule that involves waking naturally to the brightening morning instead of using an alarm. It would also mean that all of the extra daylight hours that come with the summer would end up at the end of the day, instead of some of them going before you go to work or in more northern places even before you wake up.

Re:Why is subtracting these two times in 1927 giving a stran... by iso1210 on Monday November 02, 2020 @01:58PM (#24971682)
> a regional time based on sunrise (which I'd put at 6 AM, probably).

So sunset at noon?

Re:Why is subtracting these two times in 1927 giving a stran... by amelius on Monday November 02, 2020 @11:24AM (#24969778)
> UTC still has leap seconds kludged in from time to time "because the Earth's rotation speed varies in response to climatic and geological events"

Why do we adjust time, and not geometry (given that geometry changes anyway because of shifting of tectonic plates)?

(By geometry I mean coordinates of objects like buildings, landmarks, etc.)

Re:Why is subtracting these two times in 1927 giving a stran... by fanf2 on Monday November 02, 2020 @11:47AM (#24970081)
There have been 27 leap seconds since the start of modern UTC in 1972. One second of time corresponds to 15 arcseconds of the earth’s rotation. 27 leap seconds corresponds to nearly 7 arcminutes of rotation, which is 7 nautical miles of distance at the equator. Would you like to re-do all maps to shift them 500 yards every time there is a leap second?
Re:Why is subtracting these two times in 1927 giving a stran... by parliament32 on Monday November 02, 2020 @05:05PM (#24974012)
Considering that maps have to be re-done periodically to account for tectonic plate shifts anyway, maybe this idea isn't as far off-base as it sounds.
Re:Why is subtracting these two times in 1927 giving a stran... by fanf2 on Monday November 02, 2020 @07:12PM (#24974949)
Since 2000, “Australia’s tectonic plate – the Earth’s fastest moving continental plate – has moved about 1.5 metres northeast (approximately 7 cm / yr)” https://www.icsm.gov.au/gda2020

That’s more than 1000 times slower than leapsecond-related drift

Re:Why is subtracting these two times in 1927 giving a stran... by jhayward on Monday November 02, 2020 @12:33PM (#24970684)
The geometry of plate movement isn't what affects the kind of apparent solar time changes that leap seconds address.

We do, however, take plate movement in to account when determining positions of things on the surface. Geodesic coordinate systems periodically publish 'Datum' that are the result of new surveys of positions. In some places, such as Australia, the difference a decade can make is pretty large. Other places, not so much.

Re:Why is subtracting these two times in 1927 giving a stran... by ooOOoo on Monday November 02, 2020 @11:43AM (#24970029)
The geometry used for maps actually changes because of shifting of tectonic plates! See https://nautil.us/issue/81/maps/what-happens-to-google-maps-...
Re:Why is subtracting these two times in 1927 giving a stran... by bobthepanda on Monday November 02, 2020 @11:43AM (#24970023)
How would that change the fact that it took longer for the earth to spin back to the same place on its axis?
Re:Why is subtracting these two times in 1927 giving a stran... by amelius on Monday November 02, 2020 @11:52AM (#24970149)
I mean, instead of adjusting the time, you adjust the coordinates. So Greenwich would move a bit and the real origin of UTC would be a little to the left or right of Greenwich. (We'll have to adjust it anyway because of tectonic plate shifting.)
Re:Why is subtracting these two times in 1927 giving a stran... by teraflop on Monday November 02, 2020 @12:59PM (#24970960)
Whenever you see a UTC time, the timestamp itself tells you how which "leap second epoch" it falls into (with the exception of instants that fall within the leap second itself). The only extra information you need to correctly do time calculations is the table of leap seconds, and that's a very small amount of mostly-static data that everyone can agree on.

With your proposal, time handling would be slightly simpler, but every geographic coordinate everywhere would need to be tagged with a date to let you know which epoch it was relative to, or else you would get huge (in local terms) errors.

Re:Why is subtracting these two times in 1927 giving a stran... by bartvk on Monday November 02, 2020 @08:49AM (#24968081)
I love this kind of stuff. For example the date of October 6th, 1582 doesn't exist.

https://blog.yossarian.net/2015/06/09/Dates-That-Dont-Exist

Re:Why is subtracting these two times in 1927 giving a stran... by lohfu on Monday November 02, 2020 @09:00AM (#24968163)
in most countries the dates 6th - 14th october 1582 existed since far from all countries switched to the Gregorian calendar when the Papal bull to switch was issued. Essentially only Catholic countries followed the bulla. Russia, for example, didnt switch from the Julian calendar until 1917.
Re:Why is subtracting these two times in 1927 giving a stran... by dahart on Monday November 02, 2020 @09:20AM (#24968338)
That’s pretty interesting. So is Ruby’s behavior - calling the date invalid - is that bad behavior, or a totally reasonable choice to assume the DateTime is Gregorian? It would be neat if the exception said why the date was invalid, but I guess for any dates going back in history globally we should try to use a more sophisticated time lib that takes calendar and locale into account whenever they exist.
Re:Why is subtracting these two times in 1927 giving a stran... by jcranmer on Monday November 02, 2020 @10:29AM (#24969113)
The Gregorian calendar was adopted in arguably four main spurts. The first spurt changed over in 1582, and was exclusively Catholic countries. Most of Protestant Europe then changed in 1700, in a second spurt. The third spurt was the Anglosphere, switching in 1752, and Sweden, switching for good in 1753. The final spurt was Orthodox countries changing over during and after World War I.

There is an additional wrinkle to comment on, which is that not every country started their year on January 1. And when a country changed their year start to January 1 is often not the same as when they changed from Julian to Gregorian.

In the absence of more specific information, it is usual to assume that an unlabeled calendar reference is a Julian date reference (starting on January 1) until October 4, 1582 and a Gregorian date reference from October 15, 1582 onwards, with October 5-14, 1582 not existing. It should be noted that this calendar does not correspond to any actual calendar used by any polity in actual history that I am aware of, but it would tend to be less confusing than actual historical calendars.

Re:Why is subtracting these two times in 1927 giving a stran... by rmah on Monday November 02, 2020 @10:37AM (#24969231)
What about non-european cultures? When was the Gregorian calendar adopted generally in india, central asia, the far east (china, japan, korea), south-east asia, east africa, west africa?
Re:Why is subtracting these two times in 1927 giving a stran... by jcranmer on Monday November 02, 2020 @11:26AM (#24969800)
East Asia adopted the Gregorian calendar as part of the drives to Westernization: Japan in 1873, Korea in 1895, and China in the early 20th century (post-Qing China wasn't a unified country following the same rules).

In the Americas, the Julian or Gregorian calendar would have been adopted at time of European conquest. Similarly, in most of the rest of the world (which was conquered by Europeans at some time or another), civil administration would have switched to Gregorian when Europeans started administration, although this might not imply a change in local usage of calendar.

Islamic countries have had the most resistance to the Gregorian calendar, with Saudi Arabia not using it (de jure, although it was used in private industry de facto) until 2016 and Iran and Afghanistan still not using it.

Re:Why is subtracting these two times in 1927 giving a stran... by mehrzad on Monday November 02, 2020 @02:18PM (#24971914)
Iran uses its own observation-based solar calendar (which means it follows the seasons exactly every year), but it also reports the Gregorian date on the nightly news. People in Iran are generally aware of the Gregorian month and year they are in, if not the exact date.
Re:Why is subtracting these two times in 1927 giving a stran... by tangus on Monday November 02, 2020 @09:46AM (#24968643)
It's documented.

>A Date object can be created with an optional argument, the day of calendar reform as a Julian day number, which should be 2298874 to 2426355 or negative/positive infinity. The default value is Date::ITALY (2299161=1582-10-15).

Re:Why is subtracting these two times in 1927 giving a stran... by rkagerer on Monday November 02, 2020 @09:31AM (#24968452)
Samoa is near the international date line and flipped back and forth a couple times to align with whoever it was doing more trading with at the time (Asia or US). In 1892 they celebrated 4th of July (US independence day) twice.
Re:Why is subtracting these two times in 1927 giving a stran... by elliekelly on Monday November 02, 2020 @09:26AM (#24968403)
Time is one of those weird things I didn’t give much thought to until I started programming. And in the beginning it annoyed me that something as “simple” as time could be so complicated for computers. But then I read stories like this and I try to imagine how we’d deal with these complexities if they hadn’t been fixed before things got so complicated. What would happen if we told the world in 2020 that we’re just going to skip ten days ahead on the calendar? How many things would break? I suspect a whole lot.
Re:Why is subtracting these two times in 1927 giving a stran... by bartvk on Monday November 02, 2020 @10:24AM (#24969040)
Yup, me too. I thought I figured it out, until I started builing apps for an airline. Cabin crew wish to view their schedules in local times when departing and arriving. It took several tries to show their schedule in a calendar-like view that intuitively made sense to them.
Re:Why is subtracting these two times in 1927 giving a stran... by lisper on Monday November 02, 2020 @12:01PM (#24970293)
It's not just airline crews. I do a lot of traveling, and I want to enter my itinerary in my calendar in terms of the local time where I will be at the time of the event. I use a Mac, and Mac calendar assumes that all times are local to the time zone I'm in when I entered the event. So when I'm on the road, I would like to change the time zone on my laptop to match the local time where I am, but I can't because if I do, Calendar will move every event on my calendar to a new (wrong) time. So I have to keep my Mac's time zone set to my home time zone in order to not have it screw up my calendar. It drive me nuts.
Re:Why is subtracting these two times in 1927 giving a stran... by esrauch on Monday November 02, 2020 @09:08AM (#24968242)
I would have presumed the perceived gap was "yesterday we were using Julian, today we'll use Gregorian" (or Gregorian v0 to v1). Instead the article suggests it is "before today Julian and Gregorian both existed and were the same, now Gregorian has jumped".
Re:Why is subtracting these two times in 1927 giving a stran... by lordnacho on Monday November 02, 2020 @09:49AM (#24968674)
Time is one of those libs that you don't try to implement on your own. It's one of those things that sound simple on the face of it, but you soon find out there's a huge number of complications. Things like locales having different daylight savings, which require a DB to keep track of, and might change in the future. Historically baked in weirdness like the thing in this SO answer. The international dateline. Arizona having its own TZ. Half hour countries. Cultural specific calendars like Jewish or Arab. It's a cave of horrors.

At best, try to understand that if you do use something other than epoch time, you might have to record a bunch of stuff like what I mentioned.

Re:Why is subtracting these two times in 1927 giving a stran... by ben-schaaf on Monday November 02, 2020 @10:02AM (#24968788)
Computerphile has a great video on this: https://www.youtube.com/watch?v=-5wpm-gesOY
Re:Why is subtracting these two times in 1927 giving a stran... by floitsch on Monday November 02, 2020 @09:36AM (#24968522)
I implemented (part of) the Dart date/time library. Lots of fun stuff with time zones...

Wrote a blog post about the most interesting things I found: https://medium.com/@florian_32814/date-time-526a4f86badb

Re:Why is subtracting these two times in 1927 giving a stran... by lultimouomo on Monday November 02, 2020 @09:41AM (#24968582)
You read the question, you immediately know Jon Skeet is giving the answer.
Re:Why is subtracting these two times in 1927 giving a stran... by mark-r on Monday November 02, 2020 @12:29PM (#24970627)
That's a perfect example of why Jon Skeet is untouchable in Stack Overflow reputation.
Re:Why is subtracting these two times in 1927 giving a stran... by daveslash on Monday November 02, 2020 @02:00PM (#24971698)
Two other interesting pieces of Time Trivia:

1. The date 30 December 2009 never existed in Somoa and Tokelau https://www.bbc.com/news/world-asia-16351377

2. Until 1937, the Netherlands Timezone was a nice, even, GMT + 00:19:32.13 -- yes, the timezone offset was to a hundredth of a second. https://en.wikipedia.org/wiki/UTC%2B00:20

Re:Why is subtracting these two times in 1927 giving a stran... by yread on Monday November 02, 2020 @09:03AM (#24968193)
Wouldn't you hit strange results doing this much earlier - there are leap seconds (or worse) every few years
Re:Why is subtracting these two times in 1927 giving a stran... by moomin on Monday November 02, 2020 @01:13PM (#24971133)
The fun thing about this is that just from the headline I knew who would have the highest rated and extremely complete answer.