News for hackers. Stuff that matters.
Re:Does Your Code Pass the Turkey Test? by QuercusMax on Friday December 06, 2024 @05:01PM (#42345004)
There's one more test: the Thailand test. I've been bitten by issues in Java where Calendar.getInstance() will return a Thai Buddhist calendar, which is exactly the same as the Gregorian calendar except 543 years in the future.
Re:Does Your Code Pass the Turkey Test? by klik99 on Friday December 06, 2024 @07:00PM (#42345946)
Exists in iOS too - once built an iPad black car dispatch app where one driver was constantly having issues. After weeks of remote debugging the car company owner just asked the driver to come in, as soon as he told me it was a Buddhist calendar I had it fixed. Now I always triple check my assumptions.
Re:Does Your Code Pass the Turkey Test? by brudgers on Friday December 06, 2024 @05:31PM (#42345279)
Wouldn’t issues in Java be failing “The Indonesian Test?”
Re:Does Your Code Pass the Turkey Test? by cirrus3 on Friday December 06, 2024 @06:37PM (#42345793)
Why are you using the Calendar API in Java? It is full of issues like this.
Re:Does Your Code Pass the Turkey Test? by tisdadd on Friday December 06, 2024 @08:29PM (#42346440)
I never really understood why not simply use milliseconds since the epoch and keep track of a time zone separately if needed... This allows fairly easy conversion to most native systems i have worked with, easy sorting and diff operations as well as final display control. Also don't have a need to be thinking about daylight savings then, or do other conversions for say timesheets.
Re:Does Your Code Pass the Turkey Test? by patrickthebold on Friday December 06, 2024 @09:48PM (#42346843)
It depends on what you need to do. If you just need to say when something happened (e.g. some log event) then milliseconds since the epoch is fine. If want a user to schedule a reoccurring meeting at 8am on the first Thursday of every month, you can also keep a set of timestamps as milliseconds since the epoch, but you are going to need to do some work to figure out the right numbers correctly.
Re:Does Your Code Pass the Turkey Test? by XCabbage on Friday December 06, 2024 @10:53PM (#42347127)
> If want a user to schedule a reoccurring meeting at 8am on the first Thursday of every month, you can also keep a set of timestamps as milliseconds since the epoch

No, you can't really, especially if the recurring meetings go on more than a few years into the future. If the time zone rules themselves change (e.g. if the user's country abolishes or introduces DST), then the timestamps you stored will become wrong in light of the change.

Re:Does Your Code Pass the Turkey Test? by tsss on Saturday December 07, 2024 @05:57AM (#42348898)
Because a calendar date and a point in time are entirely different things.
Re:Does Your Code Pass the Turkey Test? by klysm on Saturday December 07, 2024 @06:56AM (#42349166)
Timezone rules change. If you want to be fully robust, you need to store the intent of the time
Re:Does Your Code Pass the Turkey Test? by thebruce87m on Saturday December 07, 2024 @11:29AM (#42350797)
I don’t know anything about calendar pitfalls or Java, but I would have loved to see a better alternative suggested here.
Re:Does Your Code Pass the Turkey Test? by QuercusMax on Sunday December 08, 2024 @01:02PM (#42358745)
I didn't write the code originally; this was like 15 years ago. If the API still exists people will misuse it.