Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API for week-of-year? #64

Open
complyue opened this issue Apr 6, 2021 · 2 comments
Open

API for week-of-year? #64

complyue opened this issue Apr 6, 2021 · 2 comments

Comments

@complyue
Copy link

complyue commented Apr 6, 2021

I can't find an API to obtain week-of-year from a Datetime, is it intended so or missing by accident?

@andrewthad
Copy link
Member

Since the Datetime is YYYY-MM-DD HH-MM-SS, there is no easy way to extract the week of the year. The Time data type (nanoseconds since the epoch) is considered canonical in this library, and any human-friendly presentation of it should first convert it to some other type and then encode that.

That aside, all the week-of-year stuff is missing because I just never needed it. The API would look something like this:

data YearWeek = YearWeek
  { yearWeekYear :: !Int64
  , yearWeekWeek :: !Int -- should be less than 53 (or 54?)
  }
timeToYearWeek :: Time -> YearWeek

And then various encodeYearWeek functions are possible but not necessary. If you or anyone else wants to add this, I'd take a PR.

@complyue
Copy link
Author

complyue commented Apr 6, 2021

Sure, I think I'll prepare a PR per my schedule.

Thanks for the information.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants