Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #19035

Re: Accessing Constructor Arguments

From Dr J R Stockton <reply1300@merlyn.demon.co.uk.invalid>
Newsgroups comp.lang.javascript
Subject Re: Accessing Constructor Arguments
Date 2013-03-27 20:56 +0000
Organization Home
Message-ID <Z2sAGlLT01URFwP1@invalid.uk.co.demon.merlyn.invalid> (permalink)
References <a75c7d49-b129-4d92-a7a1-2bce31b71ce4@googlegroups.com> <XnsA18FF4162252Eeejj99@194.109.133.133>

Show all headers | View raw


In comp.lang.javascript message <XnsA18FF4162252Eeejj99@194.109.133.133>
, Tue, 26 Mar 2013 23:59:40, Evertjan. <exxjxw.hannivoort@inter.nl.net>
posted:

> wrote on 26 mrt 2013 in comp.lang.javascript:
>
>> Interestingly, when a new instance of Date is created, if the date
>> supplied via the arguments is not a valid date, the date is
>> automatically adjusted to its nearest valid neighbor.
>
>You ony have to check the validity of two[!]
>of the three parts of the resulting date,
>something like:
>
>var tempA = myDateString.split(/[-.\/]/); // d-m-yyyy expected
>
>// [test for the array size being 3, and the components being numeric]
>
>var tempD = new Date(tempA[2],tempA[1]-1,tempA[0]);
>
>if (tempA[1]-1 != tempD.getMonth()) ... error
>
>if (tempA[2] != tempD.getFullYear()) ... error
>
>// now tempD.getDate() must be correct by logic.


For "two[!]" read "one[!!]".

Do the split with a crafty RegExp, thereby ensuring that the day-of-
month lies in '00' to '99; create a new Date Object from the split, and
check that the Month "in" the Object agrees with the month in the split
string.

But, of course, it is not possible to check a date string for validity
without more information - is 1712/02/30 valid? it is, and the location
must be not very far to the NE of the Netherlands.  Is 1752-09-12 valid?
not here, and I think I therefore once remarked to my mother on her
birthday that she could not possibly have been exactly some specific
considerable number of decades older.  Is 14/11/1948 valid? of course,
it is the DoB of a.k.a. the Earl of Chester.  Are 2013-W13-3 and 2013086
valid?  Yes, and they represent today (Wednesday), and so is 56378.

Remember the delightful tale of the American who tried in September YYYY
to enter Europe using a visa marked as expiring 11.06.YYYY (a genuine
example represented by made-up details).

To check for meaningful validity, one needs in general to know the
Calendar (Gregorian, Julian, Civil (where?), etc.), the notation or
allowable notations (e.g. ISO, Euro-trad, FFF) and if not numeric the
allowable languages.

Remember too that 16-bit Unicode, as used in JavaScript, has at least
two ways of specifying (for the learned such as yourself, and for anyone
educated long enough ago, and for film fans) each of the dozen months of
the Christian calendar with a single character.

The OP should have read the FAQ, which might then have guided him to my
Web site.

The OP's second sentence is incorrect.

-- 
 (c) John Stockton, nr London, UK.   E-mail, see Home Page.    Turnpike v6.05.
 Website  <http://www.merlyn.demon.co.uk/> - w. FAQish topics, links, acronyms
 PAS EXE etc. : <http://www.merlyn.demon.co.uk/programs/> - see in 00index.htm
 Dates - miscdate.htm estrdate.htm js-dates.htm pas-time.htm critdate.htm etc.

Back to comp.lang.javascript | Previous | Next — Previous in thread | Find similar | Unroll thread


Thread

Accessing Constructor Arguments ddjolley@gmail.com - 2013-03-26 09:59 -0700
  Re: Accessing Constructor Arguments Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-03-26 18:32 +0100
  Re: Accessing Constructor Arguments JJ <jaejunks@nah.meh> - 2013-03-27 05:53 +0700
  Re: Accessing Constructor Arguments "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2013-03-26 23:59 +0100
    Re: Accessing Constructor Arguments Dr J R Stockton <reply1300@merlyn.demon.co.uk.invalid> - 2013-03-27 20:56 +0000

csiph-web