this post was submitted on 16 Nov 2023
196 points (95.8% liked)

Programmer Humor

23710 readers
2333 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 2 years ago
MODERATORS
 

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

top 50 comments
sorted by: hot top controversial new old
[–] space@lemmy.dbzer0.com 48 points 2 years ago (4 children)

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 20 points 2 years ago (1 children)

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

[–] coloredgrayscale@programming.dev 13 points 2 years ago* (last edited 2 years ago) (1 children)

Just npm install isWeekend for the required locales.

Depends on: isMonday, isTuesday,...

[–] jcg@halubilo.social 2 points 2 years ago

...isWednesdayMyDudes...

[–] AndyLikesCandy@reddthat.com 6 points 2 years ago

This dude(ette) globalizes.

[–] RonSijm@programming.dev 5 points 2 years ago

Not using CultureInfo.InvariantCulture for basically everything

[–] Hadriscus@lemm.ee 4 points 2 years 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 44 points 2 years ago (3 children)

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 13 points 2 years ago (1 children)

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 5 points 2 years 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 11 points 2 years ago

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

[–] Halosheep@lemm.ee 7 points 2 years ago (1 children)

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

[–] Schrolli97@programming.dev 3 points 2 years ago

Thats not really one weekend then though, is it? Its more like last week’s post-week weekend and this week’s pre-week weekend

[–] Matombo@feddit.de 29 points 2 years ago (1 children)

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!

[–] Leate_Wonceslace@lemmy.dbzer0.com 7 points 2 years ago (1 children)

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 2 years ago* (last edited 2 years 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.

[–] irdc@derp.foo 27 points 2 years ago* (last edited 2 years ago) (2 children)
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 5 points 2 years ago

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

load more comments (1 replies)
[–] dauerstaender@feddit.de 27 points 2 years ago (1 children)

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

[–] DroneRights@lemm.ee 26 points 2 years ago (5 children)

A rope has two ends, and so does a week

[–] DrunkenPirate@feddit.de 21 points 2 years ago (2 children)

Sentences have both meanings and sound, yours have sound

[–] Scrath@feddit.de 7 points 2 years ago

I like fancy insults

[–] subignition@kbin.social 2 points 2 years ago

Methinks your username is a little too relevant right now :p

[–] magic_lobster_party@kbin.social 14 points 2 years ago

Do you say weekend or weekends?

load more comments (3 replies)
[–] Lysergid@lemmy.ml 23 points 2 years ago (22 children)
load more comments (22 replies)
[–] MagicShel@programming.dev 23 points 2 years ago (1 children)

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.

[–] Cosmicomical@kbin.social 2 points 2 years ago

This, and maybe a couple of unit tests

[–] Cosmicomical@kbin.social 23 points 2 years ago

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

[–] OneCardboardBox@lemmy.sdf.org 19 points 2 years ago (2 children)

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

[–] koper@feddit.nl 3 points 2 years ago

Reserved for future use

[–] mac@programming.dev 17 points 2 years 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 ›