On this page:
9.0
top
up

8Generic Time OperationsπŸ”— i

An interface, implemented by time , datetime , and moment , that supplies generic operations on times.

procedure

( time-provider? x)boolean

x:any/c
Returns #t if x implements gen:time-provider ; #f otherwise.

procedure

( ->time t)time?

Returns the local time corresponding to t.

Examples:
> (->time (time 124510))

#<time 12:45:10>

> (->time (datetime 1969721256))

#<time 02:56:00>

> (->time (moment 2015381#:tz"America/New_York"))

#<time 01:00:00>

procedure

( ->hours t)(integer-in 023)

Returns the hour of the day from t.

Examples:
> (->hours (time 124510))

12

> (->hours (datetime 1969721256))

2

> (->hours (moment 2015381#:tz"America/New_York"))

1

procedure

( ->minutes t)(integer-in 059)

Returns the minute of the hour from t.

Examples:
> (->minutes (time 124510))

45

> (->minutes (datetime 1969721256))

56

> (->minutes (moment 2015381#:tz"America/New_York"))

0

procedure

( ->seconds t[fractional?])

(if fractional?
(and/c rational? (>=/c 0)(</c 60))
(integer-in 059))
fractional?:boolean? =#f
Returns the seconds from t. If fractional? is #t, then the fraction of the second will be included; otherwise, the result is an integer.

Examples:
> (->seconds (time 124510123456789))

10

> (->seconds (datetime 196972125630123456789)#t)

30123456789/1000000000

> (->seconds (moment 201538100999999999#:tz"America/New_York")#t)

999999999/1000000000

procedure

( ->milliseconds t)exact-integer?

Returns the milliseconds from t.

Examples:
> (->milliseconds (time 124510123456789))

123

> (->milliseconds (datetime 196972125630123456789))

123

> (->milliseconds (moment 201538100999999999#:tz"America/New_York"))

999

procedure

( ->microseconds t)exact-integer?

Returns the microseconds from t.

Examples:
> (->microseconds (time 124510123456789))

123456

> (->microseconds (datetime 196972125630123456789))

123456

> (->microseconds (moment 201538100999999999#:tz"America/New_York"))

999999

procedure

( ->nanoseconds t)exact-integer?

Returns the nanoseconds from t.

Examples:
> (->nanoseconds (time 124510123456789))

123456789

> (->nanoseconds (datetime 196972125630123456789))

123456789

> (->nanoseconds (moment 201538100999999999#:tz"America/New_York"))

999999999

procedure

( on-date td[#:resolve-offsetresolve])datetime-provider?

Combines the time fields of t with the date fields of d to produce a datetime provider. Any time zone information from t will be preserved in the result.

Examples:
> (on-date (time 0)(date 1970))

#<datetime 1970εΉ΄01月01ζ—₯T00:00:00>

> (on-date (datetime 1234567)(datetime 20201220))

#<datetime 2020εΉ΄12月20ζ—₯T04:05:06.000000007>

> (on-date (moment 2000112#:tz"America/New_York")
(date 201538)
#:resolve-offsetresolve-offset/post )

#<moment 2015εΉ΄03月08ζ—₯T03:00:00-04:00[America/New_York]>

top
up

AltStyle γ«γ‚ˆγ£γ¦ε€‰ζ›γ•γ‚ŒγŸγƒšγƒΌγ‚Έ (->γ‚ͺγƒͺγ‚ΈγƒŠγƒ«) /