There have been multiple accounts created with the sole purpose of posting advertisement posts or replies containing unsolicited advertising.

Accounts which solely post advertisements, or persistently post them may be terminated.

Matombo ,

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!

MrScottyTay ,

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 ,

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

MrScottyTay ,

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

JohnEdwa ,

Just like the two ends of a string create a singular string end.

Magnetar ,

I’ve never understood string physics.

Matombo ,

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

MrScottyTay ,

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.

Leate_Wonceslace ,
@Leate_Wonceslace@lemmy.dbzer0.com avatar

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 ,

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.

space ,

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.

Hadriscus ,

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

kogasa ,
@kogasa@programming.dev avatar

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

coloredgrayscale ,

Just npm install isWeekend for the required locales.

Depends on: isMonday, isTuesday,…

Elderos ,

This but non-ironically.

RonSijm ,
@RonSijm@programming.dev avatar

Not using CultureInfo.InvariantCulture for basically everything

AndyLikesCandy ,

This dude(ette) globalizes.

OneCardboardBox ,

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

xmunk ,

Zat is vhen ve party!

coloredgrayscale ,

Undefined

koper ,

Reserved for future use

xmunk ,

As a Real Programmer™ 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 ,

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.

kogasa ,
@kogasa@programming.dev avatar

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.

usrtrv ,

Throwing UTC everywhere doesn’t solve comparisons around leap seconds. I’m sure they’re other issues with this method, but this is kinda the point of “just use a library”. Then it’s someone else’s problem.

kogasa ,
@kogasa@programming.dev avatar

I’m a .NET dev, I don’t have a concept of “just use a library.” Everything is a library. I don’t mean “using int for datetimes is ok as long as you label it utc,” I just mean “don’t deal with time zones.”

v9CYKjLeia10dZpz88iU ,

Unix is the easiest format I’ve used. It’s easy to parse, it’s consistent, there’s not usually competing unix like formats, it converts perfectly to other time formats, most file explorers can immediately sort it correctly, and it’s clearly the date from which the universe spawned into existence.

xmunk ,

It’s alright, but real programmers use Julian UTC.

v9CYKjLeia10dZpz88iU ,

I also really like the Bitcoin block number. It will likely be one of the most provable records of time passing, but not as convienent for tracking or converting time.

coloredgrayscale ,

Luckily we won’t colonize the moon or another planet anytime soon…

AndyLikesCandy ,

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.

DAMunzy ,

2 timezones but the complication is that it is dependent on which country you’re in?

xmunk ,

There are two distinct time offsets used in Indiana but there are 11 different timezones en.m.wikipedia.org/wiki/Time_in_Indiana

Zanothis ,

Relevant talk by Jon Skeet

invidious.io.lol/watch?v=64X8rCy1jSA

Cosmicomical ,

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

xmunk ,

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

Schmeckinger , (edited )

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.

xmunk ,

Genius.

Cosmicomical ,

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

mac ,
@mac@programming.dev avatar

Image Transcription: Meme


[Paneled meme with a brain that gets increasingly glowing]


[The brain is smaller than the skull]


<span style="color:#323232;">if dayOfWeek.name == "Sunday" || dayOfWeek.name == "Saturday"
</span><span style="color:#323232;">    weekend = true
</span>

[The brain is glowing in some areas]


<span style="color:#323232;">if dayOfWeek &lt; 2 || dayOfWeek > 6
</span><span style="color:#323232;">    weekend = true
</span>

[The brain is shooting out rays of light]


<span style="color:#323232;">weekend = !((dayOfWeek - 1) % 6)
</span>

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

MagicShel ,

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 ,

This, and maybe a couple of unit tests

TheSlad ,

7 unit tests should be enough I think

Cosmicomical ,

Lol i can't lie, it took me a while to get the joke. I feel so dumb

irdc ,

<span style="color:#323232;">weekend = day_of_week in (“sat”, “sun”)
</span>

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

baseless_discourse ,

Until some idiot sends in “Sunday” as days of the week…

activ8r ,

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

👍

snowe ,
@snowe@programming.dev avatar

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

dbilitated ,
@dbilitated@aussie.zone avatar

yeah I like having an array of days that are weekend days then testing if the day is in the array. can change what days are considered weekend if we go to a three day weekend and it reads really well. I hate massive if statements

ISometimesAdmin ,
@ISometimesAdmin@the.coolest.zone avatar

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)
DroneRights OP ,

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

eluvatar ,

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?

subignition ,
@subignition@kbin.social avatar

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

Esca ,

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 ,

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

Halosheep ,

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

Schrolli97 ,

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

dauerstaender ,

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

DroneRights OP ,

A rope has two ends, and so does a week

DrunkenPirate ,

Sentences have both meanings and sound, yours have sound

subignition ,
@subignition@kbin.social avatar

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

Scrath ,

I like fancy insults

magic_lobster_party ,

Do you say weekend or weekends?

boredtortoise ,

Three-day workweek now

fl42v ,

So, where does it start then?

DroneRights OP ,

At the ends

Lysergid ,

weekend = dayOfWeek > 5

DroneRights OP , (edited )

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

JeffKerman1999 ,

On which planet? Monday is 1

DroneRights OP ,

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

Cralder ,

JavaScript is wrong

DroneRights OP ,

That’s nice, you can run weekend = dayOfWeek > 5 and then explain to the boss why clients are getting work texts on a sunday

JeffKerman1999 ,

Don’t use JavaScript on the backend ¯_(ツ)_/¯

DroneRights OP ,

I’ll be sure to tell my boss to throw away all the work he already paid for and start over in a different language. I’m sure he’ll be very understanding

emmanuel_car ,

Sunken cost fallacy

DroneRights OP ,

I don’t think you understand the concept of having a boss.

Earlier this week I proved to him that his new “more secure” password policy results in passwords that can be cracked in under a minute, and he didn’t care

xmunk ,

Sneak in a library that makes things more sane when nobody is looking…

Also, that isn’t “having a boss” it’s having a shit boss. As an engineering manager I am happy to go to bat and make excuses for time my reports spend paying down technical debt and making things more maintainable (within reason of course, and if shits really bad I can usually sneak a sustainability project into the timeline).

We’ll always need to make some compromises for our workplaces, the perfect job doesn’t exist, but what you described is a huge red flag. You deserve respect at work.

Cosmicomical ,

Yo nodejs is just plain amazing. We should just keep improving on js and replace all other languages. Js is already on all browsers, by adopting it on the server you get huge efficiency as you can move code AND coders between backend and frontend. Of course you must make the right choices of practices and frameworks for this to be possible

JeffKerman1999 ,

I agree! How many js frameworks spawned today? Which one is best?

oolio ,

Cron has clearly the superior numbering system, where sunday is both 0 and 7

kungen ,

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

Zagorath ,
@Zagorath@aussie.zone avatar

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.

DroneRights OP ,

Yeah, that’s why my calendar starts the week on Saturday

Cosmicomical ,

Funny thing, september comes from the number 7, october from 8 and november and december from 9 and 10, as the year in ancient rome was starting around march. This problem is timeless.

Zagorath ,
@Zagorath@aussie.zone avatar

Huh. I knew about the problem (that’s why I used October as my example, rather than, say, February), but I was mistaken as to the cause. The way I had always heard it told, September–December don’t match their current place in the year because of the addition of July and August. But I just looked it up and it seems you’re right. Those months are merely renamings of Quintilis and Sextilis, and the numbering issue comes from moving the start of the year from March to January.

Cosmicomical ,

Phew luckily my random memory was correct this time!

theKalash ,

On planet America.

JeffKerman1999 ,

Ah the same place that uses feet and inches, and puts the month before the day, and cannot read a 24 hour clock?

4am ,

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”

  • All
  • Subscribed
  • Moderated
  • Favorites
  • [email protected]
  • random
  • lifeLocal
  • goranko
  • All magazines