The Problem with Time & Timezones - Computerphile

πŸš€ Add to Chrome – It’s Free - YouTube Summarizer

Category: N/A

Building WordCloud ...

Summary

No summary available.

Transcript

00:00

sooner or later every programmer has to deal with time zones and I can't really offer much advice here I can offer a cautionary tale um I can tell you why you really should never ever deal with time zones if you can help

00:17

it let's imagine that someone has has built an application that lets you calculate how many seconds something is in the past you type in a date and a time it gives you the number of seconds and they they look at that and think okay that that kind of works for me but

00:33

let's let's add a little box that lets you change the time zone so if you're you know if you're comparing between now in New York and 5 days ago in London you can work that out and that's fine you know the little drop down lets you change which hour forward or backward of

00:49

Greenwich you are brilliant sooner or later after it gets a bit popular they'll get a call from Australia and Australia will say good day I'm not going to try and do accents um austr I just shouldn't do accents um Australia will say hello um by the way we're 9 and

01:06

1 half hours ahead of Greenwich and the program will go really I like yeah yeah 9 and a half hours oh okay I'll add a special case for you that's fine then a little bit later someone will call from Napal and they'll say hello um we're 5 and A4 hours ahead of grenic and they'll

01:24

say really I say yeah yeah we've been that for ages yeah 5 and a/ qu hours Great okay and they'll and put in a special case and maybe they'll look up the list of time zones the the canonical list that tells you what everything is they'll make sure they covered every time zone in the world and then Autumn

01:41

will come along and we'll get a call from England and uh England will say excuse me um we're an hour out at the minute what's going on and the work hold on the clock's just changed that's fine no no we dealt with that we dealt with we we made a note of when Daylight Saving changes for us and we've put that

01:58

in and and England will say no see Daylight Saving changes a week earlier for us it's different depending on where you live we we shift our clocks back a week before you do and and at that point that point generally the program will start to hold their head in their hands

02:14

and realize what they've got themselves into and that's fine you know they they'll put that in and they will deal with each country shifting to Daylight Savings Time on a different day and they'll look at the file that tells them how to do that and they'll copy all that in and then they'll get a call from someone in the southern h atere again

02:30

who will say yeah we're not shifting back in the Autumn we shift forward our our spring is in November and and that point they'll generally start looking longingly at their intoxicant of choice and wondering whether they should have a quick drink

02:46

before keeping going and and then they'll they'll code that in as well and then they'll get a call from Samoa out in the Pacific on the international dat line and Sor will say hello um yeah we we skipped today the other year and the program will say what say yeah we

03:02

skipped today we went from December the 29th 2011 to December the 31st we we shifted from one side of the International Date Line from being hours and hours behind grenic to being hours and hours ahead of Greenwich helps us

03:18

with trading with Australia can can you take account of that when you work out how many days things are and how many seconds things are in the past it's fine there's a there's a file that tells you when any country has changed its time zone and it turns out

03:33

that that happens fairly often but they they're announced ahead of schedule so as long as you keep that file updated and code that into your program's logic as well it'll be fine then you look back and you notice that during World War II England had double British summertime it

03:49

went completely onto BST and then just added an extra hour so it was 2 hours ahead of Greenwich despite having Greenwich that's fine you deal with that it's changing if you notice I'm starting talking as if as if it was you or me because I've done this before and it's really really frustrating and you make

04:06

sure that you subscribe to the list of when countries are going to change their time zones which happens apparently many times like sometimes several times in a year because governments change over and then then the program this this mythical programmer gets a call from Libya who in

04:23

2013 with only a couple of days notice decided that they weren't going to put the clocks back with enough notice said it wasn't possible for anyone to get the update out in time and meaning that every Libyan computer no matter what operating system it ran was an hour out

04:41

if it's okay you you read the news article about that and you hurriedly code that in as well and then then you get a call from the West Bank where the Israeli population is on a different time zone to the Palestinian population

04:56

because one is following Israel and one isn't and now you have two populations of people in the same location who are following different time zones and now they're all having to ask themselves whether they're on this time zone or or this one depending on who they are and where they are and there's no way to

05:12

code that into your program and then then you get a call from the historian who says right I'm trying to calculate some some times back in the 18th century and we changed from the Julian calendar to the to the Gregorian

05:28

calendar and it's not that we lost about three weeks it's just that we skipped right from this date to this date and and missed the others and can you code it so that so that it just kind of works that out for me and it's fine because someone else

05:45

has already told you when those dates are and and you can code that into your program's logic as well but now it's looking really long and really complicated it's Tangled mess of spaghetti code that somehow Works down and then you get a call from the Russian historian who says yeah we only changed

06:00

the Gregorian calendar in the 20th century and it turns out the dates that you skip change depend on depending on your location and and can you deal with that as well then you get a call from the British historian who says that until I think it was the 16th century the year started on the 25th of March

06:19

just to blow your mind there on the 24th of March 924 and then it will be the 25th of March 92 5 and that is the next day because you have gone from December 31st 924 to January the 1st 924 because it

06:37

goes in that order and it's massively complicated and then you get the call from the astrophysicist Who Says by the way we just had a leap second and at this point you just kind of go what leap seconds because the

06:54

Earth does not rotate at a constant speed it slows down it speeds up as as tectonic plates move about and and magnetic fields shift or something like that and so occasionally the international astronomical Union will work out whether we need a leap second

07:10

and if you do the clocks go 23 59 58 and then it's 23 59 59 and then instead instead of going like any sensible time zone wood it goes 23 59 60

07:26

and everything breaks because suddenly you have 61 seconds in a minute so depending on your implementation either your clock gets 1 second out of sync with the rest of the world or it repeats a second the way you're meant to deal

07:42

with this is something called the Unix time stamp a number file I think has talked about this before that that you have this number that started at the first exact second of 1970 and increments 1 second per second

07:57

constantly tick tick tick and that's great because what you're meant to do is you take whatever whatever date has been given you and you calculate that as a Unix time stamp and you put that into your database and and that'll just deal with leap seconds except it doesn't of

08:13

course it doesn't because because you have Universal Coordinated Time which which includes leap seconds and that it repeats occasionally and it just includes 2359 60 and then you have astronomical time which does not include leap seconds and has steadily been

08:29

getting out of sink with the rest of the world because we need to look at the stars and design telescopes around it and what you learn what you learn after after dealing with time zones is that what you do is you put away your

08:44

code you don't try and write anything to deal with this you look at the people who have been there before you you look at the first people the people who have dealt with this before the people who have built the spaghetti code and you go to them and you thank them very much for from making it open source and you give

09:01

them credit and you take what they have made and you put it in your program and you never ever look at it again because that way lies Madness Google actually has a really

09:17

really good approach to LEAP seconds that they invented themselves there's an article about it on on their blog I think that that explains it and they do something called a leap smear um because having 61 seconds in a minute or because having a clock tick back a second uh can be really really

09:33

bad for for massive agencies that sort of have to synchronize everything really precisely and have to trust uh that one bit of data was stored before another they essentially smear the second out over the whole day they increase their clock by a microsc at a time tick tick

09:50

tick tick tick all the way through the day so that it's sometimes maybe even half a second out from reality but as long as everything on their servers is half a second it's built to be out of sync with the world um as long as it knows that one thing happened before

10:06

another like having continuity is more important than actually having accurate time