Yes, someone actually did this and I found it running on our server
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.
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.
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…
What gregorian year and date will the spacian date value of zero correlate to? Trick question.
The atomic clock on the moon 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.
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
moronsprogrammers 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.
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.
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.
It’s alright, but real programmers use Julian UTC.
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.
2 timezones but the complication is that it is dependent on which country you’re in?
There are two distinct time offsets used in Indiana but there are 11 different timezones https://en.m.wikipedia.org/wiki/Time_in_Indiana
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.
The obvious solution is to inject an IWeekendDaysOfWeekProvider service in the inversion of control container. In your, uh, javascript web app.
Just npm install isWeekend for the required locales.
Depends on: isMonday, isTuesday,…
…isWednesdayMyDudes…
This dude(ette) globalizes.
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.
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.
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.
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)?
No, the two ends of a week create a singular weekend.
Why would you call it weekend and the start the week with half of it?!
A rope has two ends, and so does a week
Sentences have both meanings and sound, yours have sound
I like fancy insults
Do you say weekend or weekends?
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?
Yeah it’s the front end of the week and Saturday is the rear end
They’re the week’s ends, front and back.
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
weekend = day_of_week in (“sat”, “sun”)
As a bonus this completely sidesteps the issue of what day is 0 or 1.
Until some idiot sends in “Sunday” as days of the week…
/^(sun|sat)/i.test(day_of_week)
👍
Ah yes the ole
sunweday
. My favorite day of the weekend.
Interesting that your days are 1-indexed. What happens on nullday?
You forgot weekend = dayOfWeek.name[0] == ‘S’;
Can confirm this works completely as expected when the user’s system is set to lang=ES.
weekend = dayOfWeek > 5
Sunday is
10 and Saturday is76.You just made Friday part of the weekendYou forgot SundayOn which planet? Monday is 1
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.
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.
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.
Phew luckily my random memory was correct this time!
On planet America.
Ah the same place that uses feet and inches, and puts the month before the day, and cannot read a 24 hour clock?