In comp.lang.javascript message <96661402-8d83-4437-b2c7-f8a55696811f@v3
0g2000yqm.googlegroups.com>, Thu, 19 Nov 2009 14:28:40, Jason
We created a simple Javascript function for date formatting to use on
FeedMagnet.com (a tool that helps businesses harness social media).
We're releasing the code to the public and hope other can benefit from
it. It essentially maps the PHP date formatting character strings
(e.g. "F j, Y") so you can use them in Javascript.
Here's the link for more explanation and the code:
http://budurl.com/jsdate
Have you considered testing the code?
Near the end, I see a line
var m = date.getHours() > 0 && date.getHours < 12 ? 'am' : 'pm'
so it appears at first that 'am' is used from 01:00 up to 12:00 and 'pm'
is used for 00:00 up to 01:00 and 12:00 up to 24:00. But perhaps
reading the rest of the code would explain it. There again, the lack of
parentheses after the second getHours is interesting; it eliminates
mornings.
There's an intrinsic problem with the 12-hour clock for times which
cannot by general context be placed within a range of at most 12 hours.
To want to use it, one must be daft; to use it correctly, one must not
be daft. Fortunately, over 99% of countries seem to understand ISO 8601
well enough to be able to use it within IT work.
That page needs inspection by its author in Firefox with text zoom. I
have to zoom out to see the ends of the code lines; but then the entire
code is too small and faint to read.
Most of the Date methods, especially the non-UTC ones, are relatively
slow. Therefore, where a result is used more than once (e.g.
getHours()), it should be determined once and saved for following use.
Compare, for example, the line (wrapped here)
if (format.indexOf('D') > -1 || format.indexOf('N') > -1 ||
format.indexOf('w') > -1 || format.indexOf('l') > -1) {
with
if ( /[DNwl]/.test(format) ) {
which is certainly shorter and is somewhat quicker in Firefox 3.0.15.
You should have used the Wayback machine to read old versions of the
FAQ on the subject of date.
The FeedMagnet site gives no clear indication of who is responsible for
it, or what country it comes from. Reputable authors, and many others,
always give a clear indication of who is responsible for the work.
Without that, one naturally assumes the worst. The site and code seem
to justify that - for example, I see a price of "$50/year/employee"
without any indication of which breed of $ is intended.
On the cited page,
http://validator.w3.org/ gives '3 Errors, 1
warning(s)'. That seems hopeful, until one sees ' Line 19, Column 31:
script element between head and body. <script
type="text/javascript">Line 19, Column 31: Cannot recover after last
error. Any further errors will be ignored.
<script type="text/javascript">' and that it has 270 more lines.
I suppose, therefore, that you don't validate your pages.