Skip to content

Feature request: add function to calculate the starting date of a week for a given year #57908

@hhaensel

Description

@hhaensel

AFAIK there's currently no function to calculate the starting date of a week for a given year. I've stumbled across https://discourse.julialang.org/t/determine-date-range-given-year-and-week-number/93878/11 that provides a solution.
Based on that discussion, I propose the following addition to Dates:

function firstdayofISOyear(x)
  firstday = firstdayofweek(firstdayofyear(x))
  week(firstday) == 1 ? firstday : firstday + Day(7)
end
firstdayofISOyear(x::Integer) = firstdayofISOyear(Date(Year(x)))

firstdayofISOweek(year, week::Integer) = firstdayofISOyear(year) + Day(7(week - 1))
# or alternatively add a two-argument method to `firstdayofweek()`
firstdayofweek(year, week::Integer) = firstdayofISOyear(year) + Day(7(week - 1))

would be interested in knowing what you think.

Metadata

Metadata

Assignees

No one assigned

    Labels

    datesDates, times, and the Dates stdlib modulefeatureIndicates new feature / enhancement requests

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions