Reputation: 115
The week() function in Julia DateTime implementation returns week number of the year using ISO Calendar which means monday is first day of the week. In the USA Sunday is the first day of week which causes Sundays to have week number of decremented by 1. Is there a way to specify the first day of the week as Sunday for week() function?
Upvotes: 2
Views: 422
Reputation: 631
Monday is baked into the code.
It looks like you just have to deal with it.
d = DateTime(2017,11,25) # Saturday
w = Dates.issunday(d) ? Dates.week(d) + 1 : Dates.week(d)
# 47
d = DateTime(2017,11,26) # Sunday
w = Dates.issunday(d) ? Dates.week(d) + 1 : Dates.week(d)
# 48
Julia 0.6.1 See JuliaDirectory/share/julia/base/dates/accessors.jl line 35
# https://en.wikipedia.org/wiki/Talk:ISO_week_date#Algorithms
const WEEK_INDEX = (15, 23, 3, 11)
function week(days)
w = div(abs(days - 1), 7) % 20871
c, w = divrem((w + (w >= 10435)), 5218)
w = (w * 28 + WEEK_INDEX[c + 1]) % 1461
return div(w, 28) + 1
end
Upvotes: 4