Class: PerfectTOML::LocalDateTime
- Inherits:
-
LocalDateTimeBase
- Object
- LocalDateTimeBase
- PerfectTOML::LocalDateTime
- Defined in:
- lib/perfect_toml.rb
Overview
Represents TOML's Local Date-Time
Instance Method Summary collapse
- #day ⇒ Object
- #hour ⇒ Object
-
#initialize(*args) ⇒ LocalDateTime
constructor
A new instance of LocalDateTime.
- #min ⇒ Object
- #month ⇒ Object
- #sec ⇒ Object
-
#to_s ⇒ Object
Returns a string representation in RFC 3339 format.
-
#to_time(zone = nil) ⇒ Object
Converts to a Time object with the local timezone.
- #year ⇒ Object
Methods inherited from LocalDateTimeBase
#<=>, #==, #inspect, #pretty_print, #to_inline_toml
Constructor Details
#initialize(*args) ⇒ LocalDateTime
Returns a new instance of LocalDateTime.
65 66 67 68 69 |
# File 'lib/perfect_toml.rb', line 65 def initialize(*args) @date = args[0].is_a?(LocalDate) ? args.shift : LocalDate.new(args.shift, args.shift, args.shift) @time = args[0].is_a?(LocalTime) ? args.shift : LocalTime.new(args.shift, args.shift, args.shift) raise ArgumentError, "wrong number of arguments" unless args.empty? end |
Instance Method Details
#day ⇒ Object
73 |
# File 'lib/perfect_toml.rb', line 73 def day = @date.day |
#hour ⇒ Object
74 |
# File 'lib/perfect_toml.rb', line 74 def hour = @time.hour |
#min ⇒ Object
75 |
# File 'lib/perfect_toml.rb', line 75 def min = @time.min |
#month ⇒ Object
72 |
# File 'lib/perfect_toml.rb', line 72 def month = @date.month |
#sec ⇒ Object
76 |
# File 'lib/perfect_toml.rb', line 76 def sec = @time.sec |
#to_s ⇒ Object
Returns a string representation in RFC 3339 format
ldt = PerfectTOML::LocalDateTime.new(1970, 1, 1, 2, 3, 4)
ldt.to_s #=> 1970-01-01T02:03:04
95 96 97 |
# File 'lib/perfect_toml.rb', line 95 def to_s "#{ @date }T#{ @time }" end |
#to_time(zone = nil) ⇒ Object
Converts to a Time object with the local timezone.
ldt = PerfectTOML::LocalDateTime.new(1970, 1, 1, 2, 3, 4)
ldt.to_time #=> 1970-01-01 02:03:04 +0900
You can specify timezone by passing an argument.
ldt.to_time("UTC") #=> 1970-01-01 02:03:04 UTC
ldt.to_time("+00:00") #=> 1970-01-01 02:03:04 +0000
87 88 89 |
# File 'lib/perfect_toml.rb', line 87 def to_time(zone = nil) Time.new(@date.year, @date.month, @date.day, @time.hour, @time.min, @time.sec, zone) end |
#year ⇒ Object
71 |
# File 'lib/perfect_toml.rb', line 71 def year = @date.year |