Skip to content

Instantly share code, notes, and snippets.

@darrenldl
Last active December 11, 2020 07:47
Show Gist options
  • Save darrenldl/f9f474e65dbc8b681e1c31bc36d79801 to your computer and use it in GitHub Desktop.
Save darrenldl/f9f474e65dbc8b681e1c31bc36d79801 to your computer and use it in GitHub Desktop.

Examples

"starting from 2020 Dec, every 2 months, second thursday"

(since_year 2020 (since_start_of_month `Dec (every_nth_month 2 (nth_weekday 2 `Thu entire_day))))

"every other day of year 2020"

(since_year 2020 (until_year 2020 (every_nth_day_of_year 2 entire_day)))
or
year 2020 & every_year (every_nth_day_of_year 2 entire_day)

"every other day of every other month"

(every_nth_month 2 (every_nth_day 2 entire_day))

"11pm to 2am" (not expressible via branching)

(between_exc (hour 23) (hour 2))

"20th to 1st" (not expressible via branching)

(between_inc (day 20) (day 1))

"the Friday the 13th following the 15th day of the 3rd month of 1985" (example from timenorm)

after (year 1985 & month `Mar & day 15) (weekday `Fri & day 13)

API

Search control

since_year : int -> since_month -> t

since_start_of_year : int -> t -> t

since_month : month -> since_day -> since_month

since_start_of_month : month -> t -> since_month

since_day : int -> since_hms -> since_day

since_start_of_day : int -> t -> since_day

since_hms : hms -> t -> since_hms

since_month : month -> since_day -> since_month

since_start_of_month : month -> t -> since_month

since_day : int -> since_hms -> since_day

since_start_of_day : int -> t -> since_day

since_hms : hms -> t -> since_hms

similarly defined for until_*

type boundary = [
  | `Year
  | `Month
  | `Day
]

after : ?boundary:boundary -> t -> t -> t

between_inc : ?boundary:boundary -> t -> t -> t

between_exc : ?boundary:boundary -> t -> t -> t

Recurrence (sensitive to search control)

module Recur = struct
  every_year : recur_in_year -> t

  every_nth_year : int -> recur_in_year -> t
  
  entire_month : recur_in_month

  every_month : recur_in_month -> recur_in_year

  every_nth_month : int -> recur_in_month -> recur_in_year

  month : month -> recur_in_month -> recur_in_year
  
  entire_day : recur_in_day

  every_day : recur_in_day -> recur_in_month

  every_day_of_year : recur_in_day -> recur_in_year

  every_nth_day : int -> recur_in_day -> recur_in_month

  every_weekday : weekday -> recur_in_day -> recur_in_month

  every_weekday_of_year : weekday -> recur_in_day -> recur_in_year

  every_nth_weekday : int -> weekday -> recur_in_day -> recur_in_month
  
  nth_weekday : int -> weekday -> recur_in_day -> recur_in_month

  every_nth_day_of_year : int -> recur_in_day -> recur_in_year
  
  entire_hour : recur_in_hour

  every_nth_hour : int -> recur_in_hour -> recur_in_day

  every_hour : recur_in_hour -> recur_in_day
  
  entire_minute : recur_in_minute

  every_nth_minute : int -> recur_in_minute -> recur_in_hour

  every_minute : recur_in_minute -> recur_in_hour

  every_nth_second : int -> recur_in_minute

  every_second : recur_in_minute
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment