DEV Community

Cover image for Dates are hard folks
Nick Taylor
Nick Taylor Subscriber

Posted on

Dates are hard folks

I saw this posted yesterday and thought it would be fun to discuss. "Scientists rename human genes to stop Microsoft Excel from misreading them as dates".

Dates can be hard when handling them in code. There's a reason people reach for date libraries. 😉

Anyone have some great stories about working with dates?

Top comments (21)

Collapse
 
merri profile image
Vesa Piittinen • Edited

Sure, this video is one of my favs regarding time!

Collapse
 
scgrk profile image
Stephen Gerkin

I love this video. Another great thing I like to link any time someone mentions timezones is this article: UTC is Enough for Everyone, Right?. It's quite long but absolutely hilarious and extremely informative.

Collapse
 
pilskalns profile image
Andžs

What a timeless piece.

I enjoyed every single word if it, the frustrations from common pitfalls that arise in every aspect of time/dates/zones/formats...

Oh, it hits home so well it's sad and funny at the same time.

Collapse
 
terabytetiger profile image
Tyler V. (he/him)

😂 That link is hilarious and definitely worth the long read!

Collapse
 
olivierjm profile image
Olivier JM Maniraho

Thanks for sharing

Collapse
 
shiraazm profile image
Shiraaz Moollatjie

Back when Flash/Flex was still a thing, user's used to submit date objects in forms. That time the rpc protocol used was something called BlazeDS.

What this BlazeDS used to do, is serialize the date with the timezone information and then send it over to the server (So you select 2020-02-03 as a date, it will send 2020-02-03 02:00am). Then the server would deserialize that date in it's timezone (so 2020-02-03 02:00am back to 2020-02-03 00:00).

All fine and well, because this was for a backoffice application. Until the day our software got deployed in a multinational company sitting between two timezones. So client sends a date in a +2 timezone, and the server sits in a +1 timezone.

Because two different timezones were being used for serialization/deserialization on on the client/server, the incorrect dates were always being used in ALL screens (50 or so). Took a good day or two for me to figure it out.

TL;DR; Always send dates over as strings and as UTC time.

Collapse
 
terpinmd profile image
terpinmd

even better send them as a number representing milliseconds

Collapse
 
shiraazm profile image
Shiraaz Moollatjie

it depends on the language you use. I wouldn't recommend this for Go specifically.

Collapse
 
kallmanation profile image
Nathan Kallman

User: Why does it show this event happened on a different date when I know it happened on X
Me: Because the event is recorded according to their timezone; which being close to midnight here, the time difference means they are on a different date.
User: Shouldn't it still show the same date though? It happened on X. I thought timezones only change the time.
Me: No... that's not how dates work...

Collapse
 
terabytetiger profile image
Tyler V. (he/him)

Not a story so much as a general frustration - I find myself having to convert Dates in Excel to Unix timestamps an awkward amount and Excel's base date being 1/0/1900 and UNIX being 1/1/1970 always causes trouble 😅

Collapse
 
molly profile image
Molly Struve (she/her)

My husband works in information security for a trading firm which means he has to schedule software updates for the company. For one update, he scheduled it for what he thought was UTC-6, but it was actually UTC. There is a video from the security cameras of him sprinting across the office when he realized his error to unplug all the servers to prevent them from running the update in the middle of the workday.

Collapse
 
nickytonline profile image
Nick Taylor

Dog slipping ice and sliding on their belly

Collapse
 
shane profile image
Shane McGowan

With the Java Date formatter "YYYY" and "yyyy" have a very slight difference.
YYYY will give you the year belonging to the current week (whatever that means and is useful for). So sometimes around the end of the year things break.
So, the 31st of December 2020. That week technically belongs to the year 2021, so YYYY was returning 31st of December 2021 from our API while the database was correctly storing it as 31st of December 2020.

ALWAYS use 'yyyy'

Collapse
 
ahferroin7 profile image
Austin S. Hemmelgarn

The 'YYYY' format is for week number dates (today is 2020-W32-5 per the ISO 8601 week date system). Week number dates are used a lot in manufacturing (or at least, the year and week number is, not the weekday as much) because that makes it easier to trace a given batch of products to a particular shift that was responsible for producing or checking them.

Collapse
 
olivierjm profile image
Olivier JM Maniraho

Dates are indeed hard especially when they are timezones involved, I had to deal with Timesheets at once and calculations went all well but the last for monthly calculations was on the 26th and timesheets would just go insane especially those on a different timezone. It was a nightmare for the first months.

Collapse
 
lexlohr profile image
Alex Lohr

Leap years and time shifts everywhere! They're out to get you. Run!

Collapse
 
wassimbj profile image
Wassim Ben Jdida

hhhh im actually right now working on a project, (adding some features and the feature is all about dates and times ! its actually sooo fun really thanks to momentjs :)

Collapse
 
mhm13dev profile image
Mubashir Hassan

I just started out with a random thought of building an age calculator from the birthday and it took me like almost 5 hours. It was seriously frustrating to work with dates.

Some comments may only be visible to logged-in visitors. Sign in to view all comments.