 Good morning. Originally I wanted to make my lecture in Swiss German, but I have nothing to do with my high German. And that's the reason why I'm going to speak in English. A day is only 24 plus or minus one hour and I have much less time to talk to you a little bit about how to check the time that you shouldn't check the current time too often and that you should check what your government does. My name is Miroslav Shedivy. I was born in Bratislava in Czechoslovakia, which is currently the time zone in Europe, Bratislava. I studied in France at Insalion, which is the time zone of Europe, Paris. And now I'm working as a senior software developer for Zolute Game BH in Karsruhe, just one and a half hour train ride from here to the north, which is time zone of Europe, Berlin. It looks like that I have spent my whole life in the central European time zone and that I have not so much to speak about it, but actually in our company Zolute, which stays behind the Germany's largest price-comparing website, Billigade A, we use Python and a lot of other open source software technologies and we have a lot to do with time as well. If you would like to come to the place where both bicycle and car were born and to the region of the best German wine and the best French beer, just speak to me after the talk or to my colleagues. Okay, I'm not going to do any live coding, but I have to do something with time, so please set your time to 10.33, central European summer time here in Basel in Switzerland, the 11th of July, because all the following slides will concern exact this time. When you are using Python and you want to get the current time, you can import the standard daytime library and then do daytime-day-time now and you will get the current time with year, months, day, hour, minute, second, microsecond, so 10.33, but this is not what you want to do because on your computer this is what you get. On a server set to UTC, you will get a similar daytime object that is offset by two hours because it's set to UTC and you see no difference between these two objects except for two hours offset in the hours. So if you compare these two daytime objects, you'll have an offset of two hours although they have been created at the same moment, so you don't want to do this because you don't know what time zone your server is on or your computer and you will get different results, so don't use daytime-day-time now. You can use daytime-day-time UTC now which will return also a daytime object always in UTC, so you see there is 8.33, so the current time in UTC, that's great. This is what you get on every computer but in Python explicitly better than implicit because here in implicitly you see, you know implicitly that you are in UTC but it is not in the object itself. So what you can do in Python 3, you can tell now and then tell the computer I want daytime-time zone UTC, I want the current time in the UTC time zone. This time you can use now method because you give it a time zone, it will return a daytime object that is time zone aware, it means that it knows that it is in the in some time zone. And with this object, with this daytime object with TZ info attribute set, you have an exact daytime object and you know what time is it, exact time, which is the same on every computer and you know also in which time zone it is, so this is completely explicit and perfect. But we are now here in Basel and we know to know the current time here, it is not 8.33, it's 10.33, so what you can do, you do the same, you create a new time zone which is defined by the time delta object of two hours offset and then you get the current time with the information we are two hours ahead of UTC and it is 10.33. Okay, but we know that now we are in the Central European summer time, so two hours ahead of UTC but in winter or 2022 or 1970, what was the time, we don't know whether it was, we were two hours ahead of UTC or not. So you have to reach out for a third party library, PYTZ is the best choice, the standard choice and in this case if you ask now, PYTZ time zone Europe Zurich, you define this Zurich time zone or you define, you use it, then you will get the daytime object, 10.33 correctly and in the TZ info field there is Zurich with two hours ahead of UTC and now you have an object that is perfectly defined as the local time here in Zurich or here in Switzerland. So this is how we get the current time but maybe you sometimes want to, sometimes you want to define the time literally, so create a new daytime object but not the current time but define it with all the attributes and then you use the daytime object constructor and you define all the fields, every month, day, hour, minute, second, microsecond and the last field is a time zone. But if you did, and you say I want today 10.33 in Zurich, the result you will get is daytime object but what you see in the TZ info, there is Europe Zurich but there is no CEST plus two hours, there is some LMT and 34 minutes, what's that? That's something that we are going to have a look at later but if you convert this to UTC you will get the current time 10.33 or the time 10.33 but not in the central European summertime but in some non-existent time zone that is 34 minutes ahead of UTC. So we don't want to do this. If you want to literally create a daytime object and give it a time zone information you have to create a daytime object that is time zone naive, it means you create daytime with all the information here, day, month and so on without the TZ info and then you pass it to a time zone object using the localized method and this way you will get the right object and you see in the TZ info there is central European summertime two hours ahead of UTC. Okay, now let's say that our current time with the Zurich information is in the variable now and we want to add some time delta offset 184 days which is approximately six months and then we will get a new object on the 11th of January 2020, 10.33 but what you see in the TZ info there is again central European summertime although in January there is central European standard time or only central European time with one hour ahead of UTC but here you get two hours ahead of UTC. So this is also actually wrong, the interpreter thinks that in January we are using, we are at the same time zone offset like now in July so you don't, if you use now, if you take this object and then you normalize it using your time zone object you will get 11th of January, time zone is the standard time one hour ahead of UTC but you will get in the hour field you will get nine o'clock, one hour less because actually if now you add 184 times 24 hours you will get really one hour less in your time information so if you want to add really wall clock, it's 10.33 you want to add some number of days and then get a date with the same wall time wall clock time you will have to take the now replace the TZ info, remove the time zone information then add those days and then localize it again and you will get the January time at 10.33 in the standard time please don't write everything down, just have a look at the normalize and localize methods of time, PYTZ library OK, so now for the next information I will just jump away from the time zones there is one thing that I wanted to show you let's say we have this piece of code, we need two strings one string with the current date and we want a string with current day of the week so we want 11th of July and Thursday with these two lines of code it's easy, you can read it very well but this code will break this code will give, not break but it will give you false information or information that you don't expect and at that moment very probably you are not sitting in front of your computer and I start these two lines of code one microsecond before midnight the first line of code executes on Thursday 11th of July the second line of code executes the next day you will get already Friday so you will get two time informations that are actually not from the same day what you want to do is to have a look at your clock only once you check the current time, you save it into variable it's a logical step in one function you work then with this now information if you have a method the best way is to pass the current time as a parameter then it will be testable much easier because you can fake the current time and then test it much better so check the current time only once on the other hand there is one exception when you want to check for the current time more often it is if you want in your runtime evaluate some runtime information for example some expensive operation like download you want to evaluate how fast your download or some operation is you get the current time at the beginning at the end you subtract these two daytime objects and then with total seconds you will get a float with the time difference but creating a daytime object with all this year and so on just to check the delta between two operations that's not probably what you really need it takes some time and you don't need to initiate daytime objects always so you can use the standard time library time.time, expensive operation, again time.time you get two floats, this difference between them and you're done the problem is that this can go wrong imagine that during your expensive operation your NDP date server runs so it means that the system clock of your computer will get updated and if it was too fast before and then the clock will be turned back time by a few seconds it can happen that your start happens after end and then elapsed is actually a negative number you don't want to program this because you cannot really test it it can happen at any time and it can have some very bad consequences so what you want to use is monotonic in Python 3 and monotonic returns some float that is guaranteed to be monotonically increasing it means that no matter what happens with your system clock your end happens always after the start if you are in the Python 3.7 you can even do monotonic in nanoseconds and you get an integer in nanoseconds so this was Python let's get back to the time zones how would you measure time a few centuries ago you would have a look at the sun when it is at the highest position that's noon another day again noon the difference between the two is probably 24 hours that's wrong there is equation of time probably on some wall clocks, sun dials and so on you have already seen something like an 8 this is equation of time and it defines that the rotation of Earth around sun means that our mean the sun position is not every day at noon at this highest position and it can oscillate here in Switzerland in our latitude by about plus or minus 15 minutes during a year so it means that during a year every solar day is not 24 hours long that's why statistically they calculated that we have to take something like a mean time and this is where this mean in the world of GMT or LMT local mean time and so on, this mean time comes from it means that during a year we calculate all these oscillations of the sun position and then we have solar noon which is approximately 24 hours after each other okay, so that's okay this is how you can get the current local time but then later with all the ships that travels around the world in Atlantic Ocean people wanted to get the current position the current position to get the current latitude is not so difficult because you see the sun at its highest position and you know okay it is at its highest position this angle, I know how far in the north or south I am but the latitude you can get now it is the local noon here but I have to know what current time for example in Paris on London is so I can calculate my distance from these cities the problem is that for many centuries you were not able to get a clock with you on a ship because all these sand, water clocks they didn't work exactly and even pendulum clock doesn't work on a moving ship so it took quite a long time and cost a lot of money and energy to develop a clock that you could take with you so this was on the sea but then even on earth you need something like coordinated time and you don't have to go anywhere else and the beginning of the railroad in USA they just everybody every city was using their local time and the problem was that once not only once but at least several times there were trains on a single track that just started at the same time and there were even some collisions and some debt because they didn't know what time is it exactly in this other city and according to their timetables they just sent two trains at the same time on a single track so that the government saw that they have to coordinate this time and then there were some regional or national times that were developed there was Greenwich France of course they had their own time the French railroad they took the for the standard railroad time they took the Paris time and they added 5 minutes to that and that was the French standard railway time the 5 minutes was there only to allow late passengers to get to their train but it was abolished after several years and then France used a single time and then they moved to GMT to the Greenwich time and this is how this is how Europe looked like at the beginning of the 20th century at least the time zones of course the borders of the countries were a little bit different but this is actually how it should look like today because you have Greenwich at zero one hour further 15 degrees we are actually in Prague and the border between them as the border like the middle way between them is at 7.5 degrees which is actually around the border between Germany, Switzerland, Italy and Benelux and France but as we know in 1940 Hitler invaded Benelux and France and then eventually European time and Franco in Spain that's cool we are going to do it again as well and that's how it remained but the time zones actually could be like Greenwich and then plus minus 12 hours so 25 time zones around the world but that's a lot like this if you import PYTZ and you ask what is the number of the time zones you will get 440 so you have seen like Europe, Zurich Berlin, Paris, Bratislava and so on all these have are separate time zones which means that they are not really all these cities in central Europe have now the current time and they switch to daylight saving time on the same date but these time zones how are they defined? like every place every country a larger city is defined as a separate time zone in other countries if there are more regions that follow different time zone different daylight saving time start and since 1970 they will be listed as a separate time zone 1970 this means that you can more or less rely on PYTZ using the times from 1970 it contains most of the information also from 1970 but they are not listed as separate time zones and we are going to look at that more specifically so these are the time zones in the world same colour means the same time now so you see Europe blue our central Europe has the same time as Eastern Africa because we are now one hour ahead more two hours under time even Antarctica has several time zones yeah where does this come from? I told you about PYTZ you tell me no no no I know Aero I know DeLorean okay you can use any library you wish but all of them will be based on this information coming from IANA which is Internet Assigned Numbers Association this is not an authority like United Nations this is like only an association that observes all this information and they list it on their website this is what all the operating systems except for MS-DOS and similar use this so UNIX all the systems they are based on this if you go to this website you will find two things there is archive downloadable file with the edition of the Dizzy data and there is a mailing list you can see the archives and you can also sign up and follow it and this mailing list is actually something that is the source of this whole information in this mailing list people write oh our government is going to switch to Dayline Saving Time next year or we are going to abolish it or I have read something or I have found an information that Russia in 1917 in some region they did something differently and all this information is compiled and released from time to time the current version comes from the last week this is the data 2019 this B means this is the second version of 2019 this year it is really quite very quiet but usually there are up to 11 the releases per year and this file if you download it 300 kilobytes if you unpack it you will find some pearl or shell scripts some documentation but the most interesting are these files called Africa under South, North America, Europe and so on these files this is like a book of history of the mankind in the past 130 years it is really interesting read there are two things in each file there is some code that will be interpreted by all the parsers and converted for example to PYTZ to time zone libraries for all different programming languages for database systems for your system for everything and there are the comments that explain what which line means and we are going to have a look at that if there is one picture you want to take from this talk this is the one if you want to read it correctly turn your heads to the left so X axis are the years from 1890 to 2038 and on the Y axis if you just look like this the zero is Greenwich and everything down is West so America zero is Europe Africa and then there is Asia and Australia and every line is one of these 440 time zones and all that changes through more than one century at the beginning what you see is really wild this is the local time of each respective time zone this is for example at 33 minutes above zero we will find Zurich 34 minutes this is the 34 that we have seen at the beginning time zone object for Zurich at the beginning these 34 minutes it means that Zurich at the beginning was defined as 34 minutes ahead of UTC then you see that it is more normalized to more or less 24 24 different time zones there are some half hour time zones some quarter hour time zone and then what you see this is daylight saving time every year then it stops then maybe you don't see that some lines just jump by one or two time zones to one or other direction and then what you see sometimes there are vertical lines through the whole spectrum and the vertical lines there are random pacific ocean islands that just jumped the whole day and moved from the eastern hemisphere to western or vice versa 2019 the blue line this is now and now what you see this daylight saving time it goes on until future this is how it is defined it means if you say I wrote a python application I tested it I put it in virtual and it can run intimately this is what it will do the whole time 2021 European Union wants to abolish daylight saving time switching your code will just jump so don't forget to update your libraries this is more defined specifically Europe you see that every time zone is positioned in the large city so we have for example Switzerland in Switzerland you see Li I will explain it later yeah so this is how it looks in Europe and this is how the time zones look more specifically in Europe only the European time zones in 1919 you see there are quite wild jumps somewhere in Russia and between 1919 and 1940 you see a blue line around the minus one no plus one that is a little bit offset but very regularly that's Netherlands so but let's return back to Switzerland we are going to have a look at Europe Zurich time zone so this is what you find as a code Europe Zurich and then you have the offset the dashes or Swiss or EU are the rules I'm going to explain that then the short name of the time zone you see LMT LMT is local mean time so LMT every time zone had once LMT then there is BMT this is burned mean time and CE is central European summertime or it's not and then the last column is until when it was valid so it means Zurich as a time zone until 1853 was 34 minutes and 8 seconds ahead of UTC and then they switched to burn mean time so it was still called Europe Zurich there is no Europe burn but the mean time in burn is 5 minutes less so this was still not the whole Switzerland because Genève stayed with their time until 94 and only then they followed the Swiss time zone rule so important is this time zone before 1970 is valid only for Zurich because burn had their own local time Genève Fribourg Lausanne and so on every every city had their own mean time so if you want to calculate something for for any city before 1970 you can calculate it only for Zurich so and there is this Swiss what does Swiss mean it is defined somewhere else that during the World War 2 Switzerland experimented a little bit with daylight saving time only once they just abolished it and this EU rule this is something that most European time zones are using and you see there was some different time zone in 77, 80 and so on but Switzerland started following it but European time zone rule is started in 1977 it means that there were already countries that followed the European rules Switzerland joined a little bit later and that was chaos we are going to have a look at that but the most important lines if you are working with European time zones are the last two lines because this is actually what we are using now the last lines you see that from 1981 on the last Sunday of March we are going to start daylight saving time and it goes until the end of October and these two max words mean that it is defined undefinitely so in the future always it will just jump between daylight saving time and standard time who remembers that the daylight saving time didn't run until end of October the whole time because until 1995 it was until the end of September so our generation should remember that there are some new lines to this file so there is Wadus Liechtenstein so you can use Europe Wadus Europe Zurich they are the same this is just a simple link and there is this Büsingen ever been to Büsingen this is Germany almost there are two time zones in Germany both of them start with B the other one is not Bonn it's Büsingen this is not far away from here if you see the border between Germany and Switzerland this is the Rhein river but river is like this and the border is not exactly the river because there are some villages on one side and on the other side and there is one bigger city called Schaffhausen a very famous waterfalls on Rhein river and this is like a region and next to Schaffhausen there is a small village Büsingen 1500 inhabitants they have two postal codes like the Swiss and the German one you can call them using 49 or 41 phone call like through Germany or Switzerland and they have their own time zone why is that? because these are the 70s and 80s in Europe when the Great Saving Time was introduced you see the year 70 starts in 73 goes to 85 and you see the numbers 0 to 30 to 29 these are all the time zones all the European all the capitals of the European Union countries some of them are plus, minus minus one or plus one and the graph shows the offset in many countries there is currently the offset so usually now you would see something like in winter and in summer but when you see some irregularities it means that there were countries that started with their deadline saving time a little bit sooner a little bit later so at the beginning there were only 5 or 6 countries and later there are more now all of them are following the deadline saving time and if you see small jumps it means that some countries started with their deadline saving time a week later, a week sooner, 2 hours later and so on at the end of the 70s it was real cows in Europe and Germany started with their deadline saving time I think in 1980 and Switzerland didn't only one year later and Büsingen we forgot to switch with Germany we are going to stay with Switzerland and that's why Büsingen links to Zurich and the other countries Berlin at the beginning it was 53 minutes 28 seconds ahead of UTC then there was at the beginning of the 20th century it was like central European time zone more or less and then at the end of the World War II there was Soviet zone during some time Berlin followed Moscow time so there were 3 hours ahead of UTC and then there was Germany rule Paris, France again there was local time, Paris meantime and during World War II the CEU central European time together with Germany of course and since 1977 they started with their deadline saving time and this is Amsterdam in the comment there is written that Amsterdam meantime was actually 19 minutes 32 seconds and 30 seconds so really time that you cannot really calculate very easily the offset but then they joined through Germany they joined central European time now you hear something like summertime or deadline saving time and standard time in some languages there is a concept of summertime and winter time summer time, winter time the problem is that there is no winter time there is only one exception in the history of the world there was in one country once winter time and this was Czechoslovakia 1946 the parliament did a law that the government may declare winter time then they did it on the 27th of November that it will start on the 1st of December and on the 1st of December Czechoslovakia will go in the standard time even one hour back so this was not daylight saving time it was daylight wasting time it worked until the 23rd of February then abolished and never introduced again but this law is always valid and Czech Republic and Slovakia in 1993 followed they took all the laws from Czechoslovakia it means that now it is even in the book of laws it means that the Czech government may declare winter time at any time so when you travel to Prague or Bratislava just pay attention whether they are not on the winter time again so this was Europe quite predictable now hopefully but let's have a look at some other time zones for example there is Istanbul which is Europe, Istanbul or Asia Istanbul because it is on both continents and then you see some information you have already seen this on March 27, 14, 15 sometimes EU rule and sometimes something different what does that mean? there are comments Turkey will change into summertime on March 28 instead of March 27 this change is due to a nationwide exam it means on the 10th of March less than 3 weeks ahead they decided we are not going to start daylight saving time on Sunday we are going to start it on Monday you can now imagine how fast you can update your systems 2014 again DST for Turkey has been changed for this year because of the Turkish local election so Turkey will move clocks forward one hour, one day later again mid-February that's not early enough the second comment is from Randall Schwartz having landed on a fly from the states to Istanbul I can tell you that nobody respected this time zone change delay maybe the word just didn't get out in time imagine airports that have their embedded systems they are not going to update that fast 2015 is officially announced that it delays winter time to the days of November so they are going to start it one week later BBC news EST Erdogan engineered standard time if you have automatical systems it doesn't work 2016 there is little code but a lot of comments they want to stay in daylight saving time even in winter it is permanent, no they are going to go back so actually at some point the versions included information that something will change but then the government decided no they are not going to change it so the comments they are left in the database but the code just changed Karakas, Venezuela clocks advance 30 minutes on the 1st of May announced 2 weeks ahead there is some URL from Reuters and then very important published in the official Gazette and a link to a Venezuelan URL you click on it there is some PDF file from the government that says that they will update it the work, the job of people who do something in this mailing list is checking for all the sources and then try to get the best information they can get and then publish it here because sometimes you even don't know because there is no official Gazette from the government you just read it in some local newspapers Povta Prans, this is Haiti in summer they have 13 hours of daylight in winter 11 and still since 10 years they vote in February, March and they say that they will be in the same time or not always with 30% probability the last sentence we have received 4 mails from different people telling that Haiti has started DST again today and this source seems to confirm that I have not been able to find a more authoritative source so if there are enough people who just say okay I have seen that maybe people in the IANA database maintaining group are going to say so in Pyongyang South and North Korea until 45 it was of course the same and then South Korea experimented with oh we are going to move from plus 9 to plus 830 in 54 so the whole country moved half an hour back but all international authorities like everything that has with naval aeronautics, meteorology telecommunications they just were afraid that they would have problems with the exterior so they stayed with plus 9 hours so it means South Korea was internally was half an hour behind the external services North Korea they started experimenting quite late 2015 according to many new sources North Korea is going to change to the 830 time zone on August the 15th announced one week ahead but the most important of course bells rang out midnight as part of the celebrations 2018 they moved back North Korea re-revert its time zone again back to Korea standard time announced on the 20th April while the change was on the 5th of May so only six days ahead, seven days ahead and then the last thing it appears to be the front page story at the top in the right most column you click you get a pdf with 10 columns with some Korean text and then you can find the information that the government is going to switch to a different time zone so you know everyone does like he's pleased so this is where you can get the information I invite you probably to read more, you will find certainly something that I have missed and then please give a lightning talk tonight or tomorrow that you have found something about your time zone and the question is what will happen after 2021 because European Union is going to stop switching probably is going to stop switching between daylight saving time and standard time but it is not sure whether they will stay with central European time or switch to they call it summer time but actually Eastern European time so what will happen some big country maybe will decide okay we are going to stick with that time zone and all the surrounding we don't want to have a border with you with different time zone we are going to go with you but it is wrong because nowadays they are European Union internal borders that have time zone differences like between Portugal and Spain between Poland and Lithuania or between Hungary and Romania but what will happen Zurich will probably keep the EU rule and only in the last two lines this max is by 2021 or a combination of that so what you can do to avoid or avoid not to get mad about all these time zones don't invent your time zones never don't hard code any rules if you check is it the last Sunday of March between two and three o'clock so I have to do something no keep your time zones lips up to date it means if you what you can even do is to somewhere to store the information that these local time zones are from the TZ data version 2019 B because in the next edition they may change for example 2019 B edition introduces the abolishment of daylight saving time in Brazil so for example this year Brazil in our winter is not going to start daylight saving time and if you now have Linux system it is still not in TZ data so you have to update it later when it comes follow your government's intentions to modify your time zone and inform TZ IANA please if you write a nice comment it will just stay in the archives and a future me or someone else is going to show your comments in a talk and if you can avoid the time zones thank you very much talking about time we've got five minutes left for questions so come to the microphones or get mine hello can I give you one new example for your slides when Europe moves away from summertime and around that time is very possible that the UK will have left the EU Ireland at the moment shares a time and will probably work with Europe in the same time zone and get rid of daylight savings that will mean that in the south of Ireland the time zone will be one hour different from the north of Ireland so moving north or south to north you can go back in time just a little example fair enough thanks other questions yes please so the presentation you mentioned the example of localising a time in the wrong way and then getting an offset of 34 minutes and you showed that the 34 minutes was actually an old time zone can you tell us why does it do that like why does it pick the first time zone because yeah that's there's some internal implementation I didn't study that but I mentioned that actually this PYT is a time zone passive and active object passive would be okay I am here use my attributes and active is I have to take your data and do something with that because actually time PYTZ has to calculate what was the real time zone offset at that time in the history time zone localise it also decides whether it is whether the time is right because imagine that you give it the data object that is time zone naive from the end of October to 13 in the morning where it is not clear whether it is the daylight saving time or not so actually it has to decide so you have to pass your data to this object I have heard that some people are unhappy with the implementation how Python that does you recommend it I started using data utils instead of PYTZ because that follows your operating system so you don't have to rebuild your code is there reason you shouldn't use it okay as I told you PYTZ is more or less the standard but data util is perfect as well because both of them are based on TZ data and this depends on the operating system you are using so for example in different Linux distributions PYTZ is depending on TZ data or not so for example if you update TZ data all libraries will get the correct but in Arch Linux PYTZ is compiled itself and it doesn't depend on the TZ data package and this happened last year in May, June when North Korea switched from 8.30 to 9 and on one computer with the current system Arch Linux computer I asked for the current time in Pyongyang in Linux in the command line and in Python and there was offset of half an hour because PYTZ was still in the old version and TZ data was already fresh so you have to pay attention how it is compiled, how it is on your system if they do it depends on TZ data it's perfect but actually you can compile they do it probably that it contains all the information itself I don't know it's possible is PyTZ used in the standard Python libraries like datetime so if I do a calculation there going 100 years back I will not end up from today's midnight at 100 years sometime during the day because there was some weird offsetting PYTZ is not in the standard library it is not in the standard library because it is something that changes quite often several times a year it is not in the standard library because otherwise you could take some current Python compile it and then run it infinitely the TZ data information you have to update it so if there are no further questions we are running out of time just switch it out to MiWu MiWu will be around and give him a big round of applause thank you