▲ | kccqzy 5 days ago | ||||||||||||||||||||||
> people’s birthdays changing when they move timezones That's because the developers use datetimes (aka timestamps) to store a single date. Just pick an arbitrary epoch date (such as January 1, 1900 as used by Excel, or my favorite January 1, 1600 since 1600 is a multiple of 400 making leap year calculations even simpler) and store the number of days elapsed since then. The rules involving leap years are much much simpler than rules involving timezones and timezone databases. The translation from/to this representation to a broken-down y/m/d takes only ~50 lines of code anyways. Of course if you don't need to do arithmetic on dates, just store three numbers, year, month, and day. | |||||||||||||||||||||||
▲ | SoftTalker 5 days ago | parent | next [-] | ||||||||||||||||||||||
No, don't do that. Use a date datatype (not date/time). You aren't the first person to ever need to handle dates without times/timezones in a computer program. Use what your database/language/libraries already have to support that. | |||||||||||||||||||||||
| |||||||||||||||||||||||
▲ | happytoexplain 5 days ago | parent | prev | next [-] | ||||||||||||||||||||||
In my humble opinion, this is not good advice unless you demonstrably need it for query performance or something. It is very easy for the logic layer to accidentally mess that up, either in reading or, worse, in writing back. In this case, I'd suggest storing what you mean (the user wasn't born 9,487 days after Jan 1 1970. They were born Dec 23, 1995.) Storing the literal units (and ONLY the relevant units), as the parent has, is robust and logically+semantically correct (they could add a translation layer for UX so the user doesn't have to be particular, but that's beside the point). Whether you use a string or a struct or some date-only type is moot, as long as you're literally storing the year, month, and day, and only those three things. You can ephemerally convert it to your platform's date type if you need to. | |||||||||||||||||||||||
▲ | pavel_lishin 5 days ago | parent | prev | next [-] | ||||||||||||||||||||||
> The translation from/to this representation to a broken-down y/m/d takes only ~50 lines of code anyways. Didn't the article explicitly tell us not to write our own date parsing library? | |||||||||||||||||||||||
| |||||||||||||||||||||||
▲ | habibur 5 days ago | parent | prev [-] | ||||||||||||||||||||||
> or my favorite January 1, 1600 since 1600 is a multiple of 400 You need to deal with 1600 and 2000 being leap year. While 1700, 1800, 1900 not being a leap year. I limit dates from 1900 to 2100. All !year%4 = leap year. Especially when you try to convert int_date to y,m,d things get tricky. | |||||||||||||||||||||||
|