Class: Temporal::ZonedDateTime
- Inherits:
-
Object
- Object
- Temporal::ZonedDateTime
- Defined in:
- lib/temporal/zoned_date_time.rb
Constant Summary collapse
- MAX_TIMESTAMP =
864 * (10**19)
- MIN_TIMESTAMP =
-MAX_TIMESTAMP
Instance Attribute Summary collapse
-
#calendar_id ⇒ Object
readonly
Returns the value of attribute calendar_id.
Instance Method Summary collapse
- #day ⇒ Object
- #day_of_week ⇒ Object
- #day_of_year ⇒ Object
- #days_in_month ⇒ Object
- #days_in_week ⇒ Object
- #days_in_year ⇒ Object
- #epoch_milliseconds ⇒ Object
- #epoch_nanoseconds ⇒ Object
- #era ⇒ Object
- #era_year ⇒ Object
- #hour ⇒ Object
-
#initialize(timestamp, tz: "UTC", calendar_id: nil) ⇒ ZonedDateTime
constructor
A new instance of ZonedDateTime.
- #leap_year? ⇒ Boolean
- #microsecond ⇒ Object
- #millisecond ⇒ Object
- #minute ⇒ Object
- #month ⇒ Object
- #month_code ⇒ Object
- #months_in_year ⇒ Object
- #nanosecond ⇒ Object
- #offset ⇒ Object
- #offset_nanoseconds ⇒ Object
- #second ⇒ Object
- #time_zone_id ⇒ Object
- #to_s ⇒ Object
- #week_of_year ⇒ Object
- #year ⇒ Object
Constructor Details
#initialize(timestamp, tz: "UTC", calendar_id: nil) ⇒ ZonedDateTime
Returns a new instance of ZonedDateTime.
12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/temporal/zoned_date_time.rb', line 12 def initialize(, tz: "UTC", calendar_id: nil) raise RangeError, "Timestamp underflow" if < MIN_TIMESTAMP raise RangeError, "Timestamp overflow" if > MAX_TIMESTAMP self.timezone = tz self.calendar_id = calendar_id seconds, nanosecond = .divmod(1_000_000_000) @time = Time.at(seconds, nanosecond, :nanosecond, in: tz) = end |
Instance Attribute Details
#calendar_id ⇒ Object
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
#day ⇒ Object
27 |
# File 'lib/temporal/zoned_date_time.rb', line 27 def day = @time.day |
#day_of_week ⇒ Object
42 |
# File 'lib/temporal/zoned_date_time.rb', line 42 def day_of_week = @time.wday |
#day_of_year ⇒ Object
43 |
# File 'lib/temporal/zoned_date_time.rb', line 43 def day_of_year = @time.yday |
#days_in_month ⇒ Object
46 |
# File 'lib/temporal/zoned_date_time.rb', line 46 def days_in_month = 30 |
#days_in_week ⇒ Object
45 |
# File 'lib/temporal/zoned_date_time.rb', line 45 def days_in_week = 7 |
#days_in_year ⇒ Object
47 |
# File 'lib/temporal/zoned_date_time.rb', line 47 def days_in_year = 366 |
#epoch_milliseconds ⇒ Object
39 |
# File 'lib/temporal/zoned_date_time.rb', line 39 def epoch_milliseconds = (@time.to_f * 1_000).to_i |
#epoch_nanoseconds ⇒ Object
40 |
# File 'lib/temporal/zoned_date_time.rb', line 40 def epoch_nanoseconds = |
#era ⇒ Object
28 |
# File 'lib/temporal/zoned_date_time.rb', line 28 def era = @time.era |
#era_year ⇒ Object
29 |
# File 'lib/temporal/zoned_date_time.rb', line 29 def era_year = @time.era_year |
#hour ⇒ Object
32 |
# File 'lib/temporal/zoned_date_time.rb', line 32 def hour = @time.hour |
#leap_year? ⇒ Boolean
49 |
# File 'lib/temporal/zoned_date_time.rb', line 49 def leap_year? = true |
#microsecond ⇒ Object
36 |
# File 'lib/temporal/zoned_date_time.rb', line 36 def microsecond = @time.usec % 1_000 |
#millisecond ⇒ Object
35 |
# File 'lib/temporal/zoned_date_time.rb', line 35 def millisecond = (@time.subsec.to_f * 1_000).to_i |
#minute ⇒ Object
33 |
# File 'lib/temporal/zoned_date_time.rb', line 33 def minute = @time.min |
#month ⇒ Object
26 |
# File 'lib/temporal/zoned_date_time.rb', line 26 def month = @time.month |
#month_code ⇒ Object
30 |
# File 'lib/temporal/zoned_date_time.rb', line 30 def month_code = :"#{format("M%02d", @time.month)}" |
#months_in_year ⇒ Object
48 |
# File 'lib/temporal/zoned_date_time.rb', line 48 def months_in_year = 12 |
#nanosecond ⇒ Object
37 |
# File 'lib/temporal/zoned_date_time.rb', line 37 def nanosecond = @time.nsec % 1_000 |
#offset ⇒ Object
50 |
# File 'lib/temporal/zoned_date_time.rb', line 50 def offset = "+00:00" |
#offset_nanoseconds ⇒ Object
51 |
# File 'lib/temporal/zoned_date_time.rb', line 51 def offset_nanoseconds = 0 |
#second ⇒ Object
34 |
# File 'lib/temporal/zoned_date_time.rb', line 34 def second = @time.sec |
#time_zone_id ⇒ Object
53 |
# File 'lib/temporal/zoned_date_time.rb', line 53 def time_zone_id = @timezone.upcase |
#to_s ⇒ Object
55 |
# File 'lib/temporal/zoned_date_time.rb', line 55 def to_s = "#{@time.inspect[..-5]}+00:00[UTC]".tr(" ", "T") |
#week_of_year ⇒ Object
44 |
# File 'lib/temporal/zoned_date_time.rb', line 44 def week_of_year = (@time.yday / 7) + 1 |
#year ⇒ Object
25 |
# File 'lib/temporal/zoned_date_time.rb', line 25 def year = @time.year |