Class: Cybertrain::ZonedTime

Inherits:
Object
  • Object
show all
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

Constructor Details

#initialize(epoch, zone, usec = 0) ⇒ ZonedTime

Returns a new instance of ZonedTime.

Parameters:

  • epoch (Integer) —

    the UTC instant, epoch seconds

  • zone (TimeZone)
  • usec (Integer) (defaults to: 0) —

    the instant’s microseconds, kept by #to_time



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.

Returns:

  • (Integer) —

    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.

Returns:

  • (Integer) —

    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.

Returns:

  • (Integer) —

    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.

Returns:



48
# File 'cybertrain/zoned_time.rb', line 48

def month = @zt_month

#sec ⇒ Integer

Returns the second, 0 to 59.

Returns:

  • (Integer) —

    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.

Returns:



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.

Returns:



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).

Returns:

  • (Integer) —

    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.

Returns:

  • (Integer) —

    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.

Returns:

  • (Integer) —

    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.

Returns:

  • (Integer) —

    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.

Returns:

  • (String)


82
# File 'cybertrain/zoned_time.rb', line 82

def zone = @zt_abbr