Class: Temporal::PlainDate
- Inherits:
-
Object
- Object
- Temporal::PlainDate
- Defined in:
- lib/temporal/plain_date.rb
Instance Attribute Summary collapse
-
#calendar_id ⇒ Object
readonly
Returns the value of attribute calendar_id.
-
#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
- #==(other) ⇒ Object
- #add(hash = {}, **kwargs) ⇒ Object
- #era ⇒ Object
- #era_year ⇒ Object
-
#initialize(year, month, day, calendar_id: nil) ⇒ PlainDate
constructor
A new instance of PlainDate.
- #month_code ⇒ Object
Constructor Details
#initialize(year, month, day, calendar_id: nil) ⇒ PlainDate
Returns a new instance of PlainDate.
7 8 9 10 11 12 13 |
# File 'lib/temporal/plain_date.rb', line 7 def initialize(year, month, day, calendar_id: nil) @year = Units::Year.new(year) @month = Units::Month.new(month, @year) @day = Units::Day.new(day, @month) @month.lower = @day self.calendar_id = calendar_id end |
Instance Attribute Details
#calendar_id ⇒ Object
Returns the value of attribute calendar_id.
5 6 7 |
# File 'lib/temporal/plain_date.rb', line 5 def calendar_id @calendar_id end |
#day ⇒ Object (readonly)
Returns the value of attribute day.
5 6 7 |
# File 'lib/temporal/plain_date.rb', line 5 def day @day end |
#month ⇒ Object (readonly)
Returns the value of attribute month.
5 6 7 |
# File 'lib/temporal/plain_date.rb', line 5 def month @month end |
#year ⇒ Object (readonly)
Returns the value of attribute year.
5 6 7 |
# File 'lib/temporal/plain_date.rb', line 5 def year @year end |
Instance Method Details
#==(other) ⇒ Object
45 46 47 48 49 |
# File 'lib/temporal/plain_date.rb', line 45 def ==(other) @year == other.year && @month == other.month && @day == other.day end |
#add(hash = {}, **kwargs) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/temporal/plain_date.rb', line 21 def add(hash = {}, **kwargs) raise ArgumentError unless hash.instance_of? Hash values = hash.merge kwargs raise ArgumentError if values.empty? unit_keys = i[years months weeks days hours minutes seconds milliseconds microseconds nanoseconds] units = values.slice(*unit_keys) raise ArgumentError, "No valid unit found" if units.empty? raise RangeError, "Can't mix positive and negative numbers" unless units.values.reject(&:zero?).all?(&:positive?) || units.values.reject(&:zero?).all?(&:negative?) @day += values[:days] || 0 @month += values[:months] || 0 @year += values[:years] || 0 self end |
#era ⇒ Object
19 |
# File 'lib/temporal/plain_date.rb', line 19 def era = nil |
#era_year ⇒ Object
17 |
# File 'lib/temporal/plain_date.rb', line 17 def era_year = nil |
#month_code ⇒ Object
15 |
# File 'lib/temporal/plain_date.rb', line 15 def month_code = :"#{format("M%02d", month)}" |