Closed GoogleCodeExporter closed 8 years ago
Actually I think the problem is rather simple and works as follows.
"next monday" returns the next Monday from today.
"last monday" returns the previous Monday from today.
"monday" returns the Monday of the current week.
Examples
// if today is monday
Date.parse('monday'); // returns today
// if today is tuesday
Date.parse('monday'); // returns yesterday
// if today is friday
Date.parse('monday'); // returns the last monday (4 days ago)
The tricky bit happen with "Sundays" because the first-day-of-the-week varies by
Culture/Language/Country. Usually the week either starts on Sunday or Monday.
Example
// if today is Friday, and the firstDayOfWeek (for the culture) is Sunday
Date.parse('sunday'); // returns "last sunday"
// if today is Friday, and the firstDayOfWeek (for the culture) is Monday
Date.parse('sunday'); // returns "next sunday"
The parser handles this all correctly. The parser knows the firstDayOfWeek from
the
CultureInfo file. Date.CultureInfo.firstDayOfWeek.
You can also perform the same functionality in code with the API.
Example
// if today is Friday, and the firstDayOfWeek (for the culture) is Sunday
Date.sunday(); // returns "last sunday"
// if today is Friday, and the firstDayOfWeek (for the culture) is Monday
Date.sunday(); // returns "next sunday"
Hope this helps.
Original comment by geoff%co...@gtempaccount.com
on 28 Nov 2007 at 11:17
Original comment by geoff%co...@gtempaccount.com
on 27 Mar 2008 at 10:21
Original issue reported on code.google.com by
elbig...@gmail.com
on 28 Nov 2007 at 8:45