Comment on CFCs

<- View Parent
SpaceCowboy@lemmy.ca ⁨6⁩ ⁨months⁩ ago

First of all, midnight in what timezone? A timestamp is a specific instant in time, but dates are not, the specific moment that marks the beginning of a date depends on the timezone.

What are you talking about? The same problems apply no matter which format you’re talking about. Depending on which side of the dateline your timezone is on you could wind up with different dates.

Does your janky string format of “18-03-2024” suddenly has to become aware of the timezone if I tack on a “0:00” at the end of it? Or maybe you always will have timezone issues no matter what the precision of the time you want to store.

I think you got it in your mind that you can’t do anything other than Timestamp=getdate() and if it’s a date only you have to use a string. That’s not the case. You can indeed translate a date into any number of formats, unix time is one of them. I assure you that 1710720000 will translate to the same janky “18-03-2024” format you’re using every single time unless you deliberately mess with timezones in code where you admit that you don’t want to deal with timezones. But your string jankiness break simply by someone parsing it with MM-dd-yyyy just as easily and this may not require someone to do something to deliberately break it. Depending on the library that’s being used and the localization settings of the OS, this can happen automatically. If your code will break because someone has different OS settings than yours, you are writing bad code.

If the goal is to save space then your format uses 10 bytes, while the timestamp uses 4 (with Y2K38 problems) or 8 with 64 bit Epoch time. If you’re not too worried about saving space (you really shouldn’t be these days) then use the appropriate structs defined by the language you’re using and the DB you’re using.

Even this would be better than a string:

struct { int year byte month byte day }

Six bytes as opposed to 10 and there would be no issues with confusion with the dd and MM parts of the string. It’s still shit (use existing date libraries instead) but still won’t have as many problems than what you’re doing. Seriously anything is better than just dumping a date into a string. And as I say, using the dd-MM-yyyy format is bad for multiple reasons.

Though congratulations, you’ve convinced me that Y2K might’ve been a bigger problem than I thought given how adamant you are about repeating similar mistakes that caused those issues. I guess even when there’s very obvious problems with how someone’s doing things they will insist on doing things that way even when it’s pointed out all the problems with it. I can imagine someone in the 80s and 90s pointing out the Y2K problem to someone writing the code and getting some arrogant bullshit about how only mid-level programmers worry about that. “Experts put dates in strings LOL!”

source
Sort:hotnewtop