Re: Handling freeform date field order
- From: Dr John Stockton <jrs@xxxxxxxxxxxxxxxxxx>
- Date: Fri, 17 Mar 2006 23:23:09 +0000
JRS: In article <19385887.hiu3DYX0m0@xxxxxxxxxxxxxx>, dated Fri, 17 Mar
2006 21:56:08 remote, seen in news:comp.lang.javascript, Thomas
'PointedEars' Lahn <PointedEars@xxxxxx> posted :
Dr John Stockton wrote:
[...] "Mar 2006 15" can only have one meaning,
True.
likewise "27 Feb 29").
Well, is it February 27, (19|20)29, or February 29, (19|20)27?
A) You cut my note "apart from guess-the-century error".
B) February only has 29 days in years divisible by four [*].
ISTM that the function will in all cases above put the fields into an
array in Reverse-American order (Y D M), which is good enough for
subsequent processing (it also strips day suffix as in 9th) :-
function SFr, b) { return (parseInt(b,10)|0) - (parseInt(a,10)|0) }
function (X) { return X.split(/\W+/).sort(SF) }
Comment? I can't think of an elegant modification to get Y M D order.
You could parse for known month names (and abbreviations) with
RegExp.prototype.exec() and then change the order of matched
substrings.
Not elegant.
If we require the year number to be greater than 32, 32 could be
subtracted from the result of each parseInt(). Sorting would then put
the month in the middle. But that's not really elegant.
However, if the year is allowed to be expressed
with numeric values smaller than 32, the date-year ambiguity
remains.
That's why I put "if the value of the year field is greater than the
greatest possible day field value".
I doubt whether ECMA's reading this; but efficient array primitives to
rotate an array in either direction and to transpose a pair (adjacent or
any) of elements might be appreciated.
...
Those were not primitives.
[*] and, nowadays, not all of those.
--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 MIME. ©
Web <URL:http://www.merlyn.demon.co.uk/> - w. FAQish topics, links, acronyms
PAS EXE etc : <URL:http://www.merlyn.demon.co.uk/programs/> - see 00index.htm
Dates - miscdate.htm moredate.htm js-dates.htm pas-time.htm critdate.htm etc.
.
- References:
- Handling freeform date field order
- From: Dr John Stockton
- Re: Handling freeform date field order
- From: Thomas 'PointedEars' Lahn
- Handling freeform date field order
- Prev by Date: Re: Weird variable scope
- Next by Date: JavaScript abuse?
- Previous by thread: Re: Handling freeform date field order
- Next by thread: Can I add javascript to a stylesheet?
- Index(es):
Relevant Pages
|