package forester
A tool for tending mathematical forests
Install
Dune Dependency
Authors
Maintainers
Sources
2.5.1.tar.gz
md5=b26b6f4e3d14b976c3d5018c97b81b94
sha512=f0c794ed4330485b5255639720ad7201488b77ef947b0736a847fa4f56f93d3f03a22fd2a3319bbe867bab827a4b5ae73b2426a1067911b29fe178d21dd99e73
doc/src/forester.prelude/Date.ml.html
Source file Date.ml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
type t = {yyyy : int; mm : int option; dd : int option} let year d = d.yyyy let month d = d.mm let day d = d.dd let now () = let t = Unix.localtime (Unix.time ()) in {yyyy = 1900 + t.tm_year; mm = Some (1 + t.tm_mon); dd = Some t.tm_mday} (* approximate, only for sorting *) let to_ptime (date : t) : Ptime.t = let dd = Option.value ~default:1 date.dd in let mm = Option.value ~default:1 date.mm in match Ptime.of_date (date.yyyy, mm, dd) with | None -> failwith "to_ptime" | Some t -> t let compare (d0 : t) (d1 : t) = Ptime.compare (to_ptime d0) (to_ptime d1) let parse_date str = match String.split_on_char '-' str with | yyyy :: rest -> let yyyy = int_of_string yyyy in begin match rest with | mm :: rest -> let mm = Some (int_of_string mm) in begin match rest with | [dd] -> let dd = Some (int_of_string dd) in {yyyy; mm; dd} | _ -> {yyyy; mm; dd = None} end | _ -> {yyyy; mm = None; dd = None} end | _ -> failwith @@ Format.sprintf "Invalid date string: %s" str let parse str = match String.split_on_char 'T' str with | [date] -> parse_date date | date :: _ -> parse_date date | _ -> failwith @@ Format.sprintf "Invalid date string: %s" str let pp fmt date = Format.fprintf fmt "%04d" date.yyyy; date.mm |> Option.iter @@ fun mm -> Format.fprintf fmt "-%02d" mm; date.dd |> Option.iter @@ fun dd -> Format.fprintf fmt "-%02d" dd let pp_month fmt i = Format.fprintf fmt "%s" @@ match i with | 1 -> "January" | 2 -> "February" | 3 -> "March" | 4 -> "April" | 5 -> "May" | 6 -> "June" | 7 -> "July" | 8 -> "August" | 9 -> "September" | 10 -> "October" | 11 -> "November" | 12 -> "December" | _ -> failwith @@ Format.sprintf "Invalid date: %i" i let pp_human fmt date = match date.mm with | None -> Format.fprintf fmt "%04d" date.yyyy | Some mm -> match date.dd with | None -> Format.fprintf fmt "%a %04d" pp_month mm date.yyyy | Some dd -> Format.fprintf fmt "%a %i, %04d" pp_month mm dd date.yyyy
sectionYPositions = computeSectionYPositions($el), 10)"
x-init="setTimeout(() => sectionYPositions = computeSectionYPositions($el), 10)"
>