Re: dd/mm/yyyy Date Compare Problem
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.javascript archive

Re: dd/mm/yyyy Date Compare Problem

From: Dr John Stockton <jrs@merlyn.demon.co.uk>
Date: Sat Apr 29 2006 - 00:27:56 CEST

JRS: In article <e2t7dd02ih3@news3.newsguy.com>, dated Fri, 28 Apr 2006
09:04:26 remote, seen in news:comp.lang.javascript, Matt Kruse
<newsgroups@mattkruse.com> posted :
>Assimalyst wrote:
>> if (useDate <= today)
>
>You can't compare dates this way. Instead, you should probably compare their
>.getTime() values.

I can; why should he be unable to?

In principle, .valueOf() gets the internal value, and .getTime() gets
whatever it wants, which happens to be the same. IIRC, in a context
wanting a Number, .valueOf() is used by default. Comparison is such a
context. ECMA 11.8.5, steps 1 & 2.

But, to make the conversion both brief and explicit,
  if (+useDate <= +today)
since unary + converts to Number.

>For parsing dates, converting between formats, and comparing, see my Date
>library at http://www.JavascriptToolbox.com/lib/date/ which might make your
>life easier.

I'd not use a library from someone who does not know that a relational
operator likes to compare Numbers. It might be bloated.

I've not looked at your library code recently (as you may recall, I use
News off-line), so don't know the style.

But ISTM that if you were to write in a subset of javascript,
specifically such that // (and maybe /* */) only occurred as real
comment markers and not in strings, regexps, etc., then it might be
quite easy to produce, in javascript, a de-commenter and de-indenter.
Your library could be fetched in its full glory, but readily reduced to
the working parts without positive obfuscation.

It could operate like the paragraph-pack in js-quick.htm; copy into
textarea, press button, copy out.

But perhaps you already have something better.
 

-- 
 © John Stockton, Surrey, UK.  ?@merlyn.demon.co.uk   Turnpike v4.00   IE 4 ©
 <URL:http://www.jibbering.com/faq/>  JL/RC: FAQ of news:comp.lang.javascript 
 <URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
 <URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Received on Mon May 1 05:26:20 2006