223
submitted 1 year ago* (last edited 1 year ago) by DroneRights@lemm.ee to c/programmer_humor@programming.dev

Yes, someone actually did this and I found it running on our server

top 50 comments
sorted by: hot top controversial new old
[-] xmunk@sh.itjust.works 74 points 1 year ago* (last edited 1 year ago)

As a Real Programmer(tm) I have developed such a deep fear of anything time and date related that I would fully endorse dispatching an API call to the tz_database instead of attempting any fucking part of this.

Kids, it's fine to meme about silly stuff... but date and time is deadly serious, regardless of how careful you think you're being you are wrong.

Do you know how many timezones there are in Indiana? No? Look it up and scream in horror.

[-] sunbeam60@lemmy.one 26 points 1 year ago

What if I told you that weekend days are locale dependent?!

Time and date is the black hole where optimistic programmers go to die. Nothing is simply with localisation and if you think it is, you mustn’t have worked enough with it.

Source: Run a system that schedules millions of interactions across the world and deeply depend on this. The amount of code to manage and/or call out to external services to give us information about time zones, summer time, locale specific settings, day names, calendar systems, week numbers etc etc.

[-] AndyLikesCandy@reddthat.com 9 points 1 year ago

Here's a fun thought experiment: What gregorian year and date will the spacian date value of zero correlate to? Trick question.

The atomic clock on the moon and every other celestial body colonized will simply start at zero, and thanks to relativity it will not actually be the same rate of time passing as on earth.

Enjoy your nightmares.

Luckily we won't colonize the moon or another planet anytime soon...

load more comments (1 replies)
[-] kogasa@programming.dev 5 points 1 year ago* (last edited 1 year ago)

IMO every datetime should be in utc, and variables for datetimes should either be suffixed "Utc" or have a type indicating their time zone (DateTimeOffset or UtcDateTime etc). Conversion to local time happens at the last possible second (e.g. in the view model or an outbound http request parameter). Of course that doesn't solve the problem of interoperating with other ~~morons~~ programmers who don't follow these rules, but it keeps things a lot neater locally.

Scheduling based on regional time conventions (holidays, weekends, etc) is just not great though.

load more comments (5 replies)
load more comments (3 replies)
[-] space@lemmy.dbzer0.com 56 points 1 year ago

You want to expand your business to Europe. Bam, your code is broken, in Europe the week starts on Monday.

Than you want to expand to the middle east. Bam, broken again... Because in arab countries and Israel, the weekend is on Friday and Saturday.

Then you want to expand to Mexico and India. Bam, broken again, their weekend is only on Sunday.

[-] kogasa@programming.dev 23 points 1 year ago

The obvious solution is to inject an IWeekendDaysOfWeekProvider service in the inversion of control container. In your, uh, javascript web app.

[-] coloredgrayscale@programming.dev 15 points 1 year ago* (last edited 1 year ago)

Just npm install isWeekend for the required locales.

Depends on: isMonday, isTuesday,...

load more comments (1 replies)
load more comments (1 replies)
[-] RonSijm@programming.dev 7 points 1 year ago

Not using CultureInfo.InvariantCulture for basically everything

[-] AndyLikesCandy@reddthat.com 6 points 1 year ago

This dude(ette) globalizes.

[-] Hadriscus@lemm.ee 5 points 1 year ago

I was wondering why the second example returned monday and tuesday. I had no idea the week could start any day other than monday

[-] eluvatar@programming.dev 50 points 1 year ago

Honestly the first one is the only one that works when people define the first day of the week differently. On the other hand, it does make you wonder. If Sunday is the first day of the week (as it is in many places) then how is it also part of the weekend?

[-] Esca@lemmy.one 15 points 1 year ago

But if you're worried about locale, you can't assume people use the string "Saturday" to describe Saturday either. That solution only works in English.

[-] jonne@infosec.pub 7 points 1 year ago

I assume this is in a language where the first day of the week is a fixed part of the language (like JS).

[-] subignition@kbin.social 12 points 1 year ago

Yeah it's the front end of the week and Saturday is the rear end

[-] Halosheep@lemm.ee 8 points 1 year ago

They're the week's ends, front and back.

load more comments (1 replies)
[-] dauerstaender@feddit.de 34 points 1 year ago

Why would you call it weekend and the start the week with half of it?!

[-] DroneRights@lemm.ee 28 points 1 year ago

A rope has two ends, and so does a week

[-] DrunkenPirate@feddit.de 28 points 1 year ago

Sentences have both meanings and sound, yours have sound

[-] Scrath@feddit.de 9 points 1 year ago

I like fancy insults

load more comments (1 replies)
[-] magic_lobster_party@kbin.social 17 points 1 year ago

Do you say weekend or weekends?

load more comments (3 replies)
[-] Matombo@feddit.de 34 points 1 year ago

Ok another US local units are retarded rant: it's called weekEND! why do you start your week at sunday and not monday! Sunday is part of the weekEND!

If you're referring to an "end" of an object, it can refer to the extreme of a side of it. For example, aglets are at either end of a shoelace.

[-] Matombo@feddit.de 4 points 1 year ago* (last edited 1 year ago)

I'm refering to end in a temporal sense because we are talking about a time context here. There is a clear direction so going backwards brings you to the begin.

[-] MrScottyTay@sh.itjust.works 3 points 1 year ago

I'm English, not American but I see it as Saturday and Sunday are the two ends of the week. Like how a string has two ends. The weekend is both the start and the finishing end of the week.

[-] ChrissieWF@discuss.tchncs.de 10 points 1 year ago

So, when someone asks if you are free the next two weekends, you assume they're talking about the next Saturday (tail weekend) and the next Sunday (front weekend)?

load more comments (3 replies)
load more comments (2 replies)
[-] irdc@derp.foo 30 points 1 year ago* (last edited 1 year ago)
weekend = day_of_week in (“sat”, “sun”)

As a bonus this completely sidesteps the issue of what day is 0 or 1.

[-] baseless_discourse@mander.xyz 6 points 1 year ago

Until some idiot sends in "Sunday" as days of the week...

[-] activ8r@sh.itjust.works 5 points 1 year ago* (last edited 1 year ago)

/^(sun|sat)/i.test(day_of_week)

👍

[-] snowe@programming.dev 9 points 1 year ago

Ah yes the ole sunweday. My favorite day of the weekend.

load more comments (1 replies)
load more comments (1 replies)
[-] Cosmicomical@kbin.social 27 points 1 year ago

You forgot weekend = dayOfWeek.name[0] == 'S';

[-] xmunk@sh.itjust.works 21 points 1 year ago

Can confirm this works completely as expected when the user's system is set to lang=ES.

[-] Schmeckinger@feddit.de 12 points 1 year ago* (last edited 1 year ago)

Simple save the users language setting in a variable, change it to english, check if the first letter is "s" and then change the language back.

load more comments (1 replies)
load more comments (1 replies)
[-] Lysergid@lemmy.ml 25 points 1 year ago
load more comments (23 replies)
[-] OneCardboardBox@lemmy.sdf.org 24 points 1 year ago

Interesting that your days are 1-indexed. What happens on nullday?

[-] xmunk@sh.itjust.works 9 points 1 year ago

Zat is vhen ve party!

load more comments (2 replies)
[-] MagicShel@programming.dev 23 points 1 year ago

I'd make it a named function for clarity and testability and proceed to give zero shits how it is implemented. I would unironically write this code if it worked, but I wouldn't inline it to reduce the cognitive load of reading it.

load more comments (3 replies)
[-] mac@programming.dev 18 points 1 year ago

Image Transcription: Meme


[Paneled meme with a brain that gets increasingly glowing]


[The brain is smaller than the skull]

if dayOfWeek.name == "Sunday" || dayOfWeek.name == "Saturday"
    weekend = true

[The brain is glowing in some areas]

if dayOfWeek < 2 || dayOfWeek > 6
    weekend = true

[The brain is shooting out rays of light]

weekend = !((dayOfWeek - 1) % 6)

I am a human volunteer who transcribes posts to improve accessibility on programming.dev and you could be one too! !transcribing@programming.dev

load more comments
view more: next ›
this post was submitted on 16 Nov 2023
223 points (95.5% liked)

Programmer Humor

19606 readers
1125 users here now

Welcome to Programmer Humor!

This is a place where you can post jokes, memes, humor, etc. related to programming!

For sharing awful code theres also Programming Horror.

Rules

founded 1 year ago
MODERATORS