Date-handling suggestions for ECMAScript 4 or 5 :-
document.sourceDateHeader
A string copying, exactly, the data part of the Last-Modified
header. Require that new Date(string) shall always read it
correctly (it probably always complies already).
Consider the possibility of a variant so that, for a page constructed at
run-time, one might be able to get both the instant of design and the
instant of constructing the data ???
Granted, "document." is a DOM matter. So :
Dobj.setSourceDate
Dobj is loaded from the Last-Modified header.
Dobj.getSourceDate
Return the date/time in the same standard form.
Let Dobj be a Date Object. LCT is Local Civil Time. Implement, for ISO
8601, routines like these :-
Dobj.toISOlctString()
Returns "yyyy-mm-dd hh:mm:ss +-offset", local civil time
Dobj.toISOutcString()
Returns "yyyy-mm-dd hh:mm:ss UTC", UTC/GMT
Dobj.toISOlctOrdinalString()
Returns "yyyy-ddd hh:mm:ss +-offset", local civil time
Dobj.toISOutcOrdinalString()
Returns "yyyy-ddd hh:mm:ss UTC", UTC/GMT
Dobj.toISOlctWeekString()
Returns "yyyy-Www-dd hh:mm:ss +-offset", local civil time
Dobj.toISOutcWeekString()
Returns "yyyy-Www-dd hh:mm:ss UTC", UTC/GMT
There is no need to provide any of the subset forms, since those can
easily be generated with a .substring() or a .replace(RegExp, String);.
Field yyyy is to be 4 digit, except 5 or 6 after year 9999. Year 0001
to be preceded by 0000, -001, -002, .., -999, -1000, ... ; never fewer
than four characters, Astronomers' Notation.
Dobj.setISOString(DateString[, Offset])
Reads any ISO 8601 string. If there is no offset indication in
the string, the Offset argument is used if present; otherwise
assume local time. Non-standard separators and wrong-width
numbers might be acceptable. T can be space, space can be
spaces or whitespace. Case of T, W ignored. Allow XML date.
Allow DTMF date?
It seems inappropriate to overload that into new Date(); but it could
instead be something else creating a Date Object.
There should also be the set and get operations, UTC and LCT, for YYYY,
WW, & D, and DDD, with similar behaviour to the existing ones; each set
would change only one of YYYY WW D. Implementors should read ISO 8601,
and maybe my "Week" pages, etc., *first*; Microsoft's ISO week number
algorithms should NOT be copied.
AIUI, no other method of week numbering is sufficiently used world-wide
to merit consideration.
ISTM that it could be useful to have an Object type with three Number
fields, Y M D, each individually read/write in the normal manner, and
with a "normalise" method that returned a Boolean indicating whether any
change had been needed. Normalising M>12, for example, would have the
effect of M-=12,Y++ until OK. Then add/subtract any of Y M D is trivial
(do it, normalise); and the Boolean gives a validation result. There
would be a method to set it from a Date Object and one to return a Date
Object (consider GMT offset"). Clearly one can write it in present
Javascript; but a system implementation could be more efficient.
Similarly for a Y W D Object and a Y D Object; and give each Object
methods to set it from Objects of the other types.
P.S. Just found <http://www.ecmascript.org/es4/spec/overview.pdf> page
38 foot. Date will deal with ISO, extent & details not given.
--
(c) John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v6.05 IE 6.
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.
I think they're so minor that nobody really cares.
> Dates - miscdate.htm moredate.htm js-dates.htm pas-time.htm
critdate.htm etc.
Why the obsession with dates doc? Don't take it the wrong way, but I've
always found that the Date object and it's methods is perfectly acceptable.
That header is optional so you need a way of saying it's not there.
Using a default date string, (e.g the Empress Wu's birth date), isn't
acceptable.
<snip>
>ISTM that it could be useful to have an Object type with three Number
<snip>
You don't mean 'Object', I hope. Object objects are empty apart from a
lot of crud in the prototype.
John
--
John Harris
Show us how easy it is to set a date in 25 AD then.
John
--
John Harris
Why would I want to do that?
Why would anyone want to do that?
It's 2007 :)
For anyone that does though, there should be some kind of repository of
useful extended and enhanced Date functions. If only somebody would make
such a thing ;-)
Blessed are the ignorant.
If you can code routines for all of those correctly and efficiently,
you're smarter than Microsoft (that's called damning with faint praise);
but it is alas clear that many who write Javascript fall short of even
that standard. Have you seen the Cassini home page source?
ADDENDUM :
It would also be useful to have a routine which, given a duration in
milliseconds, returns [an object holding] the duration expressed in days
hours minutes and seconds.
Granted, an intelligent ten-year-old of my generation could do that; but
few of the younger programmers seen to approach that standard reliably.
It's a good idea to read the newsgroup c.l.j and its FAQ. See below.
--
(c) John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v6.05 IE 6
news:comp.lang.javascript FAQ <URL:http://www.jibbering.com/faq/index.html>.
<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.
AFAICS :
(1) That header is "always" present.
(2) If the header is absent, an empty string or a string "Absent" should
do adequately; new Date will give NaN. Needs checking to be always
so. AFAICS, ISO/IEC 16262 fails to define it; ECMA 4 needs to.
> <snip>
>>ISTM that it could be useful to have an Object type with three Number
> <snip>
>
>You don't mean 'Object', I hope. Object objects are empty apart from a
>lot of crud in the prototype.
Consider it as an empty pot containing crud and three added items !
The range of Date is about +-275000 years. If a range of +-100000 years
suffices, consider
AD = 25, MO, DY
DObj = new Date(AD+1e5, MO-1-12e5, DY)
Aha! In fact, in IE6, new Date accepts years over 1e6, provided that
the month is suitably negative; so just change e5 to e6. Needs checking
in all browsers. But ISO 16262 requires it; should be good when the
revised Month is no bigger than +=2^53 and the date is in-range.
But DObj = new Date(0); DObj.setFullYear(25, 11-1, 05) works too.
If four-digit years in the First Century must be supplied as literals,
express them as strings (not needed after AD77, of course). Note
with (DObj = new Date(0)) setFullYear(0027, 11-1, 05)
For proper AD 25 dates, in the Julian Calendar, see js-date8.htm.
To handle AUC years, subtract DCCLIII and translate my wr-roman.pas or
cvt-rome.pas. Roman day-of-month is left as an exercise. Roman month
numbers are in js-date4.htm#Genl.
On a vaguely-related topic, I now have Javascript which can be used to
check every YYYY-MM-DD DoW date in a page or site for being a valid
Gregorian date (year 0 to 275000+) with the right DoW. In js-misc1.
> John G Harris wrote:
>> Show us how easy it is to set a date in 25 AD then.
>
> Why would I want to do that?
> Why would anyone want to do that?
> It's 2007 :)
You may find yourself in a situation where you need to write software
to automate archaeological research. You may want to develop software
for date calculations that also handle dates Ante Christum Natum. You
may be interested in storing and dealing with historically related
data. You may be interested in geological, sociological or economic
evolution over the centuries. You may use your creativity to think of
many more situations :-)
> For anyone that does though, there should be some kind of repository of
> useful extended and enhanced Date functions. If only somebody would make
> such a thing ;-)
http://search.cpan.org/dist/Date-Manip/Manip.pod
and/or
http://search.cpan.org/dist/Date-Calc/Calc.pod
might inspire.
--
Bart
There's a lot there; but it's a pity that they don't indicate more
obviously what language they're using. It's Perl.
--
(c) John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v6.05 IE 6.
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