<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">going to rant about why existing date builtins are more than adequate, and that over-engineering is the cause of most date-issues (and justify with working vanilla js code).</div><div class=""><br class=""></div><div class="">moment.js is over-engineering and unnecessary.  date manipulation is not that hard using vanilla javascript, if you follow the <i class="">best-practice of representing it internally throughout your application as a standard utc-iso-string</i> (e.g. "2017-09-21T16:57:06.781Z”).  keeping the date represented as a <i class="">string-by-default </i>saves you the hassle of doing needless custom-serializations when writing it to json or as a dom-element attribute (not to mention making debugging easier by having human-readable values). it is also sort / comparison-operator friendly as well.</div><div class=""><br class=""></div><div class="">in fact, if you enforce keeping the date represented internally as a string, there are only 3 common-cases that you need to worry about dealing with date serialization/deserialization:</div><div class="">1. date-arithmetic (trivial to do with 3-lines of vanilla javascript code)</div><div class=""><div class="">2. writing date to the ui and persistent-storage</div><div class="">3. reading date from ui and persistent-storage</div></div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">```javascript</div><div class=""><br class=""></div><div class=""><div class=""><div class="">/*jslint node: true, regexp: true */</div><div class="">'use strict';</div><div class=""><br class=""></div><div class="">function nop() {</div><div class="">/*</div><div class=""> * this function will do nothing</div><div class=""> */</div><div class="">    return;</div><div class="">}</div><div class=""><br class=""></div><div class="">// 1. date-arithmetic</div><div class="">function dateArithmeticAdd(dateIsoString, milliseconds) {</div><div class="">/*</div><div class=""> * this function will return a new dateIsoString with the given (positive or negative) milliseconds added to it</div><div class=""> */</div><div class="">    console.error('dateArithmeticAdd(' + JSON.stringify(dateIsoString) + ',' +</div><div class="">        JSON.stringify(milliseconds) + ')');</div><div class="">    // return serialized dateIsoString</div><div class="">    return new Date(</div><div class="">        // de-serialize dateIsoString and add milliseconds to it</div><div class="">        new Date(dateIsoString).getTime() + milliseconds</div><div class="">    ).toISOString();</div><div class="">}</div><div class=""><br class=""></div><div class="">// 2. writing date to the ui and persistent-storage</div><div class="">function dateWriteToUi(dateIsoString, options) {</div><div class="">/*</div><div class=""> * this function will return the date in a string-format suitable for ui-presentation</div><div class=""> * you can edit this function to suit your application needs</div><div class=""> */</div><div class="">    console.error('dateWriteToUi(' + JSON.stringify(dateIsoString) + ',' +</div><div class="">        JSON.stringify(options) + ')');</div><div class="">    var dateObject;</div><div class="">    // de-serialize dateIsoString</div><div class="">    dateObject = new Date(dateIsoString);</div><div class="">    // present date in local-time instead of utc-time</div><div class="">    if (!options.isUtc) {</div><div class="">        dateObject = new Date(dateObject.getTime() -</div><div class="">            dateObject.getTimezoneOffset() * 60 * 1000);</div><div class="">    }</div><div class="">    dateObject.toISOString().replace((/(\d\d\d\d)-(\d\d)-(\d\d)T(\d\d):(\d\d):(\d\d)/), function (</div><div class="">        match0,</div><div class="">        YYYY,</div><div class="">        MM,</div><div class="">        DD,</div><div class="">        hh,</div><div class="">        mm,</div><div class="">        ss</div><div class="">    ) {</div><div class="">        // jslint-hack</div><div class="">        nop(match0);</div><div class="">        dateObject.YYYY = YYYY;</div><div class="">        dateObject.MM = MM;</div><div class="">        dateObject.DD = DD;</div><div class="">        dateObject.hh = hh;</div><div class="">        dateObject.mm = mm;</div><div class="">        dateObject.ss = ss;</div><div class="">    });</div><div class="">    switch (options.type) {</div><div class="">    case 'china':</div><div class="">        return dateObject.YYYY + '-' +</div><div class="">            dateObject.MM + '-' +</div><div class="">            dateObject.DD + ' ' +</div><div class="">            dateObject.hh + ':' +</div><div class="">            dateObject.mm + ':' +</div><div class="">            dateObject.ss;</div><div class="">    case 'germany':</div><div class="">        return dateObject.DD + '.' +</div><div class="">            dateObject.MM + '.' +</div><div class="">            dateObject.YYYY + ' ' +</div><div class="">            dateObject.hh + ':' +</div><div class="">            dateObject.mm + ':' +</div><div class="">            dateObject.ss;</div><div class="">    case 'usa':</div><div class="">        return dateObject.MM + '/' +</div><div class="">            dateObject.DD + '/' +</div><div class="">            dateObject.YYYY + ' ' +</div><div class="">            dateObject.hh + ':' +</div><div class="">            dateObject.mm + ':' +</div><div class="">            dateObject.ss;</div><div class="">    // case 'foo':</div><div class="">    // ...</div><div class="">    // represent in default locale setting</div><div class="">    default:</div><div class="">        return dateObject.toString();</div><div class="">    }</div><div class="">}</div><div class=""><br class=""></div><div class="">// 3. reading date from ui and persistent-storage</div><div class="">function dateReadFromUi(inputText, options) {</div><div class="">/*</div><div class=""> * this function will parse inputText and return an appropriate dateIsoString</div><div class=""> * you can edit this function to suit your application needs</div><div class=""> */</div><div class="">    console.error('dateReadFromUi(' + JSON.stringify(inputText) + ',' +</div><div class="">        JSON.stringify(options) + ')');</div><div class="">    var dateObject;</div><div class="">    // use default Date parser</div><div class="">    dateObject = new Date(inputText);</div><div class="">    switch (options.type) {</div><div class="">    case 'china':</div><div class="">        inputText.replace((/(\d\d\d\d).(\d\d).(\d\d).(\d\d):(\d\d):(\d\d)/), function (</div><div class="">            match0,</div><div class="">            YYYY,</div><div class="">            MM,</div><div class="">            DD,</div><div class="">            hh,</div><div class="">            mm,</div><div class="">            ss</div><div class="">        ) {</div><div class="">            // jslint-hack</div><div class="">            nop(match0);</div><div class="">            dateObject = new Date(YYYY + '-' + MM + '-' + DD + 'T' + hh + ':' + mm + ':' + ss);</div><div class="">        });</div><div class="">        break;</div><div class="">    case 'germany':</div><div class="">        inputText.replace((/(\d\d).(\d\d).(\d\d\d\d).(\d\d):(\d\d):(\d\d)/), function (</div><div class="">            match0,</div><div class="">            DD,</div><div class="">            MM,</div><div class="">            YYYY,</div><div class="">            hh,</div><div class="">            mm,</div><div class="">            ss</div><div class="">        ) {</div><div class="">            // jslint-hack</div><div class="">            nop(match0);</div><div class="">            dateObject = new Date(YYYY + '-' + MM + '-' + DD + 'T' + hh + ':' + mm + ':' + ss);</div><div class="">        });</div><div class="">        break;</div><div class="">    case 'usa':</div><div class="">        inputText.replace((/(\d\d).(\d\d).(\d\d\d\d).(\d\d):(\d\d):(\d\d)/), function (</div><div class="">            match0,</div><div class="">            MM,</div><div class="">            DD,</div><div class="">            YYYY,</div><div class="">            hh,</div><div class="">            mm,</div><div class="">            ss</div><div class="">        ) {</div><div class="">            // jslint-hack</div><div class="">            nop(match0);</div><div class="">            dateObject = new Date(YYYY + '-' + MM + '-' + DD + 'T' + hh + ':' + mm + ':' + ss);</div><div class="">        });</div><div class="">        break;</div><div class="">    // case 'foo':</div><div class="">    // ...</div><div class="">    }</div><div class="">    // inputText was in utc-time</div><div class="">    if (options.isUtc) {</div><div class="">        dateObject = new Date(dateObject.getTime() -</div><div class="">            dateObject.getTimezoneOffset() * 60 * 1000);</div><div class="">    }</div><div class="">    return dateObject.toISOString();</div><div class="">}</div><div class=""><br class=""></div><div class="">// 1. date-arithmetic</div><div class="">console.log('\n1. date-arithmetic');</div><div class="">console.log(dateArithmeticAdd('2000-01-30T00:00:00Z', 24 * 60 * 60 * 1000));</div><div class="">console.log(dateArithmeticAdd('2000-01-30T00:00:00Z', -24 * 60 * 60 * 1000));</div><div class=""><br class=""></div><div class="">// 2. writing date to the ui and persistent-storage</div><div class="">console.log('\n2. writing date to the ui and persistent-storage');</div><div class="">console.log(dateWriteToUi('2000-01-30T00:00:00Z', { type: 'china' }));</div><div class="">console.log(dateWriteToUi('2000-01-30T00:00:00Z', { type: 'china', isUtc: true }));</div><div class="">console.log(dateWriteToUi('2000-01-30T00:00:00Z', { type: 'germany' }));</div><div class="">console.log(dateWriteToUi('2000-01-30T00:00:00Z', { type: 'germany', isUtc: true }));</div><div class="">console.log(dateWriteToUi('2000-01-30T00:00:00Z', { type: 'usa' }));</div><div class="">console.log(dateWriteToUi('2000-01-30T00:00:00Z', { type: 'usa', isUtc: true }));</div><div class=""><br class=""></div><div class="">// 3. reading date from ui and persistent-storage</div><div class="">console.log('\n3. reading date from ui and persistent-storage');</div><div class="">console.log(dateReadFromUi('2000-01-30 00:00:00', { type: 'china' }));</div><div class="">console.log(dateReadFromUi('2000-01-30 00:00:00', { type: 'china', isUtc: true }));</div><div class="">console.log(dateReadFromUi('30.01.2000 00:00:00', { type: 'germany' }));</div><div class="">console.log(dateReadFromUi('30.01.2000 00:00:00', { type: 'germany', isUtc: true }));</div><div class="">console.log(dateReadFromUi('01/30/2000 00:00:00', { type: 'usa' }));</div><div class="">console.log(dateReadFromUi('01/30/2000 00:00:00', { type: 'usa', isUtc: true }));</div></div></div><div class=""><br class=""></div><div class="">```</div><div class=""><br class=""></div><div class=""><img apple-inline="yes" id="66148521-5F0A-4013-A30F-C89621B846CE" src="cid:3D600B0A-8960-417E-8E51-C2B6228A621D" class=""></div><div class=""><br class=""></div><div><blockquote type="cite" class=""><div class="">On Sep 21, 2017, at 9:04 PM, Maggie Pint <<a href="mailto:maggiepint@gmail.com" class="">maggiepint@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">Substantial work is being put into a date standard library and formatting currently. There is a stage 1 proposal to rework the date library here: <a href="https://github.com/tc39/proposal-temporal" target="_blank" class="">https://github.com/tc39/<wbr class="">proposal-temporal</a>. I have a shim for that proposal started here: <a href="https://github.com/maggiepint/temporal-shim" target="_blank" class="">https://github.com/<wbr class="">maggiepint/temporal-shim</a>. I will probably seek stage two for this proposal in November of January. It is quite large, and the shim and spec text take a long time to write, so it can't be moved quickly.<div class=""><br class=""></div><div class="">My plan for formatting is to continue to rely on ECMA 402 as we do today. That team has done a wonderful job in the space, and I'm not entirely sure how i could one-up them at this point.</div><div class=""><br class=""></div><div class="">As far as why that proposal isn't just the Moment.js library - quite a few reasons. I maintain the Moment.js library with a couple other people, and the moment team actually created the new temporal proposal based on the knowledge of where the library falls down, and where other libraries have succeeded. Some points of difference from moment:</div><div class="">Proposal has all immutable data structures</div><div class="">Proposal provides a way to represent a date only, time only, and date time without associated time zone</div><div class="">APIs in several corners have 'safety' features that Moment doesn't have to prevent developer error - for instance the user must specify a time zone on a zoned object</div><div class=""><br class=""></div><div class="">Even after this proposal goes though, I assume there will still be libraries, simply because everyone has different preferences. That said, one should no longer HAVE to bring in a date library for anything as they do today.</div></div><div class="gmail_extra"><br class=""><div class="gmail_quote">On Thu, Sep 21, 2017 at 6:41 AM, Matthew Robb <span dir="ltr" class=""><<a href="mailto:matthewwrobb@gmail.com" target="_blank" class="">matthewwrobb@gmail.com</a>></span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr" class=""><div class="gmail_default" style="font-family:trebuchet ms,sans-serif;color:rgb(68,68,68)">I just mean to say that it makes more sense as a userland lib outside of the context of browsers.<span class="HOEnZb"><font color="#888888" class=""><br class=""></font></span></div></div><div class="gmail_extra"><span class="HOEnZb"><font color="#888888" class=""><br clear="all" class=""><div class=""><div class="m_-4184241723222850105gmail_signature" data-smartmail="gmail_signature"><div dir="ltr" class=""><div class=""><br class=""></div>- Matthew Robb</div></div></div></font></span><div class=""><div class="h5">
<br class=""><div class="gmail_quote">On Thu, Sep 21, 2017 at 9:35 AM, Michael Kriegel <span dir="ltr" class=""><<a href="mailto:michael.kriegel@actifsource.com" target="_blank" class="">michael.kriegel@actifsource.<wbr class="">com</a>></span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
  
    
  
  <div text="#000000" bgcolor="#FFFFFF" class=""><p class="">Actually I used it in node.js today - where using/deploying
      another lib is less "painful" - agreed. Still I don't think it is
      browser scope only...<br class="">
    </p><div class=""><div class="m_-4184241723222850105h5">
    <br class="">
    <div class="m_-4184241723222850105m_2545588254098210361moz-cite-prefix">On 21.09.2017 14:59, Matthew Robb
      wrote:<br class="">
    </div>
    <blockquote type="cite" class="">
      <div dir="ltr" class="">
        <div class="gmail_default" style="font-family:trebuchet ms,sans-serif;color:rgb(68,68,68)">+1 this sentiment</div>
        <div class="gmail_default" style="font-family:trebuchet ms,sans-serif;color:rgb(68,68,68)"><br class="">
        </div>
        <div class="gmail_default" style="font-family:trebuchet ms,sans-serif;color:rgb(68,68,68)">Raise your hand if you are
          using Moment.js in projects today?</div>
        <div class="gmail_default" style="font-family:trebuchet ms,sans-serif;color:rgb(68,68,68)">Raise your hand if you ship
          the library wholesale?</div>
        <div class="gmail_default" style="font-family:trebuchet ms,sans-serif;color:rgb(68,68,68)">Raise your hand if you use
          webpack tok strip out the locale files which add sig. heft to
          your bundle?</div>
        <div class="gmail_default" style="font-family:trebuchet ms,sans-serif;color:rgb(68,68,68)"><br class="">
        </div>
        <div class="gmail_default" style="font-family:trebuchet ms,sans-serif;color:rgb(68,68,68)">Moment.js should be
          standardized...</div>
        <div class="gmail_default" style="font-family:trebuchet ms,sans-serif;color:rgb(68,68,68)"><br class="">
        </div>
        <div class="gmail_default" style="font-family:trebuchet ms,sans-serif;color:rgb(68,68,68)">HOWEVER: The language spec
          is likely the wrong place. This should probably be a browser
          spec as the biggest motivation is going to be localization
          which I find obnoxious to include in an often shipped defacto
          lib.<br class="">
        </div>
      </div>
      <div class="gmail_extra"><br clear="all" class="">
        <div class="">
          <div class="m_-4184241723222850105m_2545588254098210361gmail_signature" data-smartmail="gmail_signature">
            <div dir="ltr" class="">
              <div class=""><br class="">
              </div>
              - Matthew Robb</div>
          </div>
        </div>
        <br class="">
        <div class="gmail_quote">On Thu, Sep 21, 2017 at 3:17 AM,
          Michael Kriegel <span dir="ltr" class=""><<a href="mailto:michael.kriegel@actifsource.com" target="_blank" class="">michael.kriegel@actifsource.c<wbr class="">om</a>></span>
          wrote:<br class="">
          <blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
            <div text="#000000" bgcolor="#FFFFFF" class=""><span class=""><p class="">Quoting my initial posting:</p><p class="">> I know there are libraries for that, but I think
                  it is fundamental enough to put it into the standard
                  instead.</p>
              </span><p class="">Isn't it legitimate to ask for a defacto-standard to
                become a real standard...<br class="">
              </p>
              <div class="">
                <div class="m_-4184241723222850105m_2545588254098210361h5"> <br class="">
                  <div class="m_-4184241723222850105m_2545588254098210361m_175685408612832698moz-cite-prefix">On
                    21.09.2017 09:13, Bob Myers wrote:<br class="">
                  </div>
                  <blockquote type="cite" class="">
                    <div dir="ltr" class="">There are third-party libraries which
                      are so widely-used as to be defacto standards.
                      <div class="">Bob</div>
                    </div>
                    <div class="gmail_extra"><br class="">
                      <div class="gmail_quote">On Thu, Sep 21, 2017 at
                        12:11 PM, Michael Kriegel <span dir="ltr" class=""><<a href="mailto:michael.kriegel@actifsource.com" target="_blank" class="">michael.kriegel@actifsource.c<wbr class="">om</a>></span>
                        wrote:<br class="">
                        <blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I would like to
                          suggest to take up date formatting into the
                          standard. Either as optional format parameter
                          on Date.prototype.toDateString() or as a
                          separate method Date.prototype.toFormattedDate<wbr class="">String(format).<br class="">
                          <br class="">
                          format should be a string in the form as
                          specified in <a href="https://tc39.github.io/ecma262/#sec-date-time-string-format" rel="noreferrer" target="_blank" class="">https://tc39.github.io/ecma262<wbr class="">/#sec-date-time-string-format</a><br class="">
                          <br class="">
                          I know there are libraries for that, but I
                          think it is fundamental enough to put it into
                          the standard instead.<br class="">
                          <br class="">
                          I hope this was not already discussed before
                          and I just did not find the thread.<span class="m_-4184241723222850105m_2545588254098210361m_175685408612832698HOEnZb"><font color="#888888" class=""><br class="">
                              <br class="">
                              -- <br class="">
                              Michael Kriegel • Head of R&D •
                              Actifsource AG • Haldenstrasse 1 • CH-6340
                              Baar • <a href="http://www.actifsource.com/" rel="noreferrer" target="_blank" class="">www.actifsource.com</a>
                              • <a href="tel:+41%2056%20250%2040%2002" value="+41562504002" target="_blank" class="">+41 56 250 40 02</a><br class="">
                              <br class="">
                              <br class="">
                              ______________________________<wbr class="">_________________<br class="">
                              es-discuss mailing list<br class="">
                              <a href="mailto:es-discuss@mozilla.org" target="_blank" class="">es-discuss@mozilla.org</a><br class="">
                              <a href="https://mail.mozilla.org/listinfo/es-discuss" rel="noreferrer" target="_blank" class="">https://mail.mozilla.org/listi<wbr class="">nfo/es-discuss</a><br class="">
                            </font></span></blockquote>
                      </div>
                      <br class="">
                    </div>
                  </blockquote>
                  <br class="">
                  <pre class="m_-4184241723222850105m_2545588254098210361m_175685408612832698moz-signature" cols="72">-- 
Michael Kriegel • Head of R&D • Actifsource AG • Haldenstrasse 1 • CH-6340 Baar • <a class="m_-4184241723222850105m_2545588254098210361m_175685408612832698moz-txt-link-abbreviated" href="http://www.actifsource.com/" target="_blank">www.actifsource.com</a> • <a href="tel:+41%2056%20250%2040%2002" value="+41562504002" target="_blank" class="">+41 56 250 40 02</a></pre>
                </div>
              </div>
            </div>
            <br class="">
            ______________________________<wbr class="">_________________<br class="">
            es-discuss mailing list<br class="">
            <a href="mailto:es-discuss@mozilla.org" target="_blank" class="">es-discuss@mozilla.org</a><br class="">
            <a href="https://mail.mozilla.org/listinfo/es-discuss" rel="noreferrer" target="_blank" class="">https://mail.mozilla.org/listi<wbr class="">nfo/es-discuss</a><br class="">
            <br class="">
          </blockquote>
        </div>
        <br class="">
      </div>
    </blockquote>
    <br class="">
    <pre class="m_-4184241723222850105m_2545588254098210361moz-signature" cols="72">-- 
Michael Kriegel • Head of R&D • Actifsource AG • Haldenstrasse 1 • CH-6340 Baar • <a class="m_-4184241723222850105m_2545588254098210361moz-txt-link-abbreviated" href="http://www.actifsource.com/" target="_blank">www.actifsource.com</a> • <a href="tel:+41%2056%20250%2040%2002" value="+41562504002" target="_blank" class="">+41 56 250 40 02</a></pre>
  </div></div></div>

</blockquote></div><br class=""></div></div></div>
<br class="">______________________________<wbr class="">_________________<br class="">
es-discuss mailing list<br class="">
<a href="mailto:es-discuss@mozilla.org" class="">es-discuss@mozilla.org</a><br class="">
<a href="https://mail.mozilla.org/listinfo/es-discuss" rel="noreferrer" target="_blank" class="">https://mail.mozilla.org/<wbr class="">listinfo/es-discuss</a><br class="">
<br class=""></blockquote></div><br class=""></div>
_______________________________________________<br class="">es-discuss mailing list<br class=""><a href="mailto:es-discuss@mozilla.org" class="">es-discuss@mozilla.org</a><br class="">https://mail.mozilla.org/listinfo/es-discuss<br class=""></div></blockquote></div><br class=""></body></html>