JosephMajaseSithole / datejs

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

[INVALID] Behaviour when typing a day name on its own is ambiguous #19

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Specifying "next [some day]" or "last [some day]" behaves as expected, but
specifying "[some day]" on it's own gives you the *nearest* [some day], so
the behaviour will vary depending on the day of the week.  (Typing "monday"
today gives me "last monday", but typing "monday" on Friday will give me
"next monday".)

What is the expected output? What do you see instead?
Personally, I'd expect it to always default to "next [some day]", but that
relies on local convention -- for other people "nearest [some day]" or"last
[some day]" may be the expected behaviour.  (I trust you realise that a
*huge* subset of this problem area requires strong AI? :)

What version of the product are you using? On what operating system?
Firefox 2, OS X 10.5.1

Original issue reported on code.google.com by elbig...@gmail.com on 28 Nov 2007 at 8:45

GoogleCodeExporter commented 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

GoogleCodeExporter commented 8 years ago

Original comment by geoff%co...@gtempaccount.com on 27 Mar 2008 at 10:21