Looks like they needed to return some specific sequence of date string that wouldn’t be supported through the regular date functions in JS. Not bad code IMO.
As someone that has had to do a lot of Date related things recently, this code is very tame. Once you start combining the Date object with an input element of type "date" things get awful.
[Transcriber's note: The following code contains a snippet of Arabic script. Due to its incompatibility with many screen-readers, I have included a tag before the script itself. Thanks to u/junhengc4 for providing the correct script transcription.]
On top of everything else everyone else has said as to why this is not really horrible code, or even bad code, the other piece that people may be missing is that this will return Persian numbers ۰۱۲۳۴۵۶۷۸۹ instead of 0123456789.
As such, other code out there on stackoverflow for formatting dates probably just doesn't apply in this case.
You guys will post anything that isn't written in one line here, and you won't even post a better solution... this sub is full of pretentious man-children who don't understand how real world coding works...
I always see stuff like this labeled bad code and start questioning my e tire programming existence lol. I don’t think this is bad, it is what it is haha
Could be cleaned in a code review but honestly this code is fine he's returning dates in Farsi, declaring more than 3 variables doesn't make it shit code
I don’t like how this abstracts some logic to toISOString. I don’t want to have to look at the documentation each time I want to work on this function. Succinct does not always mean good imo
Then again, no worse than this toLocaleString nonsense I guess
If you don't have a requirement of using plain JS or you don't mind installing a new library (HEIL JS!), I think moment.js is quite amazing. You can use it for a lot of stuff. The above code can be simplified to moment().format('YYYY/MM/DD') with moment.js. I usually prefer using that if I have to deal with timezone conversions, date formatting etc.
251
u/overtrick1978 Sep 11 '21
You are very sheltered if this constitutes “worst code” to you.
255
u/thepurpleproject Sep 11 '21
can't blame him it's dates
67
u/Uchimamito Sep 11 '21
Looks like they needed to return some specific sequence of date string that wouldn’t be supported through the regular date functions in JS. Not bad code IMO.
60
u/MurdoMaclachlan public boolean isInt(int i) { return true; } Sep 11 '21 edited Sep 11 '21
Image Transcription: Code
[Transcriber's note: The following code contains a snippet of Arabic script. Due to its incompatibility with many screen-readers, I have included a tag before the script itself. Thanks to u/junhengc4 for providing the correct script transcription.]
I'm a human volunteer content transcriber for Reddit and you could be too! If you'd like more information on what we do and why we do it, click here!
43
u/NoHarmPun Sep 11 '21
On top of everything else everyone else has said as to why this is not really horrible code, or even bad code, the other piece that people may be missing is that this will return Persian numbers ۰۱۲۳۴۵۶۷۸۹ instead of 0123456789.
As such, other code out there on stackoverflow for formatting dates probably just doesn't apply in this case.
References for those who are interested:
https://gist.github.com/unicornist/0e37b3691551c42c716e96c125b99df7
https://www.languagesandnumbers.com/how-to-count-in-persian/en/fas/
34
u/[deleted] Sep 11 '21
That’s just the way to do it in JS ¯_(ツ)_/¯
24
u/AtomicInflation Sep 11 '21 edited Sep 11 '21
You guys will post anything that isn't written in one line here, and you won't even post a better solution... this sub is full of pretentious man-children who don't understand how real world coding works...
9
u/Hesh35 Sep 11 '21
I always see stuff like this labeled bad code and start questioning my e tire programming existence lol. I don’t think this is bad, it is what it is haha
5
u/deftware Sep 11 '21
This sums up the problem: https://www.youtube.com/watch?v=-5wpm-gesOY
4
u/squishles Sep 11 '21
I mean posting that on a saturday's not a high/low bar.
9
u/jmswlltt Sep 11 '21
Typescript with no types?! Terrible
2
u/pkrish10 Sep 11 '21
Yeah, since today is Saturday. Once I am back at office on Monday, I am sure one or the other will top this.
2
u/404_Error_404 Sep 11 '21
Could be cleaned in a code review but honestly this code is fine he's returning dates in Farsi, declaring more than 3 variables doesn't make it shit code
2
u/GunsDontRapePeople Sep 12 '21
Not bad
1
u/[deleted] Sep 11 '21
There is a good chance I'll see a ternary operator return a boolean today, so challenge accepted.
1
u/Z3R0_F0X_ Sep 11 '21
Soooo I don’t understand why this is bad….I’m an A-Hole
1
u/G66GNeco Sep 12 '21
You severely underestimate my (and a lot of ther peoples) general lack of quality when it comes to coding.
1
u/cofffffeeeeeeee Sep 12 '21
What's the problem with this other than maybe shouldn't name the getter today?
1
u/[deleted] Sep 11 '21 edited Sep 11 '21
"Memoization" folks, it's pretty obvious. It's also advisable to just do this shit on the backend first because the value is good for the entire day.
Begin with the end in mind.
-1
u/sohang-3112 Sep 11 '21
Surely JavaScript has a built-in method for Year/Month/Day format - this is a fairly common operation. Does anyone know a method for this?
0
u/[deleted] Sep 11 '21
[deleted] — view deleted comment