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?

Latest comments (20)

Collapse
 
viksaaskool profile image
ViksaaSkool

The only reason I clicked this is because my first thought was that dates referring to mating.
Now those are harder than the ones in, let's say, Java.

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.

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
 
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
 
lexlohr profile image
Alex Lohr

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

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
 
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

Thanks for sharing

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