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

effect/DateRange module #2727

Open
jasonkuhrt opened this issue May 11, 2024 · 4 comments
Open

effect/DateRange module #2727

jasonkuhrt opened this issue May 11, 2024 · 4 comments
Labels
enhancement New feature or request

Comments

@jasonkuhrt
Copy link

What is the problem this feature would solve?

A more declarative way to deal with date ranges and combinators over them in day to day work.

A start to integrating more aspects of e.g. date-fns into Effect for furthering its "standard library" value proposition.

date-fns has DateInterval.

What is the feature you are proposing to solve the problem?

Something like this to get the ball rolling:

type DateRange = BetweenDates | SinceDate | UntilDate

interface BetweenDates {
  since: Date
  until: Date
}

interface SinceDate {
  since: Date
}

interface UntilDate {
  until: Date
}

type join = (dateRange1: DateRange, dateRange2: DateRange) => DateRange
type getOverlap = (dateRange1: DateRange, dateRange2: DateRange) => Option<DateRange>
type isOverlap = (dateRange1: DateRange, dateRange2: DateRange) => boolean
type isWithin = (dateRange1: DateRange, dateOrRange2: DateRange | Date) => boolean
type isWithinOrEqual = (dateRange1: DateRange, dateRange2: DateRange | Date) => boolean
type endsBefore = (dateRange1: DateRange, beforeDateOrRange: DateRange | Date) => boolean
type endsAfter = (dateRange1: DateRange, afterDateOrRange: DateRange | Date) => boolean
type beginsBefore = (dateRange1: DateRange, beforeDateOrRange: DateRange | Date) => boolean
type beginsAfter = (dateRange1: DateRange, afterDateOrRange: DateRange | Date) => boolean

What alternatives have you considered?

Not sure this is worth putting in Effect. Maybe someone can riff off it to a worthwhile version. Feel free to close :)

@jasonkuhrt jasonkuhrt added the enhancement New feature or request label May 11, 2024
@jessekelly881
Copy link
Contributor

+1 I wrote something like this a long while ago. Maybe it will serve as some inspiration lol. https://github.com/jessekelly881/time-fns/blob/main/src/Interval.ts

@jasonkuhrt
Copy link
Author

Hey @jessekelly881 link is 404 for me. Private repo?

@jessekelly881
Copy link
Contributor

jessekelly881 commented May 13, 2024

Oops yep. Now it's public :) It's been a while since I wrote it lol. I decided to use { start: Date, duration: Duration } instead of { start: Date, end: Date } because it made things like shifting easier.

@jasonkuhrt
Copy link
Author

@jessekelly881 I like the extend and shift functions, nice!

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

No branches or pull requests

2 participants