You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
week() function returns a 6 day week at the beginning of a year #251
I confirm there is an issue with the week() function. The week starts on Tuesday and ends on Monday.
# The 1st of Sep is a Monday
> week(ymd("2014-09-01"))
[1] 35
# The 2nd of Sep is a Tuesday
> week(ymd("2014-09-02"))
[1] 36
# The 7th of Sep is a Sunday
> week(ymd("2014-09-07"))
[1] 36
# The 8th of Sep is a Monday
> week(ymd("2014-09-08"))
[1] 36
# The 9th of Sep is a Tuesday
> week(ymd("2014-09-09"))
[1] 37
I don't think that the behavior mentioned by IamGianluca is actually a bug. The week documentation says
"Weeks is the number of complete seven day periods that have occurred between the date and January 1st, plus one."
Thus, the weeks returned by week won't normally run Sunday through Saturday (as the wday function does), unless the first day of the year is a Sunday. So since 2014 starts on a Wednesday, the first week (as returned by the week function) should run from Wednesday, January 1 through Tuesday, January 7, and the second week should run from Wednesday, January 8 through Tuesday, January 14, etc. However, the bug I mentioned is causing the first week to end on Monday, January 6 rather than Tuesday, January 7. Then subsequent weeks run from Tuesday through Monday.
@clbieganek you are right. This was a bug, and yes the behavior mentioned by @IamGianluca is as expected. week computes the number of 7 period intervals since the begining of the year including the current week.
Activity
IamGianluca commentedon Sep 2, 2014
I confirm there is an issue with the week() function. The week starts on Tuesday and ends on Monday.
CameronBieganek commentedon Sep 5, 2014
I don't think that the behavior mentioned by IamGianluca is actually a bug. The
weekdocumentation says"Weeks is the number of complete seven day periods that have occurred between the date and January 1st, plus one."
Thus, the weeks returned by
weekwon't normally run Sunday through Saturday (as thewdayfunction does), unless the first day of the year is a Sunday. So since 2014 starts on a Wednesday, the first week (as returned by theweekfunction) should run from Wednesday, January 1 through Tuesday, January 7, and the second week should run from Wednesday, January 8 through Tuesday, January 14, etc. However, the bug I mentioned is causing the first week to end on Monday, January 6 rather than Tuesday, January 7. Then subsequent weeks run from Tuesday through Monday.vspinu commentedon Dec 14, 2014
@clbieganek you are right. This was a bug, and yes the behavior mentioned by @IamGianluca is as expected.
weekcomputes the number of 7 period intervals since the begining of the year including the current week.