Class: PerfectTOML::LocalDate
- Inherits:
-
LocalDateTimeBase
- Object
- LocalDateTimeBase
- PerfectTOML::LocalDate
- Defined in:
- lib/perfect_toml.rb
Overview
Represents TOML’s Local Date
Instance Attribute Summary collapse
-
#day ⇒ Object
readonly
Returns the value of attribute day.
-
#month ⇒ Object
readonly
Returns the value of attribute month.
-
#year ⇒ Object
readonly
Returns the value of attribute year.
Instance Method Summary collapse
-
#initialize(year, month, day) ⇒ LocalDate
constructor
A new instance of LocalDate.
-
#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.
Methods inherited from LocalDateTimeBase
#<=>, #==, #inspect, #pretty_print, #to_inline_toml
Constructor Details
#initialize(year, month, day) ⇒ LocalDate
Returns a new instance of LocalDate.
104 105 106 107 108 |
# File 'lib/perfect_toml.rb', line 104 def initialize(year, month, day) @year = year.to_i @month = month.to_i @day = day.to_i end |
Instance Attribute Details
#day ⇒ Object (readonly)
Returns the value of attribute day.
110 111 112 |
# File 'lib/perfect_toml.rb', line 110 def day @day end |
#month ⇒ Object (readonly)
Returns the value of attribute month.
110 111 112 |
# File 'lib/perfect_toml.rb', line 110 def month @month end |
#year ⇒ Object (readonly)
Returns the value of attribute year.
110 111 112 |
# File 'lib/perfect_toml.rb', line 110 def year @year end |
Instance Method Details
#to_s ⇒ Object
Returns a string representation in RFC 3339 format
ld = PerfectTOML::LocalDate.new(1970, 1, 1)
ld.to_s #=> 1970-01-01
130 131 132 |
# File 'lib/perfect_toml.rb', line 130 def to_s "%04d-%02d-%02d" % [@year, @month, @day] end |
#to_time(zone = nil) ⇒ Object
Converts to a Time object with the local timezone. Its time will be 00:00:00.
ld = PerfectTOML::LocalDate.new(1970, 1, 1)
ld.to_time #=> 1970-01-01 00:00:00 +0900
You can specify timezone by passing an argument.
ld.to_time("UTC") #=> 1970-01-01 00:00:00 UTC
ld.to_time("+00:00") #=> 1970-01-01 00:00:00 +0000
122 123 124 |
# File 'lib/perfect_toml.rb', line 122 def to_time(zone = nil) Time.new(@year, @month, @day, 0, 0, 0, zone) end |