Why does the number of the week of the year start with 1 in 2017 and 0 in 2018?
Date.strptime('2017-01-01', '%Y-%m-%d').strftime('%Y-%m-%d %U') #2017-01-01 01
Date.strptime('2018-01-01', '%Y-%m-%d').strftime('%Y-%m-%d %U') #2018-01-01 00
From the Ruby docs
Week number:
The week 1 of YYYY starts with a Sunday or Monday (according to
%U
or%W
). The days in the year before the first week are in week 0.
%U - Week number of the year. The week starts with Sunday. (00..53)
So it seems that Ruby identifies the "first week" (week 1) as starting with the first Sunday of the year. Anything that happens to come before that exists in week 0. 2017 happened to start on a Sunday, so the first day started the first week. However, 2018 started on a Monday, so week 1 of 2018 will start on January 7th, the first Sunday of the year.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With