On Tue, 13 Dec 2011 20:42:33 +0000, Dr J R Stockton
<
repl...@merlyn.demon.co.uk> wrote:
>In comp.lang.javascript message <4g1de7t607d0sdudjmdv4mr1o4cm5hvekg@4ax.
>com>, Mon, 12 Dec 2011 15:04:33, Gene Wirchenko <
ge...@ocis.net> posted:
>
>> Is it legal to define a toString() for an object with the
>>toString() having one or more parameters?
>>
>> I am going to be defining a date type that does more than the
>>usual implementation does.
>
>
>You have much to learn.
Yup.
Nope. I need practice anyway.
>> (I use certain functionalities fairly
>>heavily in my existing app and would like to have them in the Web
>>version.) One of the things that I need is multiple formats. I could
>>have:
>> toString() like Date's toString()
>> ISO8601DateFormat() date in ISO 8601 format
>
>But which one - basic or extended (expanded or not), common or ordinal
>or week-numbering? With time? With offset indicator?
I mean YYYY-MM-DD. Today is 2011-12-13.
>> IMADateFormat() date in IMA (internal) format
>
>Never heard of it. Describe it, and I'll be able to see whether DOBJ2
>currently handles it. ... If I read your code correctly, and if your
>code is correct, it's just ISO 8601 common basic format.
It is a format internal to the company. It is YYMMDD. It is
used in contexts where a two-digit year is not a problem. For
example, when a shipment comes in, it is tagged as in
111213-0001
which would have been the first package in today.
>If you know that 1000 <= year <=9999,
>that can be coded more briefly as String(Y*1e4 + M*1e2 + D);
>for also 0000-0999, String(1E8 + Y*1e4 + M*1e2 + D).substring(1).
I prefer to not use arithmetic so as to avoid rounding issues. I
am not sure when they would come in in JavaScript.
>An 8-digit result converts to extended format with, IIRC,
>.replace(/(....)(..)(..)/, "$1-$2-$3")
I will have to look at that.
>>or I could have:
>> toString() (no parm)
>
>The output from that is not defined. It would be better not to use it
>in final code.
How so? I build a date and use Date's toString(). What is
undefined about that? Or do you mean that it is not specifically
defined as to format? The latter, I grant.
>> toString(1) or toString(ISO8601)
>> toString(2) or toString(IMADate)
>>
>> I tried it in IE9, and it gives me the results that I want, but
>>all that says it that it can work, not that it should. Is it, in
>>fact, legal to overload toString() like this?
>
>It is replacement, not overloading; but a reference to the original can
>be saved first. In DOBJ2, .toString takes a format string argument,
>default IIRC provided.
>
>With selector 1, your code does NOT return ISO 8601 for 9 months of the
>year and 9 days of each of the rest. Never claim compliance with an
>unfamiliar standard lest you are thought to live south of the nearby
>border.
Got me! A silly mistake considering I insert leading zeroes with
Selector==2. It's that special time of the year... when MM and DD do
not have leading zeroes.
>NOTE that, if your code is essentially calendar work, not needing to
>read the actual date/time much, it is faster to use the UTC methods; and
>then you cannot be troubled with what Those Below quaintly call DST
>changes.
I want a date type, not a datetime type like Date is. I want to
be able to compare dates without worrying about the time of day being
different.
>I suspect, but have not verified, that you are mixing month numbers
>1-12 and 0-11.
Caught me again. Yes, I intend to use 1-12 for my type. I think
that Date's 0-11 is just asking for it. Off-by-one errors are about
the most common, and here JavaScript is making it even easier to screw
up.
>It might be wiser to require selector=0 for the Date Object date, and
>make no arguments as a fatal error. That might prevent mistakes.
I thought that I might get into trouble with JavaScript expecting
such a call to be valid. I might just make it equivalent to one of
the Selector values and never use it.
Thank you for your time.
Sincerely,
Gene Wirchenko