r/ProgrammerTIL • u/aa599 • Jun 12 '20
Other TIL the danger of programming in Britain* during November..<April
While localtime is the same as UTC, code written in winter can have bugs which don't show up until daylight saving time.
Now I have to go through the database adding 3600 to a lot of numbers.
I guess countries which don't have daylight saving time (more than I realised according to Wikipedia Daylight Saving Time by Country ) have similar testing problems for exported code.
--
- other countries also use GMT, daylight saving time, and programming
111
Upvotes
9
u/lllama Jun 12 '20
It will be worse once daylight savings will disappear, though Brittain and other european countries might stay on summer time. Then countries that are ever exactly on GMT will be very limited.
47
u/ponytoaster Jun 12 '20
Tell me about it, a collegue was using a mixture of
DateTime.Now and DateTime.UtcNow
If you just use one its ok you can code around it or check, but a mix is a PITA and they did the work at a time the code "worked". Now we make it standard practice to store all dates as UTC
16
u/KagatoLNX Jun 12 '20 edited Jun 13 '20
TL;DR: Legacy systems + quirky dates = đ„
I work at a financial company that integrates with a certain large credit card network. In addition to the network itself running on 40-year-old technology, some of the equipment that end users inflict upon us misbehaves in a uniformly terrible manner.
One of the most egregious is when we receive dates with only two digits for the year or even no year at all. The field has room for 4 digits, they just donât fill them in. Thatâs right... in 2020, half of the worldâs credit card infrastructure still hasnât addressed the Y2K problem.
This is, of course, documented âstandardâ behavior. Why would you exclude people who canât be trusted to operate a calendar from integrating with critical financial infrastructure ? I mean, you could... but then youâd lose that sweet, sweet interchange revenue!
When we receive these obviously bogus dates, we have to guess what year is correct. One way to do this is to take the month and day they give us, then fill in potential year values and see which one is closest to the current time. So, for example, we might check something coming in as 07-04-0000 as 2019, 2020, and 2021.
There are other ways to approach the problem, but this one is one of the simpler ones. And, since most transactions are about events happening relatively close to ânowâ, it works surprisingly well.
Until February 29th, that is... Any other day of the year, next year or last year with the same day and month is a perfectly valid date. But not on that day. On this auspicious day, every time library will gleefully explode when asked to compare the current time to a time that is impossible. Itâs called a leap day because exceptions leap out of your code from surprising and unexpected spots.
As you might imagine, this is not merely a fairy tale. We recently experienced this particular joy. In our case, it manifested in two ways. Initially, our builds started failing because the test code generated bad dates. Just as we fixed that, it hit midnight UTC and we started failing transactions in production with almost the exact same exception.
Ironically, the test failures were not even remotely related to the code killing the transactions. It was the same type of bug but in an entirely different subsystem. Needless to say, many fun times ensued.
10
u/captain_wiggles_ Jun 12 '20
https://infiniteundo.com/post/25326999628/falsehoods-programmers-believe-about-time
Dates and times are much much more complicated than most people want to believe.
3
u/[deleted] Jun 12 '20
https://youtu.be/-5wpm-gesOY
3
u/ismokedwithyourmom Jun 13 '20
Always UTC! We're in the UK and had some servers in Northern Ireland and it caused a huge mess - we were told they were in the UK and some developers assumed the time would be the same but it's in fact an hour ahead
5
u/aidandeno Jun 12 '20
Kinda off topic, but DST is stupid and unnecessary in the modern world.
2
u/[deleted] Jun 12 '20
It's so much worse than that: https://www.youtube.com/watch?v=-5wpm-gesOY
0
u/[deleted] Jun 12 '20
[deleted] â view deleted comment