package core_unix
Install
Dune Dependency
Authors
Maintainers
Sources
md5=f9a74834f239874286d84ec99d75e5fa
sha512=d020db759cde35c0e9d9919dee2c0ea5bb5b7a5ee75515be922d816f28eb9f74dba37e6e424a636e362eab5120b2c1e672f4e5ba798f2dac7974c0e135f80faf
doc/core_unix.date_unix/Date_unix/index.html
Module Date_unix
Source
include module type of struct include Core.Date end
include module type of Core_kernel.Date with type t := t
include Bin_prot.Binable.S with type t := t
val bin_size_t : t Bin_prot.Size.sizer
val bin_write_t : t Bin_prot.Write.writer
val bin_read_t : t Bin_prot.Read.reader
val __bin_read_t__ : (int -> t) Bin_prot.Read.reader
val bin_writer_t : t Bin_prot.Type_class.writer
val bin_reader_t : t Bin_prot.Type_class.reader
val bin_t : t Bin_prot.Type_class.t
val hash_fold_t :
Ppx_hash_lib.Std.Hash.state ->
t ->
Ppx_hash_lib.Std.Hash.state
val hash : t -> Ppx_hash_lib.Std.Hash.hash_value
val hashable : t Base.Hashable.t
module Table = Core.Date.Table
module Hash_set = Core.Date.Hash_set
module Hash_queue = Core.Date.Hash_queue
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 Base.Comparable.S with type t := t
compare t1 t2
returns 0 if t1
is equal to t2
, a negative integer if t1
is less than t2
, and a positive integer if t1
is greater than t2
.
ascending
is identical to compare
. descending x y = ascending y x
. These are intended to be mnemonic when used like List.sort ~compare:ascending
and List.sort ~cmp:descending
, since they cause the list to be sorted in ascending or descending order, respectively.
clamp_exn t ~min ~max
returns t'
, the closest value to t
such that between t' ~low:min ~high:max
is true.
Raises if not (min <= max)
.
type comparator_witness = Core.Date.comparator_witness
module Replace_polymorphic_compare = Core.Date.Replace_polymorphic_compare
val comparator : (t, comparator_witness) Base__.Comparator.comparator
module Map = Core.Date.Map
module Set = Core.Date.Set
include Base.Pretty_printer.S with type t := t
val pp : Base__.Formatter.t -> t -> unit
val create_exn :
y:Core_kernel__.Import.int ->
m:Core_kernel__.Month.t ->
d:Core_kernel__.Import.int ->
t
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 :
Core_kernel__.Import.string ->
pos:Core_kernel__.Import.int ->
t
For details on this ISO format, see:
http://www.wikipedia.org/wiki/iso8601
val to_string_iso8601_basic : t -> Core_kernel__.Import.string
YYYYMMDD
val to_string_american : t -> Core_kernel__.Import.string
MM/DD/YYYY
val day : t -> Core_kernel__.Import.int
val month : t -> Core_kernel__.Month.t
val year : t -> Core_kernel__.Import.int
val day_of_week : t -> Core_kernel__.Day_of_week.t
Only accurate after 1752-09
val week_number_and_year :
t ->
Core_kernel__.Import.int * Core_kernel__.Import.int
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 : t -> Core_kernel__.Import.int
See week_number_and_year
for the meaning of week number.
val is_weekend : t -> Core_kernel__.Import.bool
val is_weekday : t -> Core_kernel__.Import.bool
Monday through Friday are business days, unless they're a holiday.
add_days t n
adds n days to t
and returns the resulting date.
Inaccurate when crossing 1752-09.
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. *
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.
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.
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.
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.
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.
val add_business_days_rounding_backward :
t ->
is_holiday:(t -> Core_kernel__.Import.bool) ->
Core_kernel__.Import.int ->
t
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.
val add_business_days_rounding_forward :
t ->
is_holiday:(t -> Core_kernel__.Import.bool) ->
Core_kernel__.Import.int ->
t
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.
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
.
val add_business_days :
t ->
is_holiday:(t -> Core_kernel__.Import.bool) ->
Core_kernel__.Import.int ->
t
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
.
val add_business_days_rounding_in_direction_of_step :
t ->
is_holiday:(t -> Core_kernel__.Import.bool) ->
Core_kernel__.Import.int ->
t
add_days_skipping t ~skip n
adds n
days to t
, ignoring any date satisfying skip
, starting at the first date at or after t
that does not satisfy skip
. For example, 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
.
the following returns a closed interval (endpoints included)
first_strictly_after t ~on:day_of_week
returns the first occurrence of day_of_week
strictly after t
.
val days_in_month :
year:Core_kernel__.Import.int ->
month:Core_kernel__.Month.t ->
Core_kernel__.Import.int
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.
is_leap_year ~year
returns true if year
is considered a leap year
val unix_epoch : t
The starting date of the UNIX epoch: 1970-01-01
gen
generates dates between 1900-01-01 and 2100-01-01.
val quickcheck_generator : t Base_quickcheck.Generator.t
val quickcheck_observer : t Base_quickcheck.Observer.t
val quickcheck_shrinker : t Base_quickcheck.Shrinker.t
gen_incl d1 d2
generates dates in the range between d1
and d2
, inclusive, with the endpoints having higher weight than the rest. Raises if d1 > d2
.
gen_uniform_incl d1 d2
generates dates chosen uniformly in the range between d1
and d2
, inclusive. Raises if d1 > d2
.
module Days = Core.Date.Days
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 = Core.Date.Option
module Stable = Core.Date.Stable
module O = Core.Date.O
module Private = Core.Date.Private
val of_time :
Core_kernel__.Time_float.t ->
zone:Core_kernel__.Time_float.Zone.t ->
t
val today : zone:Core_kernel__.Time_float.Zone.t -> t
This formats a date using the format patterns available in strftime
.
This parses a date using the format patterns available in strptime
.