Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. The Lounge
  3. Javascript and Dates

Javascript and Dates

Scheduled Pinned Locked Moved The Lounge
javascriptdatabasecomdesignfunctional
22 Posts 14 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Marc Clifton

    I want to commit a crime that may put me on death row. 1. Months start at 0. January is 0. WTF. I realize this is probably because whatever sh*t for brains wrote Date was thinking, oh, month should be an index so month[0] == 'January". Idiot. 2. Changes date even though I'm only providing a date, so the time defaults to 0 Zulu, which means that at the moment, today is yesterday somewhere in the world, so all my dates are back one day. Same UI later in the day shows the correct date. :mad: Marc

    Imperative to Functional Programming Succinctly Contributors Wanted for Higher Order Programming Project!

    M Offline
    M Offline
    Mario Vernari
    wrote on last edited by
    #6

    Endorse your pain/angry. The biggest fault is just the weird language and the pseudo-APIs behind it. That would be acceptable in a kids learning world, but we'll pay all this JavaScript spreading in the (near) future...and will be a boomerang! .Net and C# forever...

    1 Reply Last reply
    0
    • M Marc Clifton

      Happily I'm not using node. I'm just using the javascript Date object, and that only to fix the damn date handling. So now I have code like this:

      function fixupDates(data, view) {
      for (var i = 0; i < data.length; i++) {
      var row = data[i]
      for (var j = 0; j < view.fields.length; j++) {
      var field = view.fields[j]

              // Fixup for stupid Javascript, which adjusts the date because the time is 0 Zulu and it's 
              // compensating for DST or the timezone or both.  Whatever the reason, this is BULLSHIT.
              if (field.type == "date") {
                  var dateval = row\[field.name\]
                  if (dateval.length >= 10) {
                      var year = dateval.substring(0, 4)
                      var month = dateval.substring(5, 7)
                      var day = dateval.substring(8, 10)
                      // Who is total sh\*t for brains idiot in Javascript that decided months should begin at month 0???
                      row\[field.name\] = new Date(year, month - 1, day)
                  }
              }
          }
      }
      

      }

      Which as to walk through every f*cking row of the dataset that I just AJAX loaded! Thankfully, because I use the same library for loading grid data and because I have the view definition in the javascript, I've only needed to fix this once and it fixes all my grids where a data field is rendered (BTW, I'm using jqxGrid) Marc

      Imperative to Functional Programming Succinctly Contributors Wanted for Higher Order Programming Project!

      Kornfeld Eliyahu PeterK Offline
      Kornfeld Eliyahu PeterK Offline
      Kornfeld Eliyahu Peter
      wrote on last edited by
      #7

      You know, you can extend/replace JavaScript objects - even Date...

      Skipper: We'll fix it. Alex: Fix it? How you gonna fix this? Skipper: Grit, spit and a whole lotta duct tape.

      "It never ceases to amaze me that a spacecraft launched in 1977 can be fixed remotely from Earth." ― Brian Cox

      1 Reply Last reply
      0
      • M Marc Clifton

        I want to commit a crime that may put me on death row. 1. Months start at 0. January is 0. WTF. I realize this is probably because whatever sh*t for brains wrote Date was thinking, oh, month should be an index so month[0] == 'January". Idiot. 2. Changes date even though I'm only providing a date, so the time defaults to 0 Zulu, which means that at the moment, today is yesterday somewhere in the world, so all my dates are back one day. Same UI later in the day shows the correct date. :mad: Marc

        Imperative to Functional Programming Succinctly Contributors Wanted for Higher Order Programming Project!

        J Offline
        J Offline
        Jeremy Falcon
        wrote on last edited by
        #8

        So Marc, tell me, when's the last time you got laid?

        Jeremy Falcon

        M 1 Reply Last reply
        0
        • M Marc Clifton

          I want to commit a crime that may put me on death row. 1. Months start at 0. January is 0. WTF. I realize this is probably because whatever sh*t for brains wrote Date was thinking, oh, month should be an index so month[0] == 'January". Idiot. 2. Changes date even though I'm only providing a date, so the time defaults to 0 Zulu, which means that at the moment, today is yesterday somewhere in the world, so all my dates are back one day. Same UI later in the day shows the correct date. :mad: Marc

          Imperative to Functional Programming Succinctly Contributors Wanted for Higher Order Programming Project!

          B Offline
          B Offline
          Brady Kelly
          wrote on last edited by
          #9

          Hahaha. As serendipity has it, I just last night bought JavaScript: The Good Parts. I wonder what Crockford's going to make of The Date Thing.

          No object is so beautiful that, under certain conditions, it will not look ugly. - Oscar Wilde

          1 Reply Last reply
          0
          • M Marc Clifton

            I want to commit a crime that may put me on death row. 1. Months start at 0. January is 0. WTF. I realize this is probably because whatever sh*t for brains wrote Date was thinking, oh, month should be an index so month[0] == 'January". Idiot. 2. Changes date even though I'm only providing a date, so the time defaults to 0 Zulu, which means that at the moment, today is yesterday somewhere in the world, so all my dates are back one day. Same UI later in the day shows the correct date. :mad: Marc

            Imperative to Functional Programming Succinctly Contributors Wanted for Higher Order Programming Project!

            D Offline
            D Offline
            dandy72
            wrote on last edited by
            #10

            Not that I use it, but I thought arrays in VB were 1-based, and people hate it for that. Well, that and many other reasons. Are you advocating we should follow the VB model? :-) month[0] being January makes sense to me. That said, an enum defining month names starting at 1 also make sense to me. I see no way of ever reconciliating these sort of idiosyncrasies, unfortunately.

            B J 2 Replies Last reply
            0
            • J Jeremy Falcon

              So Marc, tell me, when's the last time you got laid?

              Jeremy Falcon

              M Offline
              M Offline
              Marc Clifton
              wrote on last edited by
              #11

              Jeremy Falcon wrote:

              So Marc, tell me, when's the last time you got laid?

              Recently. ;) No need to be more explicit, haha. Marc

              Imperative to Functional Programming Succinctly Contributors Wanted for Higher Order Programming Project!

              J 1 Reply Last reply
              0
              • M Marc Clifton

                Jeremy Falcon wrote:

                So Marc, tell me, when's the last time you got laid?

                Recently. ;) No need to be more explicit, haha. Marc

                Imperative to Functional Programming Succinctly Contributors Wanted for Higher Order Programming Project!

                J Offline
                J Offline
                Jeremy Falcon
                wrote on last edited by
                #12

                Touché!

                Jeremy Falcon

                1 Reply Last reply
                0
                • M Marc Clifton

                  I want to commit a crime that may put me on death row. 1. Months start at 0. January is 0. WTF. I realize this is probably because whatever sh*t for brains wrote Date was thinking, oh, month should be an index so month[0] == 'January". Idiot. 2. Changes date even though I'm only providing a date, so the time defaults to 0 Zulu, which means that at the moment, today is yesterday somewhere in the world, so all my dates are back one day. Same UI later in the day shows the correct date. :mad: Marc

                  Imperative to Functional Programming Succinctly Contributors Wanted for Higher Order Programming Project!

                  K Offline
                  K Offline
                  Kent Sharkey
                  wrote on last edited by
                  #13

                  The method is deprecated, but try mydate.getYear() sometime ;) :doh:

                  TTFN - Kent

                  1 Reply Last reply
                  0
                  • D dandy72

                    Not that I use it, but I thought arrays in VB were 1-based, and people hate it for that. Well, that and many other reasons. Are you advocating we should follow the VB model? :-) month[0] being January makes sense to me. That said, an enum defining month names starting at 1 also make sense to me. I see no way of ever reconciliating these sort of idiosyncrasies, unfortunately.

                    B Offline
                    B Offline
                    Bruce Patin
                    wrote on last edited by
                    #14

                    That would be somewhat OK, if it were consistent, in which case the first day of the month would be day 0, and the first year of a century would be 0 + the century. But it is not consistent and, by convention, months and days are already numbers starting with 1. Why confuse things just because you are a programmer who likes to put the months in an array starting with a zero offset? In that case, that offset should be calculated and used internally, not by forcing everyone else to add 1 to the month everywhere it is used. I agree with the poster that some common standards were made by people exhibiting ID-10-T errors.

                    D 1 Reply Last reply
                    0
                    • M Marc Clifton

                      I want to commit a crime that may put me on death row. 1. Months start at 0. January is 0. WTF. I realize this is probably because whatever sh*t for brains wrote Date was thinking, oh, month should be an index so month[0] == 'January". Idiot. 2. Changes date even though I'm only providing a date, so the time defaults to 0 Zulu, which means that at the moment, today is yesterday somewhere in the world, so all my dates are back one day. Same UI later in the day shows the correct date. :mad: Marc

                      Imperative to Functional Programming Succinctly Contributors Wanted for Higher Order Programming Project!

                      S Offline
                      S Offline
                      scmtim
                      wrote on last edited by
                      #15

                      My favorite Javascript date "feature" is where Jan 32, 2015 rather than throwing an error will just assume you meant Feb 1, 2015.

                      1 Reply Last reply
                      0
                      • M Marc Clifton

                        I want to commit a crime that may put me on death row. 1. Months start at 0. January is 0. WTF. I realize this is probably because whatever sh*t for brains wrote Date was thinking, oh, month should be an index so month[0] == 'January". Idiot. 2. Changes date even though I'm only providing a date, so the time defaults to 0 Zulu, which means that at the moment, today is yesterday somewhere in the world, so all my dates are back one day. Same UI later in the day shows the correct date. :mad: Marc

                        Imperative to Functional Programming Succinctly Contributors Wanted for Higher Order Programming Project!

                        L Offline
                        L Offline
                        Leng Vang
                        wrote on last edited by
                        #16

                        Perhaps you don't like zero-base array. Perhaps Pascal/Delphi suits you better? It is the only language with 1 base array I know off.:cool:

                        M 1 Reply Last reply
                        0
                        • L Leng Vang

                          Perhaps you don't like zero-base array. Perhaps Pascal/Delphi suits you better? It is the only language with 1 base array I know off.:cool:

                          M Offline
                          M Offline
                          Marc Clifton
                          wrote on last edited by
                          #17

                          Isn't BASIC 1-index too? And I'm quite happy with 0-based arrays. However, a month number is not an index. It is a human-readable abstraction starting with "1". Therefore, when I ask for the month in Javascript, I do NOT expect to get 0 for January. By Javascript's logic, the first day of the month should be 0!!!! Marc

                          Imperative to Functional Programming Succinctly Contributors Wanted for Higher Order Programming Project!

                          1 Reply Last reply
                          0
                          • B Bruce Patin

                            That would be somewhat OK, if it were consistent, in which case the first day of the month would be day 0, and the first year of a century would be 0 + the century. But it is not consistent and, by convention, months and days are already numbers starting with 1. Why confuse things just because you are a programmer who likes to put the months in an array starting with a zero offset? In that case, that offset should be calculated and used internally, not by forcing everyone else to add 1 to the month everywhere it is used. I agree with the poster that some common standards were made by people exhibiting ID-10-T errors.

                            D Offline
                            D Offline
                            dandy72
                            wrote on last edited by
                            #18

                            I hear you, but ultimately, a month number is not an array index. The dumb thing is using them as such...'cuz then, somebody at some point has no choice but to add or subtract 1 because we're dealing with different "currencies". X|

                            B 1 Reply Last reply
                            0
                            • D dandy72

                              Not that I use it, but I thought arrays in VB were 1-based, and people hate it for that. Well, that and many other reasons. Are you advocating we should follow the VB model? :-) month[0] being January makes sense to me. That said, an enum defining month names starting at 1 also make sense to me. I see no way of ever reconciliating these sort of idiosyncrasies, unfortunately.

                              J Offline
                              J Offline
                              James Lonero
                              wrote on last edited by
                              #19

                              Wasn't Javascript born out of C/C++? Then, that is why lists and arrays begin at 0 and not 1.

                              D 1 Reply Last reply
                              0
                              • J James Lonero

                                Wasn't Javascript born out of C/C++? Then, that is why lists and arrays begin at 0 and not 1.

                                D Offline
                                D Offline
                                dandy72
                                wrote on last edited by
                                #20

                                Y...yes...? I don't think I was questioning this.

                                1 Reply Last reply
                                0
                                • D dandy72

                                  I hear you, but ultimately, a month number is not an array index. The dumb thing is using them as such...'cuz then, somebody at some point has no choice but to add or subtract 1 because we're dealing with different "currencies". X|

                                  B Offline
                                  B Offline
                                  Bruce Patin
                                  wrote on last edited by
                                  #21

                                  I agree. That is why I also agree with the original poster that a JavaScript month should not be starting with zero. I was just trying to say that, if one is being aggravatingly dumb, at least be consistent about it. I wonder just who it was who made the decision to make months start with zero, and what he is doing now. Is he sitting in an easy chair with his tea and crumpets, musing about his wonderful history, or is he hiding in a safehouse in fear from those of us who didn't like his work. :-)

                                  D 1 Reply Last reply
                                  0
                                  • B Bruce Patin

                                    I agree. That is why I also agree with the original poster that a JavaScript month should not be starting with zero. I was just trying to say that, if one is being aggravatingly dumb, at least be consistent about it. I wonder just who it was who made the decision to make months start with zero, and what he is doing now. Is he sitting in an easy chair with his tea and crumpets, musing about his wonderful history, or is he hiding in a safehouse in fear from those of us who didn't like his work. :-)

                                    D Offline
                                    D Offline
                                    dandy72
                                    wrote on last edited by
                                    #22

                                    He's probably fixing broken VB code. At least that's the punishment I'd come up with.

                                    1 Reply Last reply
                                    0
                                    Reply
                                    • Reply as topic
                                    Log in to reply
                                    • Oldest to Newest
                                    • Newest to Oldest
                                    • Most Votes


                                    • Login

                                    • Don't have an account? Register

                                    • Login or register to search.
                                    • First post
                                      Last post
                                    0
                                    • Categories
                                    • Recent
                                    • Tags
                                    • Popular
                                    • World
                                    • Users
                                    • Groups