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 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> References: <46cb7029-4d6f-421a-a2f2-7d3d18de660b@e14g2000yqm.googlegroups.com> 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 () Cancel-Lock: sha1:53u1FunxggtvH5/I+EM48T9WQzc= Xref: csiph.com comp.lang.javascript:16207 In comp.lang.javascript message , Wed, 26 Sep 2012 07:57:08, Jukka K. Korpela 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 report when using Safari 6 or higher? -- (c) John Stockton, nr London, UK. ?@merlyn.demon.co.uk Turnpike v6.05. Website - w. FAQish topics, links, acronyms PAS EXE etc. : - see in 00index.htm Dates - miscdate.htm estrdate.htm js-dates.htm pas-time.htm critdate.htm etc.