D
Dr John Stockton
For an all-numeric Gregorian date to be intrinsically unambiguous, it
must generally be of the form /\d{3,}\D+\d+\D+\d+/ ; and we've
discussed handling that.
But if the month is given in letters (in full, as a LTA, or as Roman
numerals) [and the language is known], then the date is unambiguous [*]
if the value of the year field is greater than the greatest possible day
field value - in which case the year value is greater than the actual
day value - whatever order the fields are in (even "Mar 2006 15" can
only have one meaning, likewise "27 Feb 29").
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.
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.
[*] apart from guess-the-century error.
must generally be of the form /\d{3,}\D+\d+\D+\d+/ ; and we've
discussed handling that.
But if the month is given in letters (in full, as a LTA, or as Roman
numerals) [and the language is known], then the date is unambiguous [*]
if the value of the year field is greater than the greatest possible day
field value - in which case the year value is greater than the actual
day value - whatever order the fields are in (even "Mar 2006 15" can
only have one meaning, likewise "27 Feb 29").
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.
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.
[*] apart from guess-the-century error.