W3cubDocs

/Crystal 0.31

struct Time::Location::Zone

Overview

A Zone represents a time zone offset in effect in a specific Location.

Some zones have a #name or abbreviation (such as PDT, CEST). For an unnamed zone the formatted offset should be used as name.

Defined in:

time/location.cr

Constant Summary

UTC = new("UTC", 0, false)

This is the UTC time zone with offset +00:00.

It is the only zone offset used in Time::Location::UTC.

Constructors

Instance Method Summary

Constructor Detail

def self.new(name : String?, offset : Int32, dst : Bool)Source

Creates a new Zone named name with offset from UTC in seconds. The parameter dst is used to declare this zone as daylight savings time.

If #name is nil, the formatted #offset will be used as #name (see #format).

Raises InvalidTimezoneOffsetError if seconds is outside the supported value range -86_400..86_400 seconds (-24:00 to +24:00).

Instance Method Detail

def dst? : BoolSource

Returns true if this zone offset is daylight savings time.

def format(io : IO, with_colon = true, with_seconds = :auto)Source

Prints #offset to io in the format +HH:mm:ss. When with_colon is false, the format is +HHmmss.

When with_seconds is false, seconds are omitted; when :auto, seconds are omitted if 0.

def format(with_colon = true, with_seconds = :auto)Source

Returns the #offset formatted as +HH:mm:ss. When with_colon is false, the format is +HHmmss.

When with_seconds is false, seconds are omitted; when :auto, seconds are omitted if 0.

def inspect(io : IO) : NilSource

Prints this Zone to io.

It contains the #name, hour-minute-second format (see #format), #offset in seconds and "DST" if #dst?, otherwise "STD".

def name : StringSource

Returns the name of the zone.

def offset : Int32Source

Returns the offset from UTC in seconds.

© 2012–2019 Manas Technology Solutions.
Licensed under the Apache License, Version 2.0.
https://crystal-lang.org/api/0.31.1/Time/Location/Zone.html