Hacker News new | ask | show | jobs
by karpierz 1589 days ago
I'm not sure I follow.

If I define a date MM/DD/YYYY as equal to the time MM/DD/YYYY 00:00 GMT, which of the equality properties am I lacking?

Similarly, if I use that definition of equality to convert the date into a time, and then compare it, can't I get '>' and '<'?

3 comments

> If I define a date MM/DD/YYYY as equal to the time MM/DD/YYYY 00:00 GMT

That's the exact problem - if you contrived a date into an int then yes, it is compatible with the =, >, and < operators.

The point of the blog post is to assert that that contrivance is not appropriate in nearly all use cases, despite how popular it seems to be. In the vast majority of use cases contriving MM/DD/YYYY into MM/DD/YYYY 00:00 GMT is not reasonable and can mask a vast amount of unintended behavior.

For example, a person in California who enters a date of 06/05/2022 in reference to their local time zone will suddenly wind up the day before - because 06/05/2022 00:00 GMT is actually 06/04/2022 16:00 PST.

If the developer wants to contrive the date into a "midnight instant", they are welcome to do so and there should be plenty of convenience functions to allow them to do that, but implicitly performing that contrivance is dangerous.

Wouldn't 06/05/2022 00:00 GMT be 05/05/2022 16:00 PST due to the DD/MM (GMT) MM/DD (PST) notation swap
Well it depends on if you have a type system that distinguishes between "date" types and "instant" types.

If you only have instants, then sure, you could do what you're saying, but the context in which the question was poised seems to imply that "dates" and "times" are separate.

And if you do have separate "date" and "instant" types, you lose the property of substitution: f(x) = f(y) if x = y for any arbitrary function f.

Sometimes the mapping is context specific...

For example non-mathematicians/programmers will specify date range as 2022-01-01 to 2022-01-31.

to map this you need a special mapping to convert to instant... (you need to map the upper range to 2022-02-01 (00:00), anything else is probably wrong).