Class: Cybertrain::ZonedTime
- Inherits:
-
Object
- Object
- Cybertrain::ZonedTime
- Defined in:
- cybertrain/zoned_time.rb
Overview
A UTC instant read in one zone: Time.utc(2026, 11, 11, 20).in_time_zone("Asia/Tokyo")
has day 12, hour 5 and zone “JST”.
Instance Method Summary collapse
-
#day ⇒ Integer
The day of the month.
-
#hour ⇒ Integer
The hour on the zone’s wall clock, 0 to 23.
-
#initialize(epoch, zone, usec = 0) ⇒ ZonedTime
constructor
A new instance of ZonedTime.
-
#min ⇒ Integer
The minute, 0 to 59.
-
#month ⇒ Integer
The month, 1 to 12.
-
#sec ⇒ Integer
The second, 0 to 59.
-
#to_date ⇒ Date
The civil date on the zone’s calendar.
-
#to_time ⇒ Time
The UTC instant, its microseconds included.
-
#utc_offset ⇒ Integer
Seconds east of UTC at this instant (
32400in Tokyo). -
#wday ⇒ Integer
The day of the week, 0 (Sunday) to 6.
-
#yday ⇒ Integer
The day of the year, 1 to 366.
-
#year ⇒ Integer
The year on the zone’s calendar.
-
#zone ⇒ String
The zone’s abbreviation at this instant (“JST”, “EDT”, “GMT”), as the builtin Time#zone answers it.
Constructor Details
#initialize(epoch, zone, usec = 0) ⇒ ZonedTime
Returns a new instance of ZonedTime.
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'cybertrain/zoned_time.rb', line 26 def initialize(epoch, zone, usec = 0) @zt_epoch = epoch.to_i @zt_usec = usec.to_i @zt_offset = zone.utc_offset_at(@zt_epoch) @zt_abbr = zone.abbreviation_at(@zt_epoch) wall = TimeZone.epoch_to_civil(@zt_epoch + @zt_offset) @zt_year = wall[0] @zt_month = wall[1] @zt_day = wall[2] @zt_hour = wall[3] @zt_min = wall[4] @zt_sec = wall[5] @zt_wday = wall[6] @zt_yday = TimeZone.days_from_civil(wall[0], wall[1], wall[2]) - TimeZone.days_from_civil(wall[0], 1, 1) + 1 end |
Instance Method Details
#day ⇒ Integer
Returns the day of the month.
52 |
# File 'cybertrain/zoned_time.rb', line 52 def day = @zt_day |
#hour ⇒ Integer
Returns the hour on the zone’s wall clock, 0 to 23.
56 |
# File 'cybertrain/zoned_time.rb', line 56 def hour = @zt_hour |
#min ⇒ Integer
Returns the minute, 0 to 59.
60 |
# File 'cybertrain/zoned_time.rb', line 60 def min = @zt_min |
#month ⇒ Integer
Returns the month, 1 to 12.
48 |
# File 'cybertrain/zoned_time.rb', line 48 def month = @zt_month |
#sec ⇒ Integer
Returns the second, 0 to 59.
64 |
# File 'cybertrain/zoned_time.rb', line 64 def sec = @zt_sec |
#to_date ⇒ Date
The civil date on the zone’s calendar.
92 |
# File 'cybertrain/zoned_time.rb', line 92 def to_date = Date.new(@zt_year, @zt_month, @zt_day) |
#to_time ⇒ Time
The UTC instant, its microseconds included.
87 |
# File 'cybertrain/zoned_time.rb', line 87 def to_time = Time.at(@zt_epoch, @zt_usec).utc |
#utc_offset ⇒ Integer
Returns seconds east of UTC at this instant (32400 in Tokyo).
76 |
# File 'cybertrain/zoned_time.rb', line 76 def utc_offset = @zt_offset |
#wday ⇒ Integer
Returns the day of the week, 0 (Sunday) to 6.
68 |
# File 'cybertrain/zoned_time.rb', line 68 def wday = @zt_wday |
#yday ⇒ Integer
Returns the day of the year, 1 to 366.
72 |
# File 'cybertrain/zoned_time.rb', line 72 def yday = @zt_yday |
#year ⇒ Integer
Returns the year on the zone’s calendar.
44 |
# File 'cybertrain/zoned_time.rb', line 44 def year = @zt_year |
#zone ⇒ String
The zone’s abbreviation at this instant (“JST”, “EDT”, “GMT”), as the builtin Time#zone answers it.
82 |
# File 'cybertrain/zoned_time.rb', line 82 def zone = @zt_abbr |