9 Time Utilities
(require "../time-utilities.rkt") | package: base |
procedure
(msec->date msec) → date?
msec : nonnegative-integer?
procedure
(time->formatted-date-string msec [ pattern offset]) → string? msec : nonnegative-integer? pattern : string? = "~Y-~m-~d" offset : nonnegative-integer? = 0
procedure
(time->formatted-time-string msec [ pattern offset]) → string? msec : nonnegative-integer? pattern : string? = "~H:~M" offset : nonnegative-integer? = 0
procedure
(time->formatted-datetime-string msec [ pattern]) → string? msec : nonnegative-integer? pattern : string? = "~Y-~m-~d ~H:~M"
procedure
(timestamp->time-string timestamp [ #:format time-format #:template template]) → string? timestamp : nonnegative-integer? time-format : symbol? = 'hour-min template : (or/c null? string?) = null
If template string is omitted (or null), then the time-format argument is used for formatting. ’hour-min ("HH:MM") is the default format if neither template nor time-format are specified.
'hour-min for HH:MM format
'decimal for hour as a decimal, with either 0 precision if an integer hour (eg "13") or 2 precision if between hours (eg. "13.25" for 13:15
If template string is provided then string is formatted using srfi/19 routine for time-utc.
procedure
(timestamp->date-string timestamp [ #:template template]) → string? timestamp : nonnegative-integer? template : string? = "~m/~d"
procedure
(YMD-string->timestamp date-string) → nonnegative-integer?
date-string : string?
procedure
(min-of-timestamps timestamps) → nonnegative-integer?
timestamps : list?
procedure
s : string?
"M/D/Y" (a single day)
"M/D1-D2/Y" (a range of days within a single month)
"M1/D1/Y1-M2/D2/Y2" (range of days beginning and ending in different months)
All 3 formats can be mixed in a single string for expansion. Spaces are removed from s before expansion
(date-range-expand "5/6/2018, 7/30/2018-8/2/2018, 9/2-5/2018") -> '("2018-05-06" "2018-07-30" "2018-07-31" "2018-08-01" "2018-08-02" "2018-09-02" "2018-09-03" "2018-09-04" "2018-09-05") (date-range-expand "2/27/2018-3/2/2018, 2/27/2020-3/2/2020") -> '("2018-02-27" "2018-02-28" "2018-03-01" "2018-03-02" "2020-02-27" "2020-02-28" "2020-02-29" "2020-03-01" "2020-03-02")
struct
(struct time-unit (name abbr size limit))
name : string? abbr : string? size : nonnegative-integer? limit : nonnegative-integer?
value
time-units : list?
Unit |
| Abbr |
| "Durations (ms)" |
millsecond |
| ms |
| 1 |
second |
| s |
| 1000 |
minute |
| min |
| 60000 |
hour |
| h |
| 3600000 |
day |
| d |
| 86400000 |
week |
| wk |
| 604800000 |
month |
| mo |
| 2592000000 |
year |
| y |
| 31557600000 |
decade |
| Dy |
| 315576000000 |
century |
| Cy |
| 3155760000000 |
millennium |
| Ky |
| 3155760000000000 |
procedure
(abbr->time-unit abbr) → struct?
abbr : (or/c symbol? string?)
procedure
(number->msec num unit-abbr) → nonnegative-integer?
num : number? unit-abbr : (or/c symbol? string?)
procedure
(msec->time-unit x) → struct?
x : nonnegative-integer?
(msec->time-unit 120000) -> (time-unit "minute"...) (msec->time-unit 3900000) -> (time-unit "hour"...)
procedure
(duration->unit-string x [ #:precision precision #:unit-in-msec scale #:unit user-abbr]) → string? x : number? precision : nonnegative-integer? = 2 scale : number? = 1 user-abbr : (or/c #f symbol? string?) = #f
(duration->unit-string 300000) -> "5.00 min" (duration->unit-string 4500000) -> "1.25 h" (duration->unit-string 4500000 #:unit 'min) -> "75 min" (duration->unit-string 4800000 #:precision:4) -> "1.3333 h"