• Registered (unregistered)

    The month=1 was fristly implemented in MSDOS, where it returned a 1 .. 12 for month on GetDate

  • some guy (unregistered)

    More things: using var, document.write is called twice when once would suffice, explicit array declaration.

    Call me Bran, because I can see the genesis of this code: First, they wrote it straight-forwardly, and realized that they got almost the correct result. So they almost did the right thing and began to fiddle with it, leading to the additional lines handling the month. I can even see why it is lmonth and not month, because that definition (var month = date.getMonth()) was deleted when it became unused.

  • (nodebb)

    Using the name time for a variable that holds a date is a nice touch. Yes, it's actually a date+time object, but our use of it is date-only. I like how at the end they use two document.write() calls each containing at least one concatenation in their arguments. IMO that should have been 5 calls with no concatenations or 1 call with 4 concatenations.

    OTOH I am impressed that they avoided a typo in the 60-some characters it takes to type out all 12 month names in English. And their array indexes are in order and none are incorrect.

    So overall not wrong, just boneheadedly stupid. Brain off, fingers flying. The reeechest kind of code.

    Addendum 2024-12-17 07:00: I type too slowly. some guy wasn't there when I started.

  • (nodebb)

    Why do I have the feeling that this dev grew up with PASCAL? lol

  • OM222O (unregistered)

    TRWTF is JS for not having a proper datetime library in the language, BUT they could have just created a frozen object (either 0 or 1 indexed) and used it as a "look up table" instead of creating an array every time they need to ... "look something up" ...

  • Anonymous (unregistered) in reply to OM222O
  • (nodebb)

    It all started on the 13th hour of the 13th day of the 13th month. "Lousy Smarch weather!"

  • Officer Johnny Holzkopf (unregistered) in reply to some guy

    As we can see here, the word "almost" is one of the many real enemies of a programmer: "this code almost works, it will output the right amount of money almost every time", or "the pump will dispense almost the correct amount of insulin", "the car will almost stop at the right point", "the elevator will almost reach the requested level", or even "the plane's fuel display will almost show the correct value". So the solution is to fiddle with the code until the compiler stops complaining and only issues stupid warnings (which can be ignored), or in interpreted languages such as JS, it's good enough when it's almost correct in most cases, sometimes.

  • (nodebb)

    I wonder if the programmer started with code that formatted the date with a numeric month, so it needed to add 1 to date.getMonth(). When they changed it to print the month name, they offset the array rather than removing the +1.

  • Darren (unregistered)

    Looking at what this is outputting, it looks like date=time.getDate() returns the day of the month. That's not confusing at all...

  • (nodebb) in reply to OM222O

    TRWTF is JS for not having a proper datetime library in the language

    This is an outdated criticism. One of the more popular date libraries for javascript - moment.js - has been pushing people to use native language features rather than a library for a long time now. Here is their 2020 article literally telling developer to stop adding the library out of simple habit of "dates suck in js, where's my library". https://dockyard.com/blog/2020/02/14/you-probably-don-t-need-moment-js-anymore

  • Chris O (unregistered) in reply to Registered

    Date.GetMonth SHOULD return a 1 for January. Date.GetDay returns 1 for the first day of the month so why should only the month be zero indexed?

  • (nodebb) in reply to Officer Johnny Holzkopf

    or even "the plane's fuel display will almost show the correct value".

    That's almost how you get the Gimli Glider (and Tuninter Flight 1153).

  • Eric (unregistered)

    Arrays are normally 0-based, but we refer to months 1-based. Most languages do months in dates 1-based, but JS does them 0-based. So it looks like the developer expected it to work the way most languages do, but it didn't, so he simply added 1 rather than setting the array up starting from 0. If JS offered better date formatting, this would be just a few lines.

  • LZ79LRU (unregistered)

    Just because lazy lackadaisical laypeople lay their dates out lazily does not excuse us proper developers doing the same. Instead, it is our scared duty to always, at every step and in all things strive to correct their mischievous misguided misbehavior by adjusting all arrays. without regard to their contents such that they are properly enumerated with a zero at their start.

  • TS (unregistered)

    The lazy lackadaisical people are the computer language designers who are too inept to allow users to specify the lower bound of their arrays if that's the natural way to index what the arrays represent.

  • LZ79LRU (unregistered) in reply to TS

    Beasts we are not, bound by natures rules, but men. Men of logic and reason cold. To ways of nature we do not bend, but shape our own steel of will and icy intellect. We make the choices and know them true. For by us they are chosen, thus, true they must be for true are we. And if others should disagree than it is they who right are not. For they are lesser men than we. Why else indeed would they disagree.

  • Brian Boorman (unregistered) in reply to WTFGuy

    Date is time though. Just the larger calendar portion of it. Month/Day/Year without clock is still time. Much like specifying hours and minutes of the day but omitting the seconds portion. You've never heard physicists talk about the space-date continuum after all, have you?

  • erffrfez (unregistered)
    Comment held for moderation.
  • erffrfez (unregistered)
    Comment held for moderation.

Leave a comment on “One Month”

Log In or post as a guest

Replying to comment #:

« Return to Article