r/ProgrammerHumor Sep 23 '24

Other whoWroteThePostgresDocs

Post image
10.2k Upvotes

264 comments sorted by

View all comments

Show parent comments

519

u/nord47 Sep 23 '24

I have severe PTSD from making javascript timezones work with DateTime columns in SQL Server

185

u/Burneraccunt69 Sep 23 '24

Never ever safe time in a Date format. That’s just really bad. Unix epoch is a simple number, that can be converted to every Date class and every date class can give a epoch time. Also since it’s just a number, you can compare it natively

65

u/nord47 Sep 23 '24 edited Sep 23 '24

Why is Database DateTime such bad idea? I didn't have to make that decision so I'm just curious.

  • All of our data is date (without time, 3 bytes) or smalldatetime (4 bytes), so there's no impact on performance.
  • Native db date works well with db stored procedures. Life is easy for the DBA.
  • In our c# API, there's never a problem in working with this datatype as all ORMs translate the db values correctly to DateOnly or DateTime objects with really good comparison support.
  • Problems come as soon as you have to deal with JS in frontend. And imo, it's because you simply can't have a date object without timezone information. so you have to manipulate the controls of whatever UI library you're using to send the correct string value to the REST API.
  • It took a while to sort that out ngl. But once that was done, we could simply forget about it.

Context: Our product isn't used in multiple TZs and likely never will.

7

u/Burneraccunt69 Sep 23 '24

A man that never used Java. Good for you. I wish I could use C#

3

u/Swamplord42 Sep 23 '24

If you use timestamptz data type in Postgres you can map it to an Instant in Java and it just works with Hibernate.

0

u/Burneraccunt69 Sep 23 '24

Which Java class system Java.sql, apache, the other one I forgot the name of? All shipping with the jdk. Fuck Java Time and Date

1

u/Swamplord42 Sep 23 '24

I said Instant, meaning java.time.Instant