jon.recoil.org

Module Core.DateSource

Date module.

type t
include Bin_prot.Binable.S__local with type t := Core.Date.t
val bin_size_t__local : Core.Date.t Bin_prot.Size.sizer__local
val bin_write_t__local : Core.Date.t Bin_prot.Write.writer__local

This function only needs implementation if t exposed to be a polymorphic variant. Despite what the type reads, this does *not* produce a function after reading; instead it takes the constructor tag (int) before reading and reads the rest of the variant t afterwards.

val bin_shape_t : Bin_prot.Shape.t
val globalize : Core.Date.t @ local -> Core.Date.t
include Sexplib0.Sexpable.S__stack with type t := Core.Date.t
val t_of_sexp : Sexplib0.Sexp.t -> Core.Date.t
val sexp_of_t__stack : Core.Date.t @ local -> Sexplib0.Sexp.t @ local
val sexp_of_t : Core.Date.t -> Sexplib0.Sexp.t
val t_sexp_grammar : Core.Date.t Sexplib0.Sexp_grammar.t @@ portable
include Typerep_lib.Typerepable.S with type t := Core.Date.t
val typerep_of_t : Core.Date.t Typerep_lib.Std_internal.Typerep.t @@ portable
val typename_of_t : Core.Date.t Typerep_lib.Typename.t @@ portable

converts a string to a date in the following formats:

  • m/d/y
  • y-m-d (valid iso8601_extended)
  • DD MMM YYYY
  • DDMMMYYYY
  • YYYYMMDD
include Core.Interfaces.Stringable with type t := Core.Date.t
val of_string : string -> Core.Date.t
include Core.Comparable.S_binable__local__portable with type t := Core.Date.t
val (>=) : Core.Date.t -> Core.Date.t -> bool @@ portable
val (<=) : Core.Date.t -> Core.Date.t -> bool @@ portable
val (=) : Core.Date.t -> Core.Date.t -> bool @@ portable
val (>) : Core.Date.t -> Core.Date.t -> bool @@ portable
val (<) : Core.Date.t -> Core.Date.t -> bool @@ portable
val (<>) : Core.Date.t -> Core.Date.t -> bool @@ portable
val equal : Core.Date.t -> Core.Date.t -> bool @@ portable
val compare : Core.Date.t -> Core.Date.t -> int @@ portable
val equal__local : Core.Date.t @ local -> Core.Date.t @ local -> bool @@ portable
val compare__local : Core.Date.t @ local -> Core.Date.t @ local -> int @@ portable
val min : Core.Date.t -> Core.Date.t -> Core.Date.t @@ portable
val max : Core.Date.t -> Core.Date.t -> Core.Date.t @@ portable
val ascending : Core.Date.t -> Core.Date.t -> int @@ portable
val descending : Core.Date.t -> Core.Date.t -> int @@ portable
val between : Core.Date.t -> low:Core.Date.t -> high:Core.Date.t -> bool @@ portable
val clamp_exn : Core.Date.t -> min:Core.Date.t -> max:Core.Date.t -> Core.Date.t @@ portable
val clamp : Core.Date.t -> min:Core.Date.t -> max:Core.Date.t -> Core.Date.t Base.Or_error.t @@ portable
type comparator_witness
module Replace_polymorphic_compare : sig ... end
module Map : sig ... end
module Set : sig ... end
include Diffable.S_atomic with type t := Core.Date.t
module Diff : sig ... end
include Base.Pretty_printer.S with type t := Core.Date.t
val pp : Base.Formatter.t -> Core.Date.t -> unit
val create_exn : y:Base.Int.t -> m:Core.Month.t -> d:Base.Int.t -> Core.Date.t @@ portable

create_exn ~y ~m ~d creates the date specified in the arguments. Arguments are validated, and are not normalized in any way. So, days must be within the limits for the month in question, numbers cannot be negative, years must be fully specified, etc.

val of_string_iso8601_basic : Base.String.t -> pos:Base.Int.t -> Core.Date.t @@ portable

For details on this ISO format, see:

http://www.wikipedia.org/wiki/iso8601

val to_string_iso8601_extended : Core.Date.t -> Base.String.t

YYYY-MM-DD

val to_string_iso8601_basic : Core.Date.t -> Base.String.t

YYYYMMDD

val to_string_american : Core.Date.t -> Base.String.t

MM/DD/YYYY

val to_string : Core.Date.t -> Base.String.t
val day : Core.Date.t -> Base.Int.t @@ portable
val month : Core.Date.t -> Core.Month.t @@ portable
val year : Core.Date.t -> Base.Int.t @@ portable
val day_of_week : Core.Date.t -> Core.Day_of_week.t @@ portable

Only accurate after 1752-09

val week_number_and_year : Core.Date.t -> Base.Int.t * Base.Int.t @@ portable

Week of the year, from 1 to 53, along with the week-numbering year to which the week belongs. The week-numbering year may not correspond to the calendar year in which the provided date occurs.

According to ISO 8601, weeks start on Monday, and the first week of a year is the week that contains the first Thursday of the year. This means that dates near the end of the calendar year can have week number 1 and belong to the following week-numbering year, and dates near the beginning of the calendar year can have week number 52 or 53 and belong to the previous week-numbering year.

The triple (week-numbering year, week number, week day) uniquely identifies a particular date, which is not true if the calendar year is used instead.

val week_number : Core.Date.t -> Base.Int.t @@ portable

See week_number_and_year for the meaning of week number.

is_weekend and is_weekday treat Saturday and Sunday as the weekend, and Monday through Friday as weekdays.

Caveat: Not all cultures, countries, or businesses conform to this particular cycle of weekend / weekday.

val is_weekend : Core.Date.t -> Base.Bool.t @@ portable
val is_weekday : Core.Date.t -> Base.Bool.t @@ portable
val is_business_day : ?is_weekday:(Core.Day_of_week.t -> Base.Bool.t) -> Core.Date.t -> is_holiday:(Core.Date.t -> Base.Bool.t) -> Base.Bool.t @@ portable

Monday through Friday are business days, unless they're a holiday.

See the caveat on is_weekend about varying weekend/weekday cycles.

val add_days : Core.Date.t -> Base.Int.t -> Core.Date.t @@ portable

add_days t n adds n days to t and returns the resulting date.

Inaccurate when crossing 1752-09.

val add_months : Core.Date.t -> Base.Int.t -> Core.Date.t @@ portable

add_months t n returns date with max days for the month if the date would be invalid. e.g. adding 1 month to Jan 30 results in Feb 28 due to Feb 30 being an invalid date, Feb 29 is returned in cases of leap year.

In particular, this means adding x months and then adding y months isn't the same as adding x + y months, and in particular adding x months and then -x months won't always get you back where you were.

val add_years : Core.Date.t -> Base.Int.t -> Core.Date.t @@ portable

add_years t n has the same semantics as add_months for adding years to Feb 29 of a leap year, i.e., when the addition results in a date in a non-leap year, the result will be Feb 28 of that year.

val diff : Core.Date.t -> Core.Date.t -> Base.Int.t @@ portable

diff t1 t2 returns date t1 minus date t2 in days.

val diff_weekdays : Core.Date.t -> Core.Date.t -> Base.Int.t @@ portable

diff_weekdays t1 t2 returns the number of weekdays in the half-open interval [t2,t1) if t1 >= t2, and - diff_weekdays t2 t1 otherwise.

See the caveat on is_weekend about varying weekend/weekday cycles.

val diff_weekend_days : Core.Date.t -> Core.Date.t -> Base.Int.t @@ portable

diff_weekend_days t1 t2 returns the number of days that are weekend days in the half-open interval [t2,t1) if t1 >= t2, and - diff_weekend_days t2 t1 otherwise.

See the caveat on is_weekend about varying weekend/weekday cycles.

val add_weekdays_rounding_backward : Core.Date.t -> Base.Int.t -> Core.Date.t @@ portable

First rounds the given date backward to the previous weekday, if it is not already a weekday. Then advances by the given number of weekdays, which may be negative.

See the caveat on is_weekend about varying weekend/weekday cycles.

val add_weekdays_rounding_forward : Core.Date.t -> Base.Int.t -> Core.Date.t @@ portable

First rounds the given date forward to the next weekday, if it is not already a weekday. Then advances by the given number of weekdays, which may be negative.

See the caveat on is_weekend about varying weekend/weekday cycles.

val add_business_days_rounding_backward : Core.Date.t -> ?is_weekday:(Core.Day_of_week.t -> Base.Bool.t) -> is_holiday:(Core.Date.t -> Base.Bool.t) -> Base.Int.t -> Core.Date.t @@ portable

First rounds the given date backward to the previous business day, i.e. weekday not satisfying is_holiday, if it is not already a business day. Then advances by the given number of business days, which may be negative.

See the caveat on is_weekend about varying weekend/weekday cycles.

val add_business_days_rounding_forward : Core.Date.t -> ?is_weekday:(Core.Day_of_week.t -> Base.Bool.t) -> is_holiday:(Core.Date.t -> Base.Bool.t) -> Base.Int.t -> Core.Date.t @@ portable

First rounds the given date forward to the next business day, i.e. weekday not satisfying is_holiday, if it is not already a business day. Then advances by the given number of business days, which may be negative.

See the caveat on is_weekend about varying weekend/weekday cycles.

val add_weekdays : Core.Date.t -> Base.Int.t -> Core.Date.t @@ portable

add_weekdays t 0 returns the next weekday if t is a weekend and t otherwise. Unlike add_days this is done by looping over the count of days to be added (forward or backwards based on the sign), and is O(n) in the number of days to add. Beware, add_weekdays sat 1 or add_weekdays sun 1 both return the next tue, not the next mon. You may want to use following_weekday if you want the next following weekday, following_weekday (fri|sat|sun) would all return the next mon.

See the caveat on is_weekend about varying weekend/weekday cycles.

  • deprecated [since 2019-12] use [add_weekdays_rounding_backward] or [add_weekdays_rounding_forward] as appropriate
val add_weekdays_rounding_in_direction_of_step : Core.Date.t -> Base.Int.t -> Core.Date.t @@ portable
  • alert legacy use [add_weekdays_rounding_backward] or [add_weekdays_rounding_forward] as appropriate
val add_business_days : Core.Date.t -> ?is_weekday:(Core.Day_of_week.t -> Base.Bool.t) -> is_holiday:(Core.Date.t -> Base.Bool.t) -> Base.Int.t -> Core.Date.t @@ portable

add_business_days t ~is_holiday n returns a business day even when n=0. add_business_days ~is_holiday:(fun _ -> false) ... is the same as add_weekdays.

If you don't want to skip Saturday or Sunday, use add_days_skipping.

See the caveat on is_weekend about varying weekend/weekday cycles.

  • deprecated [since 2019-12] use [add_business_days_rounding_backward] or [add_business_days_rounding_forward] as appropriate
val add_business_days_rounding_in_direction_of_step : Core.Date.t -> ?is_weekday:(Core.Day_of_week.t -> Base.Bool.t) -> is_holiday:(Core.Date.t -> Base.Bool.t) -> Base.Int.t -> Core.Date.t @@ portable
  • alert legacy use [add_business_days_rounding_backward] or [add_business_days_rounding_forward] as appropriate
val add_days_skipping : Core.Date.t -> skip:(Core.Date.t -> Base.Bool.t) -> Base.Int.t -> Core.Date.t @@ portable

add_days_skipping t ~skip n adds n days to t, ignoring any date satisfying skip. If n >= 0, then we start from the first date at or after t that does not satisfy skip. If n < 0, then we start from the first date at or before t that does not satisfy skip.

In particular, if skip t = true, then add_days_skipping t ~skip 0 > t.

add_business_days and add_weekdays are special cases of add_days_skipping.

val dates_between : min:Core.Date.t -> max:Core.Date.t -> Core.Date.t Base.List.t @@ portable

the following returns a closed interval (endpoints included)

val business_dates_between : min:Core.Date.t -> max:Core.Date.t -> is_holiday:(Core.Date.t -> Base.Bool.t) -> Core.Date.t Base.List.t @@ portable

business_dates_between ~min ~max ~is_holiday returns the list of dates between min and max, inclusive, for which is_business_day ~is_holiday.

See the caveat on is_weekend about varying weekend/weekday cycles.

val business_dates_between_with_weekday_override : min:Core.Date.t -> max:Core.Date.t -> is_holiday:(Core.Date.t -> Base.Bool.t) -> is_weekday:(Core.Day_of_week.t -> Base.Bool.t) -> Core.Date.t Base.List.t @@ portable
val weekdays_between : min:Core.Date.t -> max:Core.Date.t -> Core.Date.t Base.List.t @@ portable

See the caveat on is_weekend about varying weekend/weekday cycles.

val previous_weekday : Core.Date.t -> Core.Date.t @@ portable
val following_weekday : Core.Date.t -> Core.Date.t @@ portable
val round_forward_to_weekday : Core.Date.t -> Core.Date.t @@ portable
val round_backward_to_weekday : Core.Date.t -> Core.Date.t @@ portable
val round_forward_to_business_day : ?is_weekday:(Core.Day_of_week.t -> Base.Bool.t) -> Core.Date.t -> is_holiday:(Core.Date.t -> Base.Bool.t) -> Core.Date.t @@ portable
val round_backward_to_business_day : ?is_weekday:(Core.Day_of_week.t -> Base.Bool.t) -> Core.Date.t -> is_holiday:(Core.Date.t -> Base.Bool.t) -> Core.Date.t @@ portable
val first_strictly_after : Core.Date.t -> on:Core.Day_of_week.t -> Core.Date.t @@ portable

first_strictly_after t ~on:day_of_week returns the first occurrence of day_of_week strictly after t.

val days_in_month : year:Base.Int.t -> month:Core.Month.t -> Base.Int.t @@ portable

days_in_month ~year ~month returns the number of days in month, using year only if month = Month.Feb to check if there is a leap year.

Incorrect for September 1752.

val last_date_in_month : year:Base.Int.t -> month:Core.Month.t -> Core.Date.t @@ portable

last_date_in_month ~year ~month returns the last date in month and year.

val all_dates_in_month : year:Base.Int.t -> month:Core.Month.t -> Core.Date.t Base.List.t @@ portable

all_dates_in_month ~year ~month returns all dates in month and year.

val is_leap_year : year:Base.Int.t -> Base.Bool.t @@ portable

is_leap_year ~year returns true if year is considered a leap year

val unix_epoch : Core.Date.t @@ portable

The starting date of the UNIX epoch: 1970-01-01

gen generates dates between 1900-01-01 and 2100-01-01.

include Core.Quickcheckable.S_range__portable with type t := Core.Date.t
val gen_incl : Core.Date.t -> Core.Date.t -> Core.Date.t Base_quickcheck.Generator.t @ portable @@ portable
val gen_uniform_incl : Core.Date.t -> Core.Date.t -> Core.Date.t Base_quickcheck.Generator.t @ portable @@ portable
module Days : sig ... end

Days provides a linear representation of dates that is optimized for arithmetic on the number of days between dates, rather than for representing year/month/day components. This module is intended for use only in performance-sensitive contexts where dates are manipulated more often than they are constructed or deconstructed; most clients should use the ordinary t.

module Option : sig ... end
module Stable : sig ... end
module O : sig ... end
module Private : sig ... end
Sourceval of_time : Core.Time_float.t -> zone:Core__.Zone.t -> Core.Date.t @@ portable
Sourceval today : zone:Core__.Zone.t -> Core.Date.t @@ portable

Deprecations

Sourceval format : [ `Use_Date_unix ] @@ portable
  • deprecated [since 2021-03] Use [Date_unix]
Sourceval of_tm : [ `Use_Date_unix ] @@ portable
  • deprecated [since 2021-03] Use [Date_unix]
Sourceval parse : [ `Use_Date_unix ] @@ portable
  • deprecated [since 2021-03] Use [Date_unix]