Dr said:
In comp.lang.javascript message <
[email protected]
september.org>, Sat, 13 Jun 2009 17:35:46, Garrett Smith
Any known sort of non-date result is easy enough to check - if the
developer thinks of it.
Compared to "Invalid Date", "" does not require l10n, is easier to
spell, and can be used in boolean context with a predictable outcome.
var result = formatDate(myDate);
if(!result) {
// handle this situation.
}
The intent should be for it to be a good routine, not liable to give
undetected error in actual use. The most probable reason for creating a
date string is to write it to a medium outside the program - the screen,
a file, a comms link, for example.
To encourage testing the result, one can make the function return a
(non-Date) object. For input, I have one in which such an object has
two properties. The first is 3 for a pattern error, 1 for a YMD error,
and false for a good date, in which case the second property is a Date
Object. One is then encouraged to write something like
if (result.Bad) <handleError>
<use> result.D
Function formatDate does not return an object. Any object, such as your
hypothetical "non-date object", would be wrong. At the very least, the
returned value should be consistent. Function formatDate returns a
string value.
The callee, in this case, just returns its value. That value can be
passed to another method M which builds an object, builds and returns
another string, or has behavioral side effects, such as updating the UI
or sending the value to the server.
That would certainly help.
I do not know which are "common" or how common they are, or what the
statistical understandability of each is.
Researcher: [shows card "2002-11-12"]
Subject (American): "November 12, two thousand and two".
Researcher: [shows card "1952-02-12T10:27:29"]
Subject (British): Arse!
That is not a date; not today's, not even that of HM's first Tuesday as
such. It has a separator not expected to be presented to people; and it
has a time; and we would not use that word ("Ass" implies "fool", and
the vulgar prefer more potent words. Granted, that's why Malvern hosted
an RSRE).
How do you know the separator is not expected to be presented to people?
The "T" should not be too confusing.
You should be an editor. You are not called on to write about what you
do not know.
What is the official reference I may cite for "most common formats"?
Even RFC 3339, sec 5.2 does not nail down recommended formats.
"Common formats" depends on frequency of use. "Understandable" depends
on who is doing the reading, and to make a blanket statement about what
can be expected to be understood requires some research. That is
something I have not seen.
What is lacking are reliable resources for 1) "common" formats and 2)
"understandable".
Your suggested text mentions sortability. That is mentioned twice in the
Kuhn document. It could be included with a paragraph on the FAQ. As you
mentioned, or could be linked.
A revision to the Dates main entry, with:
1) "common formats" removed.
2) your previous suggested text added to the top:
3) Link to Kunh document and changes to order of links.
| Unlike others, ISO 8601 formats are language-independent and
| unambiguous world-wide; and, for years 0000-9999, are of constant
| lengths and are sortable as strings. easily readable and writable by
| software
| The most common ISO 8601 Extended format, YYYY-MM-DD, can be
| understood world-wide, without ambiguity.
|
| Never use a local date/time format for a non-local event. Instead, use
| UTC, as in ISO 8601 YYYY-MM-DDThh:mm:ssZ ( Z is the only letter
| suffix).
|
| For a local date/time with time offset, to unambiguously indicate a
| particular instant, use ISO 8601 format YYYY-MM-DDThh:mm:ss±hh:mm.
|
| The T may be omitted where doing so would not cause ambiguity. For an
| SQL date, it must be replaced by a single space.
|
| Never use a local date/time format for a non-local event. Instead, use
| UTC, as in ISO 8601 YYYY-MM-DDThh:mm:ssZ ( Z is the only letter
| suffix).
|
| For a local date/time with time offset, to unambiguously indicate a
| particular instant, use ISO 8601 format YYYY-MM-DDThh:mm:ss±hh:mm.
|
| The T may be omitted where doing so would not cause ambiguity. For an
| SQL date, it must be replaced by a single space.
|
| See also:
| * ISO 8601:2004(E)
| * ECMA-262 Date.prototype, s. 15.9
| * International Standard Date and Time Notation, by Markus Kuhn
| *
http://en.wikipedia.org/wiki/ISO_8601
| * W3C QA Tip: Use international date format (ISO)
Ug. I don't know why I let that slip by me. Yes, that need immediate
attention. I think \s is simple and works in most cases.
I searched 67 days of this newsgroup, omitting spam. There are 121
"if(" and 387 "if (". The FAQ contains 8 of the former (several written
by you) and two of the latter, so the difference in non-FAQ use will be
greater.
It sounds like you are suggesting that the more common convention is to
have a space before the opening parenthesis in an |if| statement because
using a space following the "if" in an |if statement| is according to
your search results (I can't verify), much more popular.
That may be true, but I see no good reason for it. I don't see how it
avoids ambiguity with a function call, as no function could be named
|if| and functions can have a space following the identifier.
[...]
Code for the FAQ **must** be copy'n'pasted from working tested code.
Hand-copying or adjusting is unreliable.
It cannot be done that way. The character > must be converted to an
entity for HTML. That entity is ">". To generate that entity, the xml
contains &gt;.
Garrett