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

18 points

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

permalink
report
reply
1 point

Depending on whether this code is in a hotpath (and considering how “elementary” it is, I figure that’s a possibility), this could very well be a significant speed improvement.

Though I’d say that only excuses it if it’s truly an elementary function (and not one line as part of a larger function), as otherwise it’s unreadable garbage. But on its own it:

  • has a clear purpose
  • (presumably) isn’t reimplementing functionality
  • is easily tested
  • can be modified with no side effects (besides breaking your calendar, but that’s beside the point)
permalink
report
reply
1 point
*

It’s one line as part of a larger function. Also, it doesn’t actually say weekend, it just executes some other functionality if !(day % 6). I made it more readable so that everyone here could understand what it does

permalink
report
parent
reply
25 points

weekend = dayOfWeek > 5

permalink
report
reply
-10 points
*

Sunday is 1 0 and Saturday is 7 6. You just made Friday part of the weekend You forgot Sunday

permalink
report
parent
reply
21 points

On which planet? Monday is 1

permalink
report
parent
reply
4 points

I was off by one, but Sunday is 0 in javascript

permalink
report
parent
reply
11 points
*

Both Monday and Sunday are used as the first day of the week with quite some regularity. It’s a completely arbitrary standard no different to "the tenth month is the one called “October”. Or dividing a day into 24 segments which are each broken into 60 smaller segments of 60 even smaller segments. You can’t say either is “wrong” per se.

Personally, I was brought up learning Sunday is the first day of the week, but at some point decided that was bullshit partly because it’s the week end. But also just from a practical standpoint when looking at a calendar, it’s useful to have the weekend days grouped together.

permalink
report
parent
reply
1 point
*

Depending on how you’re counting your integers, Monday is 0, being the first day of the week.

permalink
report
parent
reply
9 points

On planet America.

permalink
report
parent
reply
1 point

dayOfWeek is clearly represented by 1-7 in the example, with Sunday being 1.

So, I guess the answer is “depends on what date library you’re linking against”

permalink
report
parent
reply
27 points

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

permalink
report
reply
21 points

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

permalink
report
parent
reply
1 point

true but that’s a precondition to some of the other examples as well

permalink
report
parent
reply
12 points
*

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.

permalink
report
parent
reply
2 points

Genius.

permalink
report
parent
reply
33 points

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!

permalink
report
reply
3 points

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.

permalink
report
parent
reply
1 point

since we are in a temporal context here i would argue that there is a clear distrinction between beginning and end here

permalink
report
parent
reply
2 points
*

End doesn’t always have to be the latter side of something though like I said earlier with the string analogy. The start is also an end.

permalink
report
parent
reply
10 points

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)?

permalink
report
parent
reply
-1 points

No, the two ends of a week create a singular weekend.

permalink
report
parent
reply
9 points

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.

permalink
report
parent
reply
4 points
*

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.

permalink
report
parent
reply

Programmer Humor

!programmer_humor@programming.dev

Create post

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

  • Keep content in english
  • No advertisements
  • Posts must be related to programming or programmer topics

Community stats

  • 7.1K

    Monthly active users

  • 952

    Posts

  • 36K

    Comments