tempo/offset
Functions to use with the Offset
type in Tempo. The offset values
represents the time difference between the current time and UTC time.
Example
import tempo/offset
pub fn get_system_offset() {
offset.local()
|> offset.to_string
// -> "+05:00"
}
Functions
pub fn from_string(
offset: String,
) -> Result(Offset, OffsetParseError)
Tries to create a new offset from a string. Accepted formats are
(+-)hh:mm
, (+-)hhmm
, (+-)hh
, and (+-)h
.
Example
offset.from_string("-04")
|> result.map(offset.to_string)
// -> Ok("-04:00")
pub fn literal(offset: String) -> Offset
Creates a new offset from a string literal, but will panic if the string
is invalid. Accepted formats are (+-)hh:mm
, (+-)hhmm
, (+-)hh
, and
(+-)h
.
Useful for declaring offset literals that you know are valid within your program.
Example
offset.literal("-04:00")
|> offset.to_string
// -> "-04:00"
pub fn new(offset_minutes minutes: Int) -> Result(Offset, Nil)
Creates a new offset from a number of minutes.
Example
offset.new(-65)
|> result.map(offset.to_string)
// -> Ok("-01:05")
pub fn to_string(offset: Offset) -> String
Converts an offset to a string representation.
Will not return “Z” for a zero offset because it is probably not what the user wants without the context of a full datetime. Datetime modules building on this should cover formatting for Z themselves.
Example
offset.literal("-00")
|> offset.to_string
// -> "-00:00"