1 Exception utilities
2 Number utilities
3 String utilities
4 Bytes utilities
5 Symbol utilities
6 List utilities
7 PLT 4x hash utilities
8 PLT 3x hash utilities
9 Contract utilities
10 File and path utilities
11 Parameter utilities
12 Syntax utilities
13 SRFI19 time utilities
14 Generators
15 Generators (short names)
16 Pipelines
17 Write-through cache
18 Yieldable procedures
19 Debugging tools
20 Profiling tools
21 Logging tools
On this page:
time-utc?
time-tai?
time-duration?
leap-year?
days-in-month
date-valid?
time-weekday?
time->date
time->ago-string
seconds->ago-string
current-year
current-time-zone-offset
Version: 3.99.0.23

 

13 SRFI19 time utilities

 (require (planet untyped/unlib/time))

Utility procedures for use with SRFI 19 times and dates.

(time-utc? item)  boolean?

  item : any

Predicate that recognises SRFI-19 times of the time-utc type.

(time-tai? item)  boolean?

  item : any

Predicate that recognises SRFI-19 times of the time-tai type.

(time-duration? item)  boolean?

  item : any

Predicate that recognises SRFI-19 times of the time-duration type.

(leap-year? year)  boolean?

  year : integer?

Returns #t if year is a leap year.

(days-in-month month [year])  integer?

  month : integer?

  year : integer? = 2001

Returns the number of days in month in year. month is numbered from 1 to 12. year defaults to a non-leap year if omitted.

Examples:

  > (days-in-month 2)

  28

  > (days-in-month 2 2000)

  29

(date-valid? date)  boolean?

  date : srfi:date?

Returns #t if date is a valid date (its hour, day, month and so on are all in the correct ranges).

(time-weekday? time)  boolean?

  time : (U time-tai? time-utc?)

Returns #t if time lies on a week day (that is, Monday to Friday).

(time->date time)  srfi:date?

  time : (U time-tai? time-utc?)

Converts time to a date.

(time->ago-string then [now])  string?

  then : (U time-tai time-utc)

  

now

 

:

 

(U time-tai time-utc)

 

 

 

=

 

(current-time (U time-tai time-utc))

Given the time of an event the past (and, optionally, another argument representing the current time), returns a textual description of the time passed since the event. Raises exn:fail:unlib if now is before then. See seconds->ago-string for examples.

(seconds->ago-string secs [now])  string?

  secs : integer?

  now : integer? = (current-seconds)

Like time->ago-string but then and now are integer values like those output by current-seconds.

Examples:

  > (seconds->ago-string (- (current-seconds) 45))

  "45 seconds ago"

  > (seconds->ago-string (- (current-seconds) (* 30 60)))

  "30 minutes ago"

  > (seconds->ago-string (- (current-seconds) (* 20 60 60)))

  "20 hours ago"

  > (seconds->ago-string (- (current-seconds) (* 25 60 60)))

  "yesterday"

  > (seconds->ago-string (- (current-seconds) (* 50 60 60)))

  "2 days ago"

(current-year)  integer?

Returns the current four digit year.

(current-time-zone-offset)  integer?

Returns the current local time-zone offset in seconds (taking into account DST when and where appropriate).