haskell / time

A time library

Home Page:http://hackage.haskell.org/package/time

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Week type

NorfairKing opened this issue · comments

It would be like Month but for absolute weeks, wrapping an integer.

Starting which day?

@AshleyYakeley Oh bother, good point.

I'd be happy with it being Monday and leaving it at that, but you could also put it at the type level or make its interpretation configurable I guess.

Well, what's your anticipated use for the type?

Are there any standard or pre-existing numberings of weeks?

I want to resolve Monday to "the soonest monday after today" or "the most recently past monday".
So I'd like to do something like:

resolve :: Day -> DayOfWeek -> Maybe Day
resolve today dow = 
  let (w, _) = toAbsoluteWeekDay today
      guessThisWeek = fromAbsoluteWeekDay (w, dow)
      guessNextWeek = fromAbsoluteWeekDay (succ w, dow)
  in if guessThisWeek > today then guessThisWeek else guessNextWeek

Currently I have to go via Year and WeekOfYear unlike I have to do when I want to do something similar for "the soonest 15th of the month after today".

Relevant code: https://hackage.haskell.org/package/fuzzy-time

Are there any standard or pre-existing numberings of weeks?

Not that I can find here: https://en.wikipedia.org/wiki/ISO_week_date

In hindsight this would probably cause more confusion than it will help with, because of the "which start day?" problem.

Can't you do this?

"the soonest monday after today" = firstDayOfWeekOnAfter Monday $ succ today

"the most recently past monday" = firstDayOfWeekOnAfter Monday $ addDays (negate 7) today

Oh ehm, I didn't know about those functions
Whoops, and Thanks!