Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #16207

Re: silly question on Date value evaluation or comparison

Path csiph.com!usenet.pasdenom.info!gegeweb.org!eternal-september.org!feeder.eternal-september.org!mx04.eternal-september.org!.POSTED!not-for-mail
From Dr J R Stockton <reply1239@merlyn.demon.co.uk.invalid>
Newsgroups comp.lang.javascript
Subject Re: silly question on Date value evaluation or comparison
Date Thu, 27 Sep 2012 21:27:56 +0100
Organization Home
Lines 56
Message-ID <+LUQ77IMbLZQFwll@invalid.uk.co.demon.merlyn.invalid> (permalink)
References <f3ac39d0-7800-442d-ac95-f000b89e32b0@a11g2000yqb.googlegroups.com> <k3tim5$hl1$1@speranza.aioe.org> <46cb7029-4d6f-421a-a2f2-7d3d18de660b@e14g2000yqm.googlegroups.com> <k3u1v3$kq2$1@dont-email.me>
Mime-Version 1.0
Content-Type text/plain;charset=us-ascii
Injection-Info mx04.eternal-september.org; posting-host="530603207bb5dc63eadbc45c88da0024"; logging-data="16560"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/EaFbRgSPH41Hifb6Ls4DFLVS23dLO/fU="
User-Agent Turnpike/6.05-S (<hv3ExNkgcs8aPA9uquzbCngZym>)
Cancel-Lock sha1:53u1FunxggtvH5/I+EM48T9WQzc=
Xref csiph.com comp.lang.javascript:16207

Show key headers only | View raw


In comp.lang.javascript message <k3u1v3$kq2$1@dont-email.me>, Wed, 26
Sep 2012 07:57:08, Jukka K. Korpela <jkorpela@cs.tut.fi> posted:

>
>Before even considering that, consider how you are constructing the
>Date value. When you invoke new Date(...) with an argument like
>"9/25/2012", the effect is implementation-dependent. The string
>argument will be parsed with Date.parse(), about which clause 15.9.4.2
>of the ECMAScript standard says:
>
>"The function first attempts to parse the format of the String
>according to the rules called out in Date Time String Format
>(15.9.1.15). If the String does not conform to that format the function
>may fall back to any implementation-specific heuristics or
>implementation-specific date formats."

So writes a theoretician from the back of beyond - a nice place
(mosquitoes apart) certainly; but isolated.

The Standard permits, but does not require, entirely implementation-
dependent parsing, after trying 15.9.1.15.

The real world is aware that all or almost all browsers are either
written in America or are written with the US market, and MS IE
compatibility, firmly in mind.

Therefore, not only will the weird US date format be supported, but it
will be AT LEAST as reliable as any other date format.


The best format to use, however, is "2012/09/25".  It has all of the
advantages of ISO 8601 except for compliance, and I don't recall it
failing with new Date() in any browser.  But, if using other code,
beware as treating "09" as Octal Zero.

The OP needs to consider whether the whole of that day should be
matched, and whether the offset from GMT might vary.

If only the "calendar" date is wanted, then it is best to use UTC
methods throughout.

NEVER use new Date() except for the measurement of intervals of time.
Use instead new Date(0), which gives consistent results and ought to be
faster.



Query : What do the "Safari" parts of
<http://www.merlyn.demon.co.uk/js-datex.htm> report when using Safari 6
or higher?

-- 
 (c) John Stockton, nr London, UK.    ?@merlyn.demon.co.uk     Turnpike v6.05.
 Website  <http://www.merlyn.demon.co.uk/> - w. FAQish topics, links, acronyms
 PAS EXE etc. : <http://www.merlyn.demon.co.uk/programs/> - see in 00index.htm
 Dates - miscdate.htm estrdate.htm js-dates.htm pas-time.htm critdate.htm etc.

Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

silly question on Date value evaluation or comparison justaguy <lichunshen84@gmail.com> - 2012-09-25 17:21 -0700
  Re: silly question on Date value evaluation or comparison Christoph Becker <cmbecker69@gmx.de> - 2012-09-26 02:36 +0200
    Re: silly question on Date value evaluation or comparison justaguy <lichunshen84@gmail.com> - 2012-09-25 18:39 -0700
      Re: silly question on Date value evaluation or comparison "Jukka K. Korpela" <jkorpela@cs.tut.fi> - 2012-09-26 07:57 +0300
        Re: silly question on Date value evaluation or comparison Dr J R Stockton <reply1239@merlyn.demon.co.uk.invalid> - 2012-09-27 21:27 +0100
          Re: silly question on Date value evaluation or comparison RobG <rgqld@iinet.net.au> - 2012-10-03 00:12 -0700
            Re: silly question on Date value evaluation or comparison Dr J R Stockton <reply1240@merlyn.demon.co.uk.invalid> - 2012-10-04 19:36 +0100
              Re: silly question on Date value evaluation or comparison Scott Sauyet <scott.sauyet@gmail.com> - 2012-10-05 13:21 -0700
                Re: silly question on Date value evaluation or comparison Dr J R Stockton <reply1240@merlyn.demon.co.uk.invalid> - 2012-10-06 19:06 +0100
                Re: silly question on Date value evaluation or comparison "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2012-10-07 08:03 +0000
                Re: silly question on Date value evaluation or comparison Patricia Shanahan <pats@acm.org> - 2012-10-07 09:48 +0100
                Re: silly question on Date value evaluation or comparison "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2012-10-07 10:09 +0000
  Re: silly question on Date value evaluation or comparison Gregor Kofler <usenet@gregorkofler.com> - 2012-09-26 09:11 +0200

csiph-web