silk.time.now.
The present moment as each silk.time type: Now reads the SystemClock effect and, for
local values, a Zone.
When to use#
Use it where code needs today's date or the time now. Each function shows in its signature
what it reads: the clock, and for the zone of the machine also LocalZone and TimeZones.
A test provides a fixed clock and FixedLocalZone, and the result is the same on every
machine.
Details#
There is no local time without a zone. Load the zone one time with Now.localZone or
TimeZones.zone, keep it, and pass it to Now.zonedIn, Now.dateIn, or
Now.dateTimeIn.
Examples#
Today's date in a zone#
import silk.core.effect { Effect }
import silk.system.system_clock { SystemClock }
import silk.system.system_clock_native { OsSystemClock }
import silk.time.now { Now }
import silk.time.offset { UtcOffset }
import silk.time.zone { Zone }
pub fn main() -> i32 {
let mut clock = OsSystemClock.make()
let tokyo = Zone.fixed(UtcOffset.fromMinutes(540))
let today = run Now.dateIn(&tokyo) |> Effect.provideMut<SystemClock>(&mut clock)
if today.year() < 2026 {
return 1
}
return 0
}Import as Now with import silk.time.now { Now }.
Public declarations: 1.
Now#
pub struct NowThe owner type of the functions that read the present moment. It has no fields and is never constructed.
Implementation Now#
impl NowAssociated function instant#
pub effect fn instant() -> Instant ? &mut SystemClockReturns the present instant of the SystemClock.
Associated function localZone#
pub effect fn localZone() -> Zone
! NoLocalZoneError | ZoneLookupError | OutOfMemoryError
? &mut LocalZone | &mut TimeZones | &mut AllocatorReturns the zone that the machine is set to: the name from LocalZone, and its rules from
TimeZones.
Errors#
NoLocalZoneErrorif the machine does not say which zone it is in.ZoneLookupErrorif theTimeZonesprovider does not have that zone.OutOfMemoryErrorif theAllocatorcannot supply the zone.
Associated function zonedIn#
pub effect fn zonedIn<'z>(zone: &'z Zone) -> ZonedDateTime<'z> ? &mut SystemClockReturns the present instant as seen in zone.
Associated function dateIn#
pub effect fn dateIn(zone: &Zone) -> PlainDate ? &mut SystemClockReturns the date that a calendar in zone shows now.
Associated function dateTimeIn#
pub effect fn dateTimeIn(zone: &Zone) -> PlainDateTime ? &mut SystemClockReturns the date and time that a clock in zone shows now.
Category: Time.
Profiles: aarch64-apple-darwin, aarch64-unknown-linux-gnu, aarch64-unknown-linux-gnu-no-libc, x86_64-unknown-linux-gnu, x86_64-unknown-linux-gnu-no-libc, wasm32-unknown-unknown, wasm32-wasip1, wasm32-wasip2, x86_64-pc-windows-msvc, wasm64-unknown-unknown.