pingjiang / datejs

Automatically exported from code.google.com/p/datejs
Other
0 stars 0 forks source link

[FIXED] Parsing DayName only always return 'today' #7

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
If you parse just a valid day name (friday, monday, etc), the parser always
returns today's date. 

Date.parse('friday') // returns today
Date.parse('monday') // returns today

Parsing month names works as expected. 

Date.parse('march')  // returns 1st of March

Original issue reported on code.google.com by geoff%co...@gtempaccount.com on 13 Nov 2007 at 8:54

GoogleCodeExporter commented 9 years ago
Added the following check in Date.Translator.finish()

if (this.weekday && !this.day) {
    this.day = (today.addDays((Date.getDayNumberFromName(this.weekday) -
today.getDay()))).getDate();
}

The day will be set to day-of-the-week as supplied. The functionality is 
different
than 'next | last', as the day-of-the-week could be in the past or future. 

Example

// If today is Tuesday...
Date.parse('monday') // returns yesterday's date
Date.parse('wed')    // returns tomorrow's date

The following parse is now also possible...

// If today is 13-Nov-2007
Date.parse('friday march') // 13-Mar-2007 

Original comment by geoff%co...@gtempaccount.com on 13 Nov 2007 at 9:52