Re: dd/mm/yyyy Date Compare Problem



JRS: In article <e2t7dd02ih3@xxxxxxxxxxxxxxxxx>, dated Fri, 28 Apr 2006
09:04:26 remote, seen in news:comp.lang.javascript, Matt Kruse
<newsgroups@xxxxxxxxxxxxx> 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.
.


Quantcast