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

Compute quarter boundaries based on a given day/quarter #179

Closed
sestrella opened this issue Sep 28, 2021 · 6 comments · Fixed by #180
Closed

Compute quarter boundaries based on a given day/quarter #179

sestrella opened this issue Sep 28, 2021 · 6 comments · Fixed by #180
Milestone

Comments

@sestrella
Copy link
Contributor

sestrella commented Sep 28, 2021

The addition of a module to handler quarters is very useful. As a Rubyist (and Haskeller) I like to come back to Ruby in search of features to implement in Haskell and I found the following one pretty useful:

irb(main):002:0> Date.current.all_quarter
=> Thu, 01 Jul 2021..Thu, 30 Sep 2021

An equivalent Haskell version would look something similar to:

allQuarter :: Day -> (Day, Day)
-- or
allQuarter :: Year -> Quarter -> (Day, Day)

I understand this is a core library and this feature might get rejected, but dealing with quarters seems like a pretty common use case. I'll be more than happy to submit a PR if this feature gets approved.

Reference

@AshleyYakeley
Copy link
Member

This or something like it makes sense.

@AshleyYakeley AshleyYakeley added this to the 1.13 milestone Sep 28, 2021
@AshleyYakeley
Copy link
Member

Number of ways we could go with this. For example, we currently have:

type DayOfMonth = Int
pattern MonthDay :: Month -> DayOfMonth -> Day -- bidirectional

So we could do this:

type DayOfQuarter = Int
pattern QuarterDay :: Quarter -> DayOfQuarter -> Day -- bidirectional

Alternatively (or additionally), we could do:

class HasDays t where
    firstDay :: t -> Day
    lastDay :: t -> Day

lengthDays :: HasDays t => t -> Int
lengthDays t = succ $ diffDays (lastDay t) (firstDay t)

instance HasDays Year
instance HasDays Quarter
instance HasDays Month
instance HasDays Day

@sestrella
Copy link
Contributor Author

Great, thank you for the ideas, I'm going to try the first approach

AshleyYakeley added a commit that referenced this issue Oct 10, 2021
[#179] Add HasDays type class and instances
@AshleyYakeley
Copy link
Member

Going to do QuarterDay pattern as well I think.

@AshleyYakeley AshleyYakeley reopened this Oct 10, 2021
AshleyYakeley added a commit that referenced this issue Oct 10, 2021
AshleyYakeley added a commit that referenced this issue Oct 11, 2021
@AshleyYakeley
Copy link
Member

OK this is done now.

@sestrella
Copy link
Contributor Author

@AshleyYakeley thank you for all the follow-up work renaming the type class and moving class instances close to the type definitions, I was in doubt of following that path or creating a separate Instances module like FormatTime and ParseTime. I'm planning to submit a PR adding some property/unit tests for those functions that have DayPeriod as a type constraint if that is OK with you?

AshleyYakeley added a commit that referenced this issue Oct 23, 2021
[#179] Add property and unit tests for DayPeriod functions
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

Successfully merging a pull request may close this issue.

2 participants