package sihl
The modular functional web framework
Install
Dune Dependency
Authors
Maintainers
Sources
sihl-0.1.1.tbz
sha256=eac58e5ee9c869aa3b0f0bcee936b01c53bf7fe1febb42edd607268dfb11f4e9
sha512=012b6cf1cf6af0966059761b4916ea8aa590aa8d5809a6f480cb17e23ee10c3b9245062c4f0cf9ad98ab950391c0827c9780999d39fa16a93f7aab4b12f9ab8c
doc/src/sihl.utils/utils_time.ml.html
Source file utils_time.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
open Base type duration = | OneSecond | OneMinute | TenMinutes | OneHour | OneDay | OneWeek | OneMonth | OneYear [@@deriving yojson, show, eq] let duration_to_span duration = let duration_s = match duration with | OneSecond -> 1. | OneMinute -> 60. | TenMinutes -> 60. *. 10. | OneHour -> 60. *. 60. | OneDay -> 60. *. 60. *. 24. | OneWeek -> 60. *. 60. *. 24. *. 7. | OneMonth -> 60. *. 60. *. 24. *. 30. | OneYear -> 60. *. 60. *. 24. *. 365. in Option.value_exn (Ptime.of_float_s duration_s) |> Ptime.to_span let ptime_to_yojson ptime = `String (Ptime.to_rfc3339 ptime) let ptime_of_yojson yojson = match yojson |> Yojson.Safe.to_string |> Ptime.of_rfc3339 |> Ptime.rfc3339_error_to_msg with | Ok (ptime, _, _) -> Ok ptime | Error (`Msg msg) -> Error msg let ptime_of_date_string date = let date = date |> String.split ~on:'-' |> List.map ~f:(fun str -> Option.try_with (fun () -> Int.of_string str)) |> List.map ~f: (Result.of_option ~error: "Invalid date string provided, make sure that year, month and \ date are ints") |> Result.all in match date with | Ok [ year; month; day ] -> Ptime.of_date (year, month, day) |> Result.of_option ~error:"Invalid date provided, only format 1990-12-01 is accepted" | Ok _ -> Error "Invalid date provided, only format 1990-12-01 is accepted" | Error msg -> Error msg let ptime_to_date_string ptime = let year, month, day = Ptime.to_date ptime in let month = if month < 10 then Printf.sprintf "0%d" month else Printf.sprintf "%d" month in let day = if day < 10 then Printf.sprintf "0%d" day else Printf.sprintf "%d" day in Printf.sprintf "%d-%s-%s" year month day
sectionYPositions = computeSectionYPositions($el), 10)"
x-init="setTimeout(() => sectionYPositions = computeSectionYPositions($el), 10)"
>