2.1.102 [ECMA-262-1999] Section 15.9.4.2, Date.parse (string)

V0154:

__If string is not present or is the value null or undefined, the parse function returns NaN. Otherwise, the__ #The# parse function applies the #ToString# __ToPrimitive__ operator to its argument __and then applies ToString to that result__ and interprets the resulting string as a date; it returns a number, the UTC time value corresponding to the date. The string may be interpreted as a local time, a UTC time, or a time in some other time zone, depending on the contents of the string.

V0155:

__JScript 5.x parses the string value and produces a value in accordance with the following grammar and rules. If the string can not be recognized starting with the production DateString according to these rules, the number value NaN is returned.__

__Date String Syntax__

__The following lexical grammar defines the tokens that make up date strings.__

__DateToken ::__

__Separator
NumericDateToken
AlphaDateToken
DateComment
OffsetFlag
__

__Separator :: one of__

__, : / <SP>__

__DateComment ::__

__( DateCommentBodyopt )__

__DateCommentBody ::__

__DateCommentChars
DateCommentopt
DateComment
DateCommentBodyopt
__

__DateCommentChars ::__

__DateCommentChar DateCommentCharsopt__

__DateCommentChar ::__

__DateChar but not ( or )__

__OffsetFlag :: one of__

__+ -__

__AlphaDatetoken ::__

__AlphaDateComponent periodopt__

__AlphaDateComponent ::__

__WeekDay
Month
TimeZone
MilitaryTimeZone
AmPmFlag
AdBcFlag
__

__period ::__

__.__

V0156:

__WeekDay ::__

__Sunday
Monday
Tuesday
Wednesday
Thursday
Friday
Saturday
__

__Month ::__

__January
February
March
April
May
June
July
August
September
October
November
December
__

__TimeZone ::__

__est
edt
cst
cdt
mst
mdt
pst
pdt
gmt
utc
__

__MilitaryTimeZone ::__

__a [lookahead Ï { .m m d .d p u}]
p [lookahead Ï { .m m d s}]
b [lookahead Ï { .c c}]
f [lookahead Ï { e i}]
m [lookahead Ï { a d o s}]
s [lookahead Ï { a e u}]
o [lookahead ≠ c]
n [lookahead ≠ o]
d [lookahead ≠ e]
t [lookahead Ï { h u}]
w [lookahead ≠ e]
e [lookahead Ï { d s}]
c [lookahead Ï { d s}]
g [lookahead ≠ m]
u [lookahead ≠ t]
UniqueMilitaryTimeZone
__

__UniqueMilitaryTimeZone :: one of__

__ z y x v r q h i k l__

__AmPmFlag ::__

__am
a.m
pm
p.m
__

__AdBcFlag ::__

__ad
a.d
bc
b.c
__

V0157:

__NumericDateToken ::__

__NumericDateComponent -
NumericDateComponent
[lookahead ≠ -]__

__NumericDateComponent ::__

__DateDigit [lookahead Ï DateDigit]
DateDigit DateDigit
[lookahead Ï DateDigit]
DateDigit DateDigit DateDig
it [lookahead Ï DateDigit]
DateDigit DateDigit DateDigit DateDigit
[lookahead Ï DateDigit]
DateDigit DateDigit DateDigit DateDigit DateDigit
[lookahead Ï DateDigit]
DateDigit DateDigit DateDigit DateDigit DateDigit DateDigit
[lookahead Ï DateDigit]__

__DateDigit :: one of__

__0 1 2 3 4 5 6 7 8 9__

V0158:

__Sunday ::__

__su
sun
sund
sunda
sunday
__

__Monday ::__

__mo
mon
mond
monda
monday
__

__Tuesday ::__

__tu
tue
tues
tuesd
tuesda
tuesday
__

__Wednesday ::__

__we
wed
wedn
wedne
wednes
wednesd
wednesda
wednesday
__

__Thursday ::__

__th
thu
thur
thurs
thursd
thursda
thursday
__

__Friday ::__

__fr
fri
frid
frida
friday
__

__Saturday ::__

__sa
sat
satu
satur
saturd
saturda
saturday
__

V0159:

__January ::__

__ja
jan
janu
janua
januar
january
__

__February ::__

__fe
feb
febr
febru
februa
februar
february
__

__March ::__

__ma
mar
marc
march
__

__April ::__

__ap
apr
apri
april
__

__May ::__

__ma
may
__

__June ::__

__jun
june
__

__July ::__

__ju
jul
july
__

__August ::__

__au
aug
augu
augus
august
__

__September ::__

__se
sep
sept
septe
septem
septemb
septembe
september
__

__October ::__

__oc
oct
octo
octob
octobe
october
__

__November ::__

__no
nov
nove
novem
novemb
novembe
november
__

__December ::__

__de
dec
dece
decem
decemb
decembe
december
__

V0160:

__Parsing rules for Date.parse Date strings:__

  1. __The string to be parsed is converted to lower case before applying these rules.__

  2. __The above grammar defines by means of NumericDateTokens or AlphaDateTokens the following components of a date object: weekday, year, month, date, hours, minutes, seconds, time zone, AD/BC flag, and AM/PM flag.__

  3. __Any date string has to define at least year, month, and date components. No component can be multiply defined.__

  4. __Except for cases that are explicitly specified otherwise, the components can be in any order.__

  5. __OffsetFlags:__

    __'+' and '-' (when not following a number) act as offset classifier. The next numeric component following an offset classifier is classified as an offset value. The numeric component doesn't have to immediately follow '+/-'.__

    __+offset and -offset cannot be specified before the year field. +/- offsets refers to UTC time zone and set the time zone to UTC. It is an error to have a time zone component following a +/- offset.__

  6. __Time classification of numeric components. The separator char ':' acts as a time classifier:__

    __':' following a number classifies the previous numeric component as 'hour'.__

    __':' following a number classified as 'hour' will classify the next numeric component as 'minute'. The next numeric component doesn't have to follow immediately.__

    __':' following a numeric component classified as 'minute' will classify the next numeric component as 'seconds'. The next number doesn't have to follow immediately.__

  7. __Date classification of numeric components.__

    __A not classified number with value >= 70 is always classified as year. Even when it is followed by a ':' and could be classified as hour. In this case ':' is a simple separator.__

    __A number not classified by a classifier is always classified as a date.__

    __'/' and '-' separator chars can act as classifiers:__

    __'/' or '-' following a numeric component classifies that numeric component as month.__

    __'/' or '-' following a numeric component classified as month will classify the next numeric component as a date. The next numeric component does not have to follow immediately.__

    __'/' or '-' following a numeric component classified as date will classify the next numeric component as a year. The next numeric component does not have to follow immediately.__

  8. __The week day is ignored regardless of whether it is correct or incorrect.__

  9. __The default value for AD/BC flag is AD.__

  10. __When AM/PM flag is not defined the default interpretation for hours is 24hr notation. The AM flag is ignored when the time is > 13:00:00. When the PM flag is used the time has to be < 12:00.__

V0161:

__Algorithm for computing the time value:__

__Via classification, numeric components, and alpha components, numeric values are calculated for: year, month, date, time. The following adjustments are done because of the flags, offsets, and timezones:__

  1. __If the BC/AD flag is BC, year = -year + 1. Note that 1 BC is year 0 and 2 BC is year - 1.__

  2. __If the BC/AD flag is AD and the year value is < 100, then year = year + 1900. This rule allows the short form for year. For example, 99 stands for 1999.__

  3. __The time value (time in the day) is calculated in seconds from the hour, minute, and seconds components. AM/PM flag can change the time value:__

    1. __If no AM/PM flag is present the time is considered in 24hrs notation and no adjustment is done.__

    2. __If time >= 12 * 3600 and time < 13 * 3600 and AM then time = time – 12 * 3600 (for example, 12:45 AM means 0:45).__

    3. __If the PM and time < 12 * 3600, then time = time + 12 * 3600 (for example, 2PM means 14:00).__

  4. __Zone adjustment. The result of 3 is adjusted by the zone disp values specified below. Check the values for TimeZone and MilitaryTimeZone. If 'zone' is the value for a given zone, the time is adjusted by: time = time - zone * 60.__

  5. __Offset adjustment. The offset value applies to the time in UTC zone. Let nn be the value of the numeric component following an offset. The formula for the value in seconds that adds up to the UTC time is:__

    __If nn <24__

    __vOffset = 60 * nn * 60__

    __If nn >= 24__

    __vOffset = 60 * (nn modulo 100) + (floor (nn / 100)) * 60))__

    __time = Result(4) - vOffset * 60__

  6. __Date adjustment. Set date = date – 1.__

  7. __Month adjustment. Set month = (month-1).__

  8. __Final calculation:__

    __year = year + floor(month / 12)__

    __month = Remainder(month, 12)__

    __day = day + DayFromYear(year)__

    __day = day + DayNumbersForTheMonthOfALeapYear(month);__

    __if month >= 2 && year is not a leap then day = day - 1__

    __result = day * 86400000 + time__

  9. __If no time zone was specified, consider this time in the current local time zone and get the UTC displacement of the time.__

    Time Zone

    UTC displacement

    __est__

    __-5__

    __edt

    __-4__

    __cst__

    __-6__

    __cdt__

    __-5__

    __mst__

    __-7__

    __mdt__

    __-6__

    __pst__

    __-8__

    __pdt__

    __-7__

    __gmt__

    __0__

    __utc__

    __0__

    Military Time Zone

    UTC displacement

    __z__

    __0__

    __y__

    __12__

    __x__

    __11__

    __w__

    __10__

    __v__

    __9__

    __u__

    __8__

    __t__

    __7__

    __s__

    __6__

    __r__

    __5__

    __q__

    __4__

    __p__

    __3__

    __o__

    __2__

    __n__

    __1__

    __a__

    __-1__

    __b__

    __-2__

    __c__

    __-3__

    __d__

    __-4__

    __e__

    __-5__

    __f__

    __-6__

    __g__

    __-7__

    __h__

    __-8__

    __i__

    __-9__

    __k__

    __-10__

    __l__

    __-10__

    __m

    __12__