effect icon indicating copy to clipboard operation
effect copied to clipboard

effect/DateRange module

Open jasonkuhrt opened this issue 1 month ago • 4 comments

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 avatar May 11 '24 04:05 jasonkuhrt

+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

jessekelly881 avatar May 13 '24 14:05 jessekelly881

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

jasonkuhrt avatar May 13 '24 15:05 jasonkuhrt

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.

jessekelly881 avatar May 13 '24 15:05 jessekelly881

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

jasonkuhrt avatar May 13 '24 16:05 jasonkuhrt