Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Documentation for input[week] doesn't mention what will be the underlying Date object #15883

Closed
1 of 3 tasks
v1nc3n4 opened this issue Apr 3, 2017 · 6 comments · Fixed by #16104
Closed
1 of 3 tasks

Comments

@v1nc3n4
Copy link

v1nc3n4 commented Apr 3, 2017

I'm submitting a ...

  • bug report
  • feature request
  • other (Please do not submit support requests here (see above))

Current behavior:

The documentation for angular input[week] says the input text 'yyyy-Www' is transformed into a Date object. But it can hardly be used as the documentation doesn't say exactly which day of the week, and what time is put in the Date object.

Expected / new behavior:

The documentation shall mention what will be the underlying Date object.

Minimal reproduction of the problem with instructions:

Angular version: 1.6.2

Browser: [all]

Anything else:

@frederikprijck
Copy link
Contributor

frederikprijck commented Apr 3, 2017

I wouldn't say the input[week] is not usable due to this as it's pretty easy to check for yourself:
https://plnkr.co/edit/bn6TieIDiyS5HgaQQgXF?p=preview

I'm abit confused as it looks like it defaults to wednesdays for me. I guess it would be good to update the docs. (edit: it appeared to be thursday local time (UTC+2), but was displayed wednesday due to UTC)

@v1nc3n4
Copy link
Author

v1nc3n4 commented Apr 3, 2017

It seems to be locale-dependent also. In France, it seems to be thursday, as the first day of week is monday.

@frederikprijck
Copy link
Contributor

frederikprijck commented Apr 3, 2017

It seems to be using thursday as the day by adding a certain factor of 7 days to the firstThursday of that year:

firstThurs = getFirstThursdayOfYear(year),

return new Date(year, 0, firstThurs.getDate() + addDays, hours, minutes, seconds, milliseconds);

Any idea what the reason for this is @gkalpak ?

@gkalpak
Copy link
Member

gkalpak commented Apr 3, 2017

From WikiPedia on ISO 8601:

There are several mutually equivalent and compatible descriptions of week 01:

  • the week with the year's first Thursday in it (the formal ISO definition),
    [...]
    The week number can be described by counting the Thursdays: week 12 contains the 12th Thursday of the year.
    [...]
    The Thursday of each ISO week is always in the Gregorian calendar year denoted by the ISO week-numbering year.

So, we find the first Thursday and then count Thursdays to find the week number.
I am not 100% sure why we pick Thursday as the day for the Date object, but I suspect it is because it is the only day of the week that is guaranteed to be in the Gragorian calendar year denoted by yyyy.

Docs improvements are always welcome 😃

@frederikprijck
Copy link
Contributor

frederikprijck commented Apr 3, 2017

I am not 100% sure why we pick Thursday as the day for the Date object, but I suspect it is because it is the only day of the week that is guaranteed to be in the Gragorian calendar year denoted by yyyy.

By looking at the ISO spec, I think it makes perfect sense to pick thursday. As it's possible that any other day of that week (when using thursday to calculate week number) could be in a different month/year (so different Gregorian calendar year as you said).

@gkalpak
Copy link
Member

gkalpak commented Apr 11, 2017

@Vicente69 or @frederikprijck, if you feel like submitting PR adding a note to the docs, please do 😁

Narretz pushed a commit that referenced this issue Jul 13, 2017
Add a note to documentation of input[week] to explicitly state that the
resulting Date object's value is set to Thursday at midnight of the
specified week.

Resolves #15883 
Closes #16104
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants