this post was submitted on 29 Jun 2024
874 points (95.1% liked)

Programmer Humor

31224 readers
50 users here now

Post funny things about programming here! (Or just rant about your favourite programming language.)

Rules:

founded 4 years ago
MODERATORS
 
(page 2) 50 comments
sorted by: hot top controversial new old
[–] [email protected] 12 points 4 days ago* (last edited 4 days ago)

Dates and times aren't that hard—honestly!

Video is a lecture about how to think about dates and times, through the lens of a specific open source .NET library designed to aid with applying that thinking. It points out how most languages' standard libraries really work against you, because they conflate different concepts. For example, an Instant (a specific point in time, globally recognised) and a LocalDateTime (a date and time in a way that is irrespective of your location—for example you might want your alarm to wake you at 8:00 am on weekdays, and still do that if you move to a different time zone), a ZonedDateTime (a date and time tied to a specific location—like if you want to say "the meeting starts at 10:00 am Oslo Time"), and an OffsetDateTime (a date and time tied to a specific UTC offset—which is not necessarily the same as a time zone, because "Oslo Time" is a time zone that doesn't change, but its UTC offset might change if they go in or out of DST, or if a place decides to change, like how Samoa changed from UTC-11 to UTC+13 in 2011.

These are all subtly different concepts which are useful in different cases, but most libraries force you to use a single poorly-defined "DateTime" class. It's easier and requires less thought, but is also much more likely to get you into trouble as a result, precisely because of that lack of thought, because it doesn't let you make a clear distinction about what specifically it is.

His library is great for this, but it's very worth thinking about what he's talking about even if you don't or can't use it. As he says in wrapping up:

You may be stuck using poor frameworks, but you don't have to be stuck using poor concepts. You can think of the bigger concepts and represent all the bits without having to write your own framework, without having to do all kinds of stuff, just be really, really clear in all your comments and documentation.

[–] [email protected] 5 points 4 days ago

stardate superiority

[–] [email protected] 3 points 3 days ago* (last edited 3 days ago) (2 children)

OMG, I'm dealing with a developer right now that is dealing with patient collected samples in several timezones, allowing the patients to either enter the time they collected, or use current time, and storing it in UTC time.

We do not receive any timezone data, patient collection data is showing different days than the patient could write on their samples depending on the time of day, and the developer said 'just subtract X hours' (our timezone).... for which not all patients would live in.

I suppose I could, if they'd provide the patient's timezone, but they don't even collect that. Can you just admit your solution is bad? It's fine to store a timestamp in UTC, but not user provided data... don't expect average users to calculate their time (and date) in UTC please.

load more comments (2 replies)
[–] [email protected] 7 points 4 days ago

Worst is UTC vs IAT

[–] [email protected] 8 points 4 days ago

Worst is when someone fucked up the DB time configs at some point and you have datetimes in a column that fall during the “nonexistent” hour in which clocks skip ahead for DST, and you have to figure out what the fuck actually happened there, and where in the data pipeline tz data was either added or stripped (sometimes it’s both, and sometimes it’s not just once), and undo the timestamp fuckery.

Source: did that this week. Was not super awesome.

[–] [email protected] 7 points 4 days ago (7 children)

I don’t know what the hate is unless you are trying to store time as a String property. There a special place in hell for all developers who do this.

IMHO, all you really need to know is an Epoch time stamp and whether it’s localized to the viewer or the creator… Not that complex. The problem with time zones is that politicians keep changing them

Honestly, I’d rather give the creator of NULL a slap.

load more comments (7 replies)
[–] [email protected] 3 points 4 days ago

Is GMT and UTC not the same? I'm happy to not have to code for timezones

load more comments
view more: ‹ prev next ›