byteverse / chronos

Haskell time library focusing on performance
Other
54 stars 22 forks source link

API for week-of-year? #64

Open complyue opened 3 years ago

complyue commented 3 years ago

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

andrewthad commented 3 years ago

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 commented 3 years ago

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

Thanks for the information.