silk.time.offset.
Fixed offsets from UTC: the UtcOffset type.
When to use#
Use UtcOffset for the +01:00 part of a timestamp: how far a local clock is ahead of or
behind UTC at one moment. It is not a time zone. A zone such as Europe/Rome has different
offsets in summer and in winter.
Details#
An offset is a whole number of seconds east of UTC, less than 24 hours in each direction.
Local time is UTC plus the offset, so 17:00 at +01:00 is 16:00 UTC.
Examples#
Parse an offset and read it#
import silk.core.result { Result }
import silk.time.offset { UtcOffset }
import silk.time.text { TimeParseError }
pub fn main() -> i32 {
match UtcOffset.parse("-03:30") {
Result<UtcOffset, TimeParseError>.Success { value } => {
if value.totalSeconds() != -12600 {
return 1
}
return 0
}
Result<UtcOffset, TimeParseError>.Failure { error: _ } => {
return 2
}
}
}Import as UtcOffset with import silk.time.offset { UtcOffset }.
Public declarations: 1.
UtcOffset#
pub struct UtcOffsetA fixed offset from UTC in whole seconds, less than 24 hours in each direction.
Details#
The offset is positive east of UTC: local time is UTC plus the offset. ==, !=, <, <=,
>, and >= compare the number of seconds. Display writes +HH:MM, or +HH:MM:SS when the
offset has a seconds part.
Implementation Copy for UtcOffset#
impl Copy for UtcOffsetImplementation UtcOffset#
impl UtcOffsetAssociated function utc#
pub fn utc() -> UtcOffsetReturns the zero offset, which is UTC.
Associated function fromSeconds#
pub fn fromSeconds(seconds: i32) -> UtcOffsetReturns the offset of seconds seconds east of UTC, or west for a negative count.
Gotchas#
An offset of 24 hours or more traps. UtcOffset.checkedFromSeconds returns None instead.
Associated function checkedFromSeconds#
pub fn checkedFromSeconds(seconds: i32) -> Option<UtcOffset>Returns the offset of seconds seconds east of UTC, or west for a negative count, or None
when it is 24 hours or more in either direction.
Associated function fromMinutes#
pub fn fromMinutes(minutes: i32) -> UtcOffsetReturns the offset of minutes minutes east of UTC, or west for a negative count.
Gotchas#
An offset of 24 hours or more traps.
Method totalSeconds#
pub fn totalSeconds(self: Self) -> i32Returns the offset in seconds east of UTC. It is negative west of UTC.
Method isUtc#
pub fn isUtc(self: Self) -> boolReturns true if the offset is zero.
Method toDuration#
pub fn toDuration(self: Self) -> DurationReturns the offset as a span: positive east of UTC.
Associated function parse#
pub fn parse(text: string) -> Result<UtcOffset, TimeParseError>Reads an offset from text such as +01:00, -0330, or Z.
Details#
The text is Z or z for UTC, or a sign and HH, HH:MM, HHMM, HH:MM:SS, or HHMMSS.
Errors#
TimeParseReason.UnexpectedEndorUnexpectedCharacterif the text does not have that form.TimeParseReason.OutOfRangeif the hour is above 23 or the minute or second is above 59.
Implementation Equal for UtcOffset#
impl Equal for UtcOffsetOperation equals#
equals: UtcOffset.sameImplementation Order for UtcOffset#
impl Order for UtcOffsetOperation compare#
compare: UtcOffset.compareImplementation Display for UtcOffset#
impl Display for UtcOffsetWrites the offset as +HH:MM, or +HH:MM:SS when it has a seconds part, with - west of UTC.
The zero offset is +00:00.
Operation display#
effect fn display(self: &Self, formatter: &mut Formatter) -> ()
! WriterError
? &mut WriterImplementation Debug for UtcOffset#
impl Debug for UtcOffsetWrites the same text as Display: the offset as +HH:MM or +HH:MM:SS.
Operation debug#
effect fn debug(self: &Self, formatter: &mut Formatter) -> ()
! WriterError
? &mut WriterCategory: 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.