Class: Temporal::ZonedDateTime

Inherits:
Object
  • Object
show all
Defined in:
lib/temporal/zoned_date_time.rb

Constant Summary collapse

MAX_TIMESTAMP =
864 * (10**19)
MIN_TIMESTAMP =
-MAX_TIMESTAMP

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(timestamp, tz: "UTC", calendar_id: nil) ⇒ ZonedDateTime

Returns a new instance of ZonedDateTime.

Raises:

  • (RangeError)


12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/temporal/zoned_date_time.rb', line 12

def initialize(timestamp, tz: "UTC", calendar_id: nil)
  raise RangeError, "Timestamp underflow" if timestamp < MIN_TIMESTAMP
  raise RangeError, "Timestamp overflow"  if timestamp > MAX_TIMESTAMP

  self.timezone = tz
  self.calendar_id = calendar_id

  seconds, nanosecond = timestamp.divmod(1_000_000_000)

  @time = Time.at(seconds, nanosecond, :nanosecond, in: tz)
  @timestamp = timestamp
end

Instance Attribute Details

#calendar_idObject

Returns the value of attribute calendar_id.



10
11
12
# File 'lib/temporal/zoned_date_time.rb', line 10

def calendar_id
  @calendar_id
end

Instance Method Details

#dayObject



27
# File 'lib/temporal/zoned_date_time.rb', line 27

def day         = @time.day

#day_of_weekObject



42
# File 'lib/temporal/zoned_date_time.rb', line 42

def day_of_week = @time.wday

#day_of_yearObject



43
# File 'lib/temporal/zoned_date_time.rb', line 43

def day_of_year = @time.yday

#days_in_monthObject



46
# File 'lib/temporal/zoned_date_time.rb', line 46

def days_in_month = 30

#days_in_weekObject



45
# File 'lib/temporal/zoned_date_time.rb', line 45

def days_in_week = 7

#days_in_yearObject



47
# File 'lib/temporal/zoned_date_time.rb', line 47

def days_in_year = 366

#epoch_millisecondsObject



39
# File 'lib/temporal/zoned_date_time.rb', line 39

def epoch_milliseconds = (@time.to_f * 1_000).to_i

#epoch_nanosecondsObject



40
# File 'lib/temporal/zoned_date_time.rb', line 40

def epoch_nanoseconds = @timestamp

#eraObject



28
# File 'lib/temporal/zoned_date_time.rb', line 28

def era         = @time.era

#era_yearObject



29
# File 'lib/temporal/zoned_date_time.rb', line 29

def era_year    = @time.era_year

#hourObject



32
# File 'lib/temporal/zoned_date_time.rb', line 32

def hour        = @time.hour

#leap_year?Boolean

Returns:

  • (Boolean)


49
# File 'lib/temporal/zoned_date_time.rb', line 49

def leap_year? = true

#microsecondObject



36
# File 'lib/temporal/zoned_date_time.rb', line 36

def microsecond = @time.usec % 1_000

#millisecondObject



35
# File 'lib/temporal/zoned_date_time.rb', line 35

def millisecond = (@time.subsec.to_f * 1_000).to_i

#minuteObject



33
# File 'lib/temporal/zoned_date_time.rb', line 33

def minute      = @time.min

#monthObject



26
# File 'lib/temporal/zoned_date_time.rb', line 26

def month       = @time.month

#month_codeObject



30
# File 'lib/temporal/zoned_date_time.rb', line 30

def month_code = :"#{format("M%02d", @time.month)}"

#months_in_yearObject



48
# File 'lib/temporal/zoned_date_time.rb', line 48

def months_in_year = 12

#nanosecondObject



37
# File 'lib/temporal/zoned_date_time.rb', line 37

def nanosecond  = @time.nsec % 1_000

#offsetObject



50
# File 'lib/temporal/zoned_date_time.rb', line 50

def offset = "+00:00"

#offset_nanosecondsObject



51
# File 'lib/temporal/zoned_date_time.rb', line 51

def offset_nanoseconds = 0

#secondObject



34
# File 'lib/temporal/zoned_date_time.rb', line 34

def second      = @time.sec

#time_zone_idObject



53
# File 'lib/temporal/zoned_date_time.rb', line 53

def time_zone_id = @timezone.upcase

#to_sObject



55
# File 'lib/temporal/zoned_date_time.rb', line 55

def to_s = "#{@time.inspect[..-5]}+00:00[UTC]".tr(" ", "T")

#week_of_yearObject



44
# File 'lib/temporal/zoned_date_time.rb', line 44

def week_of_year = (@time.yday / 7) + 1

#yearObject



25
# File 'lib/temporal/zoned_date_time.rb', line 25

def year        = @time.year