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. Other Discussions
  3. The Weird and The Wonderful
  4. Microsoft, Javascript and not cutting corners

Microsoft, Javascript and not cutting corners

Scheduled Pinned Locked Moved The Weird and The Wonderful
csharpjavascriptsysadmintestingbeta-testing
30 Posts 19 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.
  • D Offline
    D Offline
    DerekT P
    wrote on last edited by
    #1

    At the risk of highlighting a horrible quick-n-dirty workaround I wrote a few months back, has anyone else come across this? I have some Javascript code that creates a date object, appends it to a URL, and does a GET to another page. At the server my (.Net) code then parses the date, but does some horrible clunky stuff to convert what Javascript has created into something .Net can parse. It does this by stripping off any reference to "GMT +0000 (GMT Standard Time)". The dates that Javascript formats when simply appending a date object a string are in the format

    ddd MMM dd yyyy hh:MM:ss GMT+nnnn (xxxxxxx)

    for instance

    Fri Mar 24 2017 00:00:00 GMT+0000 (GMT Standard Time)

    (BTW, this is an intranet app that ONLY runs on Chrome). All worked well in testing. All worked well in live... until the user started entering dates after March 26th, when .Net was parsing the date as "01-01-0001". Debugging on my system revealed the problem was the shift to daylight saving (British Summer Time); so I (stupidly, as I suspected at the time!) changed the server-side code to also strip off any text "GMT +0100 (GMT Summer Time)" which is what my browser was sending. I tested, all was well, put code live. Unfortunately this didn't resolve the problem for the user, and further investigation showed that, although they were on an identical version of Chrome, their system was sending "GMT +0100 (GMT Daylight Time)"; i.e. "Daylight Time" not "Summer Time". Further investigation showed that the only difference between development and live was that their systems were running Windows 7 Pro, whereas my development system was on Windows 8. So, Microsoft, what on earth possessed you to change the name of the time zone between one version of Windows and another?? So much for forward compatibility... :( :doh: :sigh: And yes, I am very much aware I should not be hard-coding timezone strings, even if this is an intranet app running in my own timezone... :cool:

    R K M S P 13 Replies Last reply
    0
    • D DerekT P

      At the risk of highlighting a horrible quick-n-dirty workaround I wrote a few months back, has anyone else come across this? I have some Javascript code that creates a date object, appends it to a URL, and does a GET to another page. At the server my (.Net) code then parses the date, but does some horrible clunky stuff to convert what Javascript has created into something .Net can parse. It does this by stripping off any reference to "GMT +0000 (GMT Standard Time)". The dates that Javascript formats when simply appending a date object a string are in the format

      ddd MMM dd yyyy hh:MM:ss GMT+nnnn (xxxxxxx)

      for instance

      Fri Mar 24 2017 00:00:00 GMT+0000 (GMT Standard Time)

      (BTW, this is an intranet app that ONLY runs on Chrome). All worked well in testing. All worked well in live... until the user started entering dates after March 26th, when .Net was parsing the date as "01-01-0001". Debugging on my system revealed the problem was the shift to daylight saving (British Summer Time); so I (stupidly, as I suspected at the time!) changed the server-side code to also strip off any text "GMT +0100 (GMT Summer Time)" which is what my browser was sending. I tested, all was well, put code live. Unfortunately this didn't resolve the problem for the user, and further investigation showed that, although they were on an identical version of Chrome, their system was sending "GMT +0100 (GMT Daylight Time)"; i.e. "Daylight Time" not "Summer Time". Further investigation showed that the only difference between development and live was that their systems were running Windows 7 Pro, whereas my development system was on Windows 8. So, Microsoft, what on earth possessed you to change the name of the time zone between one version of Windows and another?? So much for forward compatibility... :( :doh: :sigh: And yes, I am very much aware I should not be hard-coding timezone strings, even if this is an intranet app running in my own timezone... :cool:

      R Offline
      R Offline
      raddevus
      wrote on last edited by
      #2

      What about using something like:

      new Date( new Date().toUTCString() ).toLocaleString()

      I'm just curious.

      1 Reply Last reply
      0
      • D DerekT P

        At the risk of highlighting a horrible quick-n-dirty workaround I wrote a few months back, has anyone else come across this? I have some Javascript code that creates a date object, appends it to a URL, and does a GET to another page. At the server my (.Net) code then parses the date, but does some horrible clunky stuff to convert what Javascript has created into something .Net can parse. It does this by stripping off any reference to "GMT +0000 (GMT Standard Time)". The dates that Javascript formats when simply appending a date object a string are in the format

        ddd MMM dd yyyy hh:MM:ss GMT+nnnn (xxxxxxx)

        for instance

        Fri Mar 24 2017 00:00:00 GMT+0000 (GMT Standard Time)

        (BTW, this is an intranet app that ONLY runs on Chrome). All worked well in testing. All worked well in live... until the user started entering dates after March 26th, when .Net was parsing the date as "01-01-0001". Debugging on my system revealed the problem was the shift to daylight saving (British Summer Time); so I (stupidly, as I suspected at the time!) changed the server-side code to also strip off any text "GMT +0100 (GMT Summer Time)" which is what my browser was sending. I tested, all was well, put code live. Unfortunately this didn't resolve the problem for the user, and further investigation showed that, although they were on an identical version of Chrome, their system was sending "GMT +0100 (GMT Daylight Time)"; i.e. "Daylight Time" not "Summer Time". Further investigation showed that the only difference between development and live was that their systems were running Windows 7 Pro, whereas my development system was on Windows 8. So, Microsoft, what on earth possessed you to change the name of the time zone between one version of Windows and another?? So much for forward compatibility... :( :doh: :sigh: And yes, I am very much aware I should not be hard-coding timezone strings, even if this is an intranet app running in my own timezone... :cool:

        K Offline
        K Offline
        kmoorevs
        wrote on last edited by
        #3

        I know you aren't asking for help, but what happens when a client either intentionally or by mistake changes their timezone settings? Wouldn't it be better to strip everything after the year? (only append the first 15 characters to the url) :)

        "Go forth into the source" - Neal Morse

        D 1 Reply Last reply
        0
        • D DerekT P

          At the risk of highlighting a horrible quick-n-dirty workaround I wrote a few months back, has anyone else come across this? I have some Javascript code that creates a date object, appends it to a URL, and does a GET to another page. At the server my (.Net) code then parses the date, but does some horrible clunky stuff to convert what Javascript has created into something .Net can parse. It does this by stripping off any reference to "GMT +0000 (GMT Standard Time)". The dates that Javascript formats when simply appending a date object a string are in the format

          ddd MMM dd yyyy hh:MM:ss GMT+nnnn (xxxxxxx)

          for instance

          Fri Mar 24 2017 00:00:00 GMT+0000 (GMT Standard Time)

          (BTW, this is an intranet app that ONLY runs on Chrome). All worked well in testing. All worked well in live... until the user started entering dates after March 26th, when .Net was parsing the date as "01-01-0001". Debugging on my system revealed the problem was the shift to daylight saving (British Summer Time); so I (stupidly, as I suspected at the time!) changed the server-side code to also strip off any text "GMT +0100 (GMT Summer Time)" which is what my browser was sending. I tested, all was well, put code live. Unfortunately this didn't resolve the problem for the user, and further investigation showed that, although they were on an identical version of Chrome, their system was sending "GMT +0100 (GMT Daylight Time)"; i.e. "Daylight Time" not "Summer Time". Further investigation showed that the only difference between development and live was that their systems were running Windows 7 Pro, whereas my development system was on Windows 8. So, Microsoft, what on earth possessed you to change the name of the time zone between one version of Windows and another?? So much for forward compatibility... :( :doh: :sigh: And yes, I am very much aware I should not be hard-coding timezone strings, even if this is an intranet app running in my own timezone... :cool:

          M Offline
          M Offline
          Marco Bertschi
          wrote on last edited by
          #4

          DerekTP123 wrote:

          ddd MMM dd yyyy hh:MM:ss GMT+nnnn (xxxxxxx)

          I'm sure you can strip the unnecessary stuff off using a regex, easily.

          1 Reply Last reply
          0
          • K kmoorevs

            I know you aren't asking for help, but what happens when a client either intentionally or by mistake changes their timezone settings? Wouldn't it be better to strip everything after the year? (only append the first 15 characters to the url) :)

            "Go forth into the source" - Neal Morse

            D Offline
            D Offline
            DerekT P
            wrote on last edited by
            #5

            absolutely, yes I agree 100%. Apart from exposing my moment of stupidity/laziness, the point of the post was to highlight the apparently random nature of the change in date formatting between consecutive Windows versions. 99% of the time we don't need that timezone "name" anyway, but for the 1% of applications that DO need it (or at least need it to be CONSISTENT), Microsoft just broke it. Unless it's really a Chrome thing, that checks the platform version... maybe I'm just cynical, but this sounds more like Microsoft's fault than Google's! (FWIW, Windows SBS2008 also uses "Daylight Time" rather than the newer "Summer Time". I'd be interested to know what W10 says... try

            javascript:alert(new Date())

            in your Chrome URL bar)

            T 1 Reply Last reply
            0
            • D DerekT P

              At the risk of highlighting a horrible quick-n-dirty workaround I wrote a few months back, has anyone else come across this? I have some Javascript code that creates a date object, appends it to a URL, and does a GET to another page. At the server my (.Net) code then parses the date, but does some horrible clunky stuff to convert what Javascript has created into something .Net can parse. It does this by stripping off any reference to "GMT +0000 (GMT Standard Time)". The dates that Javascript formats when simply appending a date object a string are in the format

              ddd MMM dd yyyy hh:MM:ss GMT+nnnn (xxxxxxx)

              for instance

              Fri Mar 24 2017 00:00:00 GMT+0000 (GMT Standard Time)

              (BTW, this is an intranet app that ONLY runs on Chrome). All worked well in testing. All worked well in live... until the user started entering dates after March 26th, when .Net was parsing the date as "01-01-0001". Debugging on my system revealed the problem was the shift to daylight saving (British Summer Time); so I (stupidly, as I suspected at the time!) changed the server-side code to also strip off any text "GMT +0100 (GMT Summer Time)" which is what my browser was sending. I tested, all was well, put code live. Unfortunately this didn't resolve the problem for the user, and further investigation showed that, although they were on an identical version of Chrome, their system was sending "GMT +0100 (GMT Daylight Time)"; i.e. "Daylight Time" not "Summer Time". Further investigation showed that the only difference between development and live was that their systems were running Windows 7 Pro, whereas my development system was on Windows 8. So, Microsoft, what on earth possessed you to change the name of the time zone between one version of Windows and another?? So much for forward compatibility... :( :doh: :sigh: And yes, I am very much aware I should not be hard-coding timezone strings, even if this is an intranet app running in my own timezone... :cool:

              S Offline
              S Offline
              Super Lloyd
              wrote on last edited by
              #6

              Typescript to the rescue, format your date on the client side!!

              interface Date {
              format(pattern: string, utc?: boolean): string;
              }
              // http://stackoverflow.com/questions/14638018/current-time-formatting-with-javascript
              Date.prototype.format = function (pattern: string, utc?: boolean) {
              var MMMM = ["\x00", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
              var MMM = ["\x01", "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
              var dddd = ["\x02", "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
              var ddd = ["\x03", "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];

              function ii(i: number, len?: number) {
                  var s = i + "";
                  len = len || 2;
                  while (s.length < len) s = "0" + s;
                  return s;
              }
              
              var y = utc ? this.getUTCFullYear() : this.getFullYear();
              pattern = pattern.replace(/(^|\[^\\\\\])yyyy+/g, "$1" + y);
              pattern = pattern.replace(/(^|\[^\\\\\])yy/g, "$1" + y.toString().substr(2, 2));
              pattern = pattern.replace(/(^|\[^\\\\\])y/g, "$1" + y);
              
              var M = (utc ? this.getUTCMonth() : this.getMonth()) + 1;
              pattern = pattern.replace(/(^|\[^\\\\\])MMMM+/g, "$1" + MMMM\[0\]);
              pattern = pattern.replace(/(^|\[^\\\\\])MMM/g, "$1" + MMM\[0\]);
              pattern = pattern.replace(/(^|\[^\\\\\])MM/g, "$1" + ii(M));
              pattern = pattern.replace(/(^|\[^\\\\\])M/g, "$1" + M);
              
              var d = utc ? this.getUTCDate() : this.getDate();
              pattern = pattern.replace(/(^|\[^\\\\\])dddd+/g, "$1" + dddd\[0\]);
              pattern = pattern.replace(/(^|\[^\\\\\])ddd/g, "$1" + ddd\[0\]);
              pattern = pattern.replace(/(^|\[^\\\\\])dd/g, "$1" + ii(d));
              pattern = pattern.replace(/(^|\[^\\\\\])d/g, "$1" + d);
              
              var H = utc ? this.getUTCHours() : this.getHours();
              pattern = pattern.replace(/(^|\[^\\\\\])HH+/g, "$1" + ii(H));
              pattern = pattern.replace(/(^|\[^\\\\\])H/g, "$1" + H);
              
              var h = H > 12 ? H - 12 : H == 0 ? 12 : H;
              pattern = pattern.replace(/(^|\[^\\\\\])hh+/g, "$1" + ii(h));
              pattern = pattern.replace(/(^|\[^\\\\\])h/g, "$1" + h);
              
              var m = utc ? this.getUTCMinutes() : this.getMinutes();
              pattern = pattern.replace(/(^|\[^\\\\\])mm+/g, "$1" + ii(m));
              pattern = pattern.replace(/(^|\[^\\\\\])m/g, "$1" + m);
              
              var s = utc ? this.getUTCSeconds() : this.getSeconds();
              pattern = pattern.replace(/(^|\[^\\\\\])ss+/g, "$1" + ii(s));
              pattern = pattern.replace(/(^|\[^\\\\\])s/g, "$1" + s);
              
              var f = utc ? this.getU
              
              K 1 Reply Last reply
              0
              • D DerekT P

                At the risk of highlighting a horrible quick-n-dirty workaround I wrote a few months back, has anyone else come across this? I have some Javascript code that creates a date object, appends it to a URL, and does a GET to another page. At the server my (.Net) code then parses the date, but does some horrible clunky stuff to convert what Javascript has created into something .Net can parse. It does this by stripping off any reference to "GMT +0000 (GMT Standard Time)". The dates that Javascript formats when simply appending a date object a string are in the format

                ddd MMM dd yyyy hh:MM:ss GMT+nnnn (xxxxxxx)

                for instance

                Fri Mar 24 2017 00:00:00 GMT+0000 (GMT Standard Time)

                (BTW, this is an intranet app that ONLY runs on Chrome). All worked well in testing. All worked well in live... until the user started entering dates after March 26th, when .Net was parsing the date as "01-01-0001". Debugging on my system revealed the problem was the shift to daylight saving (British Summer Time); so I (stupidly, as I suspected at the time!) changed the server-side code to also strip off any text "GMT +0100 (GMT Summer Time)" which is what my browser was sending. I tested, all was well, put code live. Unfortunately this didn't resolve the problem for the user, and further investigation showed that, although they were on an identical version of Chrome, their system was sending "GMT +0100 (GMT Daylight Time)"; i.e. "Daylight Time" not "Summer Time". Further investigation showed that the only difference between development and live was that their systems were running Windows 7 Pro, whereas my development system was on Windows 8. So, Microsoft, what on earth possessed you to change the name of the time zone between one version of Windows and another?? So much for forward compatibility... :( :doh: :sigh: And yes, I am very much aware I should not be hard-coding timezone strings, even if this is an intranet app running in my own timezone... :cool:

                P Offline
                P Offline
                Plamen Dragiyski
                wrote on last edited by
                #7

                Congratulations, your date is now "implementation-dependent" due to toString.

                ECMA-262 wrote:

                20.3.4.41.1 Runtime Semantics: ToDateString(tv) The following steps are performed: 1. Assert: Type(tv) is Number. 2. If tv is NaN, return "Invalid Date". 3. Return an implementation-dependent String value that represents tv as a date and time in the current time zone using a convenient, human-readable form.

                Luckily there is a method toUTCString or a library "moment" to allow to explicitly say the format, since ECMA are more concerned by invariants (that almost no good javascript programmer have problem with) than dates (that almost everyone works with). :doh:

                1 Reply Last reply
                0
                • D DerekT P

                  absolutely, yes I agree 100%. Apart from exposing my moment of stupidity/laziness, the point of the post was to highlight the apparently random nature of the change in date formatting between consecutive Windows versions. 99% of the time we don't need that timezone "name" anyway, but for the 1% of applications that DO need it (or at least need it to be CONSISTENT), Microsoft just broke it. Unless it's really a Chrome thing, that checks the platform version... maybe I'm just cynical, but this sounds more like Microsoft's fault than Google's! (FWIW, Windows SBS2008 also uses "Daylight Time" rather than the newer "Summer Time". I'd be interested to know what W10 says... try

                  javascript:alert(new Date())

                  in your Chrome URL bar)

                  T Offline
                  T Offline
                  twaindev
                  wrote on last edited by
                  #8

                  On W10: Daylight Time

                  D 1 Reply Last reply
                  0
                  • T twaindev

                    On W10: Daylight Time

                    D Offline
                    D Offline
                    DerekT P
                    wrote on last edited by
                    #9

                    :sigh: So it was just a brief aberration by MS then, to change the display name of the timezone from "GMT Daylight Time" to "GMT Summer Time". Thus screwing up not only forward compatibility, but backwards compatibility too. I love this job. :(( (And yes, to all other posters who've showed a way around, I understand... I really am just highlighting an issue with MS's naming of time zones!)

                    N 1 Reply Last reply
                    0
                    • D DerekT P

                      At the risk of highlighting a horrible quick-n-dirty workaround I wrote a few months back, has anyone else come across this? I have some Javascript code that creates a date object, appends it to a URL, and does a GET to another page. At the server my (.Net) code then parses the date, but does some horrible clunky stuff to convert what Javascript has created into something .Net can parse. It does this by stripping off any reference to "GMT +0000 (GMT Standard Time)". The dates that Javascript formats when simply appending a date object a string are in the format

                      ddd MMM dd yyyy hh:MM:ss GMT+nnnn (xxxxxxx)

                      for instance

                      Fri Mar 24 2017 00:00:00 GMT+0000 (GMT Standard Time)

                      (BTW, this is an intranet app that ONLY runs on Chrome). All worked well in testing. All worked well in live... until the user started entering dates after March 26th, when .Net was parsing the date as "01-01-0001". Debugging on my system revealed the problem was the shift to daylight saving (British Summer Time); so I (stupidly, as I suspected at the time!) changed the server-side code to also strip off any text "GMT +0100 (GMT Summer Time)" which is what my browser was sending. I tested, all was well, put code live. Unfortunately this didn't resolve the problem for the user, and further investigation showed that, although they were on an identical version of Chrome, their system was sending "GMT +0100 (GMT Daylight Time)"; i.e. "Daylight Time" not "Summer Time". Further investigation showed that the only difference between development and live was that their systems were running Windows 7 Pro, whereas my development system was on Windows 8. So, Microsoft, what on earth possessed you to change the name of the time zone between one version of Windows and another?? So much for forward compatibility... :( :doh: :sigh: And yes, I am very much aware I should not be hard-coding timezone strings, even if this is an intranet app running in my own timezone... :cool:

                      J Offline
                      J Offline
                      Jochen Arndt
                      wrote on last edited by
                      #10

                      There are two basic rules for passing datetime between systems:

                      1. Use UTC.
                      2. When passing as string use a fixed format and not one that depends on local system settings.

                      The recommended string format is according to ISO 8601 - Wikipedia[^].

                      B 1 Reply Last reply
                      0
                      • D DerekT P

                        :sigh: So it was just a brief aberration by MS then, to change the display name of the timezone from "GMT Daylight Time" to "GMT Summer Time". Thus screwing up not only forward compatibility, but backwards compatibility too. I love this job. :(( (And yes, to all other posters who've showed a way around, I understand... I really am just highlighting an issue with MS's naming of time zones!)

                        N Offline
                        N Offline
                        nplumridge
                        wrote on last edited by
                        #11

                        Aah, one of our customers had exactly this problem on their Windows 2012 servers - some were showing "GMT Daylight" Time, others "GMT Summer Time", even though they had all been built "exactly the same" (by a third party). It's a region/locale difference, one is English (US), the other is English (United Kingdom). I think it comes from the tzres.dll.

                        1 Reply Last reply
                        0
                        • J Jochen Arndt

                          There are two basic rules for passing datetime between systems:

                          1. Use UTC.
                          2. When passing as string use a fixed format and not one that depends on local system settings.

                          The recommended string format is according to ISO 8601 - Wikipedia[^].

                          B Offline
                          B Offline
                          bvgheluwe
                          wrote on last edited by
                          #12

                          I completely agree with using ISO 8601! (but I kindly refer to a Stackoverflow answer that fixes the (in my opinion, wrong) JSON behaviour of serializing a js Date to a UTC string and losing all timezone information).

                          J 1 Reply Last reply
                          0
                          • B bvgheluwe

                            I completely agree with using ISO 8601! (but I kindly refer to a Stackoverflow answer that fixes the (in my opinion, wrong) JSON behaviour of serializing a js Date to a UTC string and losing all timezone information).

                            J Offline
                            J Offline
                            Jochen Arndt
                            wrote on last edited by
                            #13

                            It all depends on the requirements. If you need time zone information, you must pass it too of course. If you don't need the TZ name, using the offset is fine because that can be simply parsed. If you need the name do not use the full name but the abbreviation (see List of time zone abbreviations - Wikipedia[^]). Handling local times is always a nightmare. For this reason there is the general rule to always use UTC. Only when dates should be displayed they might be converted to local time. When having tabular data containing multiple records, use UTC for the records and store the time zone information in a single record (e.g. within the user record). This applies especially when the timestamps has to be stored in binary format (like with databases).

                            1 Reply Last reply
                            0
                            • D DerekT P

                              At the risk of highlighting a horrible quick-n-dirty workaround I wrote a few months back, has anyone else come across this? I have some Javascript code that creates a date object, appends it to a URL, and does a GET to another page. At the server my (.Net) code then parses the date, but does some horrible clunky stuff to convert what Javascript has created into something .Net can parse. It does this by stripping off any reference to "GMT +0000 (GMT Standard Time)". The dates that Javascript formats when simply appending a date object a string are in the format

                              ddd MMM dd yyyy hh:MM:ss GMT+nnnn (xxxxxxx)

                              for instance

                              Fri Mar 24 2017 00:00:00 GMT+0000 (GMT Standard Time)

                              (BTW, this is an intranet app that ONLY runs on Chrome). All worked well in testing. All worked well in live... until the user started entering dates after March 26th, when .Net was parsing the date as "01-01-0001". Debugging on my system revealed the problem was the shift to daylight saving (British Summer Time); so I (stupidly, as I suspected at the time!) changed the server-side code to also strip off any text "GMT +0100 (GMT Summer Time)" which is what my browser was sending. I tested, all was well, put code live. Unfortunately this didn't resolve the problem for the user, and further investigation showed that, although they were on an identical version of Chrome, their system was sending "GMT +0100 (GMT Daylight Time)"; i.e. "Daylight Time" not "Summer Time". Further investigation showed that the only difference between development and live was that their systems were running Windows 7 Pro, whereas my development system was on Windows 8. So, Microsoft, what on earth possessed you to change the name of the time zone between one version of Windows and another?? So much for forward compatibility... :( :doh: :sigh: And yes, I am very much aware I should not be hard-coding timezone strings, even if this is an intranet app running in my own timezone... :cool:

                              E Offline
                              E Offline
                              englebart
                              wrote on last edited by
                              #14

                              If you don't care about local time zone information, just send the absolute numeric time: Date.getTime(); https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global\_Objects/Date/getTime Worse case, you might have to apply some fixed adjustment if your server Date/Time code works off of a different time 0 value.

                              1 Reply Last reply
                              0
                              • D DerekT P

                                At the risk of highlighting a horrible quick-n-dirty workaround I wrote a few months back, has anyone else come across this? I have some Javascript code that creates a date object, appends it to a URL, and does a GET to another page. At the server my (.Net) code then parses the date, but does some horrible clunky stuff to convert what Javascript has created into something .Net can parse. It does this by stripping off any reference to "GMT +0000 (GMT Standard Time)". The dates that Javascript formats when simply appending a date object a string are in the format

                                ddd MMM dd yyyy hh:MM:ss GMT+nnnn (xxxxxxx)

                                for instance

                                Fri Mar 24 2017 00:00:00 GMT+0000 (GMT Standard Time)

                                (BTW, this is an intranet app that ONLY runs on Chrome). All worked well in testing. All worked well in live... until the user started entering dates after March 26th, when .Net was parsing the date as "01-01-0001". Debugging on my system revealed the problem was the shift to daylight saving (British Summer Time); so I (stupidly, as I suspected at the time!) changed the server-side code to also strip off any text "GMT +0100 (GMT Summer Time)" which is what my browser was sending. I tested, all was well, put code live. Unfortunately this didn't resolve the problem for the user, and further investigation showed that, although they were on an identical version of Chrome, their system was sending "GMT +0100 (GMT Daylight Time)"; i.e. "Daylight Time" not "Summer Time". Further investigation showed that the only difference between development and live was that their systems were running Windows 7 Pro, whereas my development system was on Windows 8. So, Microsoft, what on earth possessed you to change the name of the time zone between one version of Windows and another?? So much for forward compatibility... :( :doh: :sigh: And yes, I am very much aware I should not be hard-coding timezone strings, even if this is an intranet app running in my own timezone... :cool:

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

                                You should also be very much aware to never trust JavaScript mixed type string concatenation.

                                Immanentize the Eschaton!

                                1 Reply Last reply
                                0
                                • D DerekT P

                                  At the risk of highlighting a horrible quick-n-dirty workaround I wrote a few months back, has anyone else come across this? I have some Javascript code that creates a date object, appends it to a URL, and does a GET to another page. At the server my (.Net) code then parses the date, but does some horrible clunky stuff to convert what Javascript has created into something .Net can parse. It does this by stripping off any reference to "GMT +0000 (GMT Standard Time)". The dates that Javascript formats when simply appending a date object a string are in the format

                                  ddd MMM dd yyyy hh:MM:ss GMT+nnnn (xxxxxxx)

                                  for instance

                                  Fri Mar 24 2017 00:00:00 GMT+0000 (GMT Standard Time)

                                  (BTW, this is an intranet app that ONLY runs on Chrome). All worked well in testing. All worked well in live... until the user started entering dates after March 26th, when .Net was parsing the date as "01-01-0001". Debugging on my system revealed the problem was the shift to daylight saving (British Summer Time); so I (stupidly, as I suspected at the time!) changed the server-side code to also strip off any text "GMT +0100 (GMT Summer Time)" which is what my browser was sending. I tested, all was well, put code live. Unfortunately this didn't resolve the problem for the user, and further investigation showed that, although they were on an identical version of Chrome, their system was sending "GMT +0100 (GMT Daylight Time)"; i.e. "Daylight Time" not "Summer Time". Further investigation showed that the only difference between development and live was that their systems were running Windows 7 Pro, whereas my development system was on Windows 8. So, Microsoft, what on earth possessed you to change the name of the time zone between one version of Windows and another?? So much for forward compatibility... :( :doh: :sigh: And yes, I am very much aware I should not be hard-coding timezone strings, even if this is an intranet app running in my own timezone... :cool:

                                  K Offline
                                  K Offline
                                  Kirk 10389821
                                  wrote on last edited by
                                  #16

                                  So, you GENERATED the URL. You used the complicated format of the date/time string given to you by default, and hard to test manually. As opposed to formatting the date in Javascript to be: YYYYMMDD_HHNNSS and simply parsing that on the other end? Try to make your code immutable to the version of windows, etc.

                                  D 1 Reply Last reply
                                  0
                                  • S Super Lloyd

                                    Typescript to the rescue, format your date on the client side!!

                                    interface Date {
                                    format(pattern: string, utc?: boolean): string;
                                    }
                                    // http://stackoverflow.com/questions/14638018/current-time-formatting-with-javascript
                                    Date.prototype.format = function (pattern: string, utc?: boolean) {
                                    var MMMM = ["\x00", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
                                    var MMM = ["\x01", "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
                                    var dddd = ["\x02", "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
                                    var ddd = ["\x03", "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];

                                    function ii(i: number, len?: number) {
                                        var s = i + "";
                                        len = len || 2;
                                        while (s.length < len) s = "0" + s;
                                        return s;
                                    }
                                    
                                    var y = utc ? this.getUTCFullYear() : this.getFullYear();
                                    pattern = pattern.replace(/(^|\[^\\\\\])yyyy+/g, "$1" + y);
                                    pattern = pattern.replace(/(^|\[^\\\\\])yy/g, "$1" + y.toString().substr(2, 2));
                                    pattern = pattern.replace(/(^|\[^\\\\\])y/g, "$1" + y);
                                    
                                    var M = (utc ? this.getUTCMonth() : this.getMonth()) + 1;
                                    pattern = pattern.replace(/(^|\[^\\\\\])MMMM+/g, "$1" + MMMM\[0\]);
                                    pattern = pattern.replace(/(^|\[^\\\\\])MMM/g, "$1" + MMM\[0\]);
                                    pattern = pattern.replace(/(^|\[^\\\\\])MM/g, "$1" + ii(M));
                                    pattern = pattern.replace(/(^|\[^\\\\\])M/g, "$1" + M);
                                    
                                    var d = utc ? this.getUTCDate() : this.getDate();
                                    pattern = pattern.replace(/(^|\[^\\\\\])dddd+/g, "$1" + dddd\[0\]);
                                    pattern = pattern.replace(/(^|\[^\\\\\])ddd/g, "$1" + ddd\[0\]);
                                    pattern = pattern.replace(/(^|\[^\\\\\])dd/g, "$1" + ii(d));
                                    pattern = pattern.replace(/(^|\[^\\\\\])d/g, "$1" + d);
                                    
                                    var H = utc ? this.getUTCHours() : this.getHours();
                                    pattern = pattern.replace(/(^|\[^\\\\\])HH+/g, "$1" + ii(H));
                                    pattern = pattern.replace(/(^|\[^\\\\\])H/g, "$1" + H);
                                    
                                    var h = H > 12 ? H - 12 : H == 0 ? 12 : H;
                                    pattern = pattern.replace(/(^|\[^\\\\\])hh+/g, "$1" + ii(h));
                                    pattern = pattern.replace(/(^|\[^\\\\\])h/g, "$1" + h);
                                    
                                    var m = utc ? this.getUTCMinutes() : this.getMinutes();
                                    pattern = pattern.replace(/(^|\[^\\\\\])mm+/g, "$1" + ii(m));
                                    pattern = pattern.replace(/(^|\[^\\\\\])m/g, "$1" + m);
                                    
                                    var s = utc ? this.getUTCSeconds() : this.getSeconds();
                                    pattern = pattern.replace(/(^|\[^\\\\\])ss+/g, "$1" + ii(s));
                                    pattern = pattern.replace(/(^|\[^\\\\\])s/g, "$1" + s);
                                    
                                    var f = utc ? this.getU
                                    
                                    K Offline
                                    K Offline
                                    kristopher baker
                                    wrote on last edited by
                                    #17

                                    HOLY GEEZUS! I like TypeScript and all but what What WHAT?! Shouldn't This Be Easier(TM)

                                    S 2 Replies Last reply
                                    0
                                    • K kristopher baker

                                      HOLY GEEZUS! I like TypeScript and all but what What WHAT?! Shouldn't This Be Easier(TM)

                                      S Offline
                                      S Offline
                                      Super Lloyd
                                      wrote on last edited by
                                      #18

                                      holymolly.. only 3 top line are typescript specific.. the rest is plain old javascript format function! ;)

                                      A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!

                                      1 Reply Last reply
                                      0
                                      • K kristopher baker

                                        HOLY GEEZUS! I like TypeScript and all but what What WHAT?! Shouldn't This Be Easier(TM)

                                        S Offline
                                        S Offline
                                        Super Lloyd
                                        wrote on last edited by
                                        #19

                                        Don't worry, I made a javascript only version for ya! Much simplerer! ;)

                                        // http://stackoverflow.com/questions/14638018/current-time-formatting-with-javascript
                                        Date.prototype.format = function (pattern, utc) {
                                        var MMMM = ["\x00", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
                                        var MMM = ["\x01", "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
                                        var dddd = ["\x02", "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
                                        var ddd = ["\x03", "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];

                                        function ii(i, len) {
                                            var s = i + "";
                                            len = len || 2;
                                            while (s.length < len) s = "0" + s;
                                            return s;
                                        }
                                        
                                        var y = utc ? this.getUTCFullYear() : this.getFullYear();
                                        pattern = pattern.replace(/(^|\[^\\\\\])yyyy+/g, "$1" + y);
                                        pattern = pattern.replace(/(^|\[^\\\\\])yy/g, "$1" + y.toString().substr(2, 2));
                                        pattern = pattern.replace(/(^|\[^\\\\\])y/g, "$1" + y);
                                        
                                        var M = (utc ? this.getUTCMonth() : this.getMonth()) + 1;
                                        pattern = pattern.replace(/(^|\[^\\\\\])MMMM+/g, "$1" + MMMM\[0\]);
                                        pattern = pattern.replace(/(^|\[^\\\\\])MMM/g, "$1" + MMM\[0\]);
                                        pattern = pattern.replace(/(^|\[^\\\\\])MM/g, "$1" + ii(M));
                                        pattern = pattern.replace(/(^|\[^\\\\\])M/g, "$1" + M);
                                        
                                        var d = utc ? this.getUTCDate() : this.getDate();
                                        pattern = pattern.replace(/(^|\[^\\\\\])dddd+/g, "$1" + dddd\[0\]);
                                        pattern = pattern.replace(/(^|\[^\\\\\])ddd/g, "$1" + ddd\[0\]);
                                        pattern = pattern.replace(/(^|\[^\\\\\])dd/g, "$1" + ii(d));
                                        pattern = pattern.replace(/(^|\[^\\\\\])d/g, "$1" + d);
                                        
                                        var H = utc ? this.getUTCHours() : this.getHours();
                                        pattern = pattern.replace(/(^|\[^\\\\\])HH+/g, "$1" + ii(H));
                                        pattern = pattern.replace(/(^|\[^\\\\\])H/g, "$1" + H);
                                        
                                        var h = H > 12 ? H - 12 : H == 0 ? 12 : H;
                                        pattern = pattern.replace(/(^|\[^\\\\\])hh+/g, "$1" + ii(h));
                                        pattern = pattern.replace(/(^|\[^\\\\\])h/g, "$1" + h);
                                        
                                        var m = utc ? this.getUTCMinutes() : this.getMinutes();
                                        pattern = pattern.replace(/(^|\[^\\\\\])mm+/g, "$1" + ii(m));
                                        pattern = pattern.replace(/(^|\[^\\\\\])m/g, "$1" + m);
                                        
                                        var s = utc ? this.getUTCSeconds() : this.getSeconds();
                                        pattern = pattern.replace(/(^|\[^\\\\\])ss+/g, "$1" + ii(s));
                                        pattern = pattern.replace(/(^|\[^\\\\\])s/g, "$1" + s);
                                        
                                        var f = utc ? this.getUTCMilliseconds() : this.getMilliseconds();
                                        pattern = pattern.replace(/(^|\[^\\\\\])fff+/g
                                        
                                        Richard DeemingR 1 Reply Last reply
                                        0
                                        • S Super Lloyd

                                          Don't worry, I made a javascript only version for ya! Much simplerer! ;)

                                          // http://stackoverflow.com/questions/14638018/current-time-formatting-with-javascript
                                          Date.prototype.format = function (pattern, utc) {
                                          var MMMM = ["\x00", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
                                          var MMM = ["\x01", "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
                                          var dddd = ["\x02", "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
                                          var ddd = ["\x03", "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];

                                          function ii(i, len) {
                                              var s = i + "";
                                              len = len || 2;
                                              while (s.length < len) s = "0" + s;
                                              return s;
                                          }
                                          
                                          var y = utc ? this.getUTCFullYear() : this.getFullYear();
                                          pattern = pattern.replace(/(^|\[^\\\\\])yyyy+/g, "$1" + y);
                                          pattern = pattern.replace(/(^|\[^\\\\\])yy/g, "$1" + y.toString().substr(2, 2));
                                          pattern = pattern.replace(/(^|\[^\\\\\])y/g, "$1" + y);
                                          
                                          var M = (utc ? this.getUTCMonth() : this.getMonth()) + 1;
                                          pattern = pattern.replace(/(^|\[^\\\\\])MMMM+/g, "$1" + MMMM\[0\]);
                                          pattern = pattern.replace(/(^|\[^\\\\\])MMM/g, "$1" + MMM\[0\]);
                                          pattern = pattern.replace(/(^|\[^\\\\\])MM/g, "$1" + ii(M));
                                          pattern = pattern.replace(/(^|\[^\\\\\])M/g, "$1" + M);
                                          
                                          var d = utc ? this.getUTCDate() : this.getDate();
                                          pattern = pattern.replace(/(^|\[^\\\\\])dddd+/g, "$1" + dddd\[0\]);
                                          pattern = pattern.replace(/(^|\[^\\\\\])ddd/g, "$1" + ddd\[0\]);
                                          pattern = pattern.replace(/(^|\[^\\\\\])dd/g, "$1" + ii(d));
                                          pattern = pattern.replace(/(^|\[^\\\\\])d/g, "$1" + d);
                                          
                                          var H = utc ? this.getUTCHours() : this.getHours();
                                          pattern = pattern.replace(/(^|\[^\\\\\])HH+/g, "$1" + ii(H));
                                          pattern = pattern.replace(/(^|\[^\\\\\])H/g, "$1" + H);
                                          
                                          var h = H > 12 ? H - 12 : H == 0 ? 12 : H;
                                          pattern = pattern.replace(/(^|\[^\\\\\])hh+/g, "$1" + ii(h));
                                          pattern = pattern.replace(/(^|\[^\\\\\])h/g, "$1" + h);
                                          
                                          var m = utc ? this.getUTCMinutes() : this.getMinutes();
                                          pattern = pattern.replace(/(^|\[^\\\\\])mm+/g, "$1" + ii(m));
                                          pattern = pattern.replace(/(^|\[^\\\\\])m/g, "$1" + m);
                                          
                                          var s = utc ? this.getUTCSeconds() : this.getSeconds();
                                          pattern = pattern.replace(/(^|\[^\\\\\])ss+/g, "$1" + ii(s));
                                          pattern = pattern.replace(/(^|\[^\\\\\])s/g, "$1" + s);
                                          
                                          var f = utc ? this.getUTCMilliseconds() : this.getMilliseconds();
                                          pattern = pattern.replace(/(^|\[^\\\\\])fff+/g
                                          
                                          Richard DeemingR Offline
                                          Richard DeemingR Offline
                                          Richard Deeming
                                          wrote on last edited by
                                          #20

                                          SyntaxError: missing ) after formal parameters You've left the TypeScript parameter types in there.


                                          "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

                                          "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

                                          S 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