Class: Temporal::PlainYearMonth
- Inherits:
-
Object
- Object
- Temporal::PlainYearMonth
- Defined in:
- lib/temporal/plain_year_month.rb
Constant Summary collapse
- IMPLICIT_DAY =
1
Instance Attribute Summary collapse
-
#calendar_id ⇒ Object
readonly
Returns the value of attribute calendar_id.
-
#month ⇒ Object
readonly
Returns the value of attribute month.
-
#year ⇒ Object
readonly
Returns the value of attribute year.
Instance Method Summary collapse
- #day ⇒ Object
- #era ⇒ Object
- #era_year ⇒ Object
-
#initialize(year, month, day: nil, calendar_id: nil) ⇒ PlainYearMonth
constructor
A new instance of PlainYearMonth.
- #month_code ⇒ Object
- #to_s(calendar_name: nil) ⇒ Object
Constructor Details
#initialize(year, month, day: nil, calendar_id: nil) ⇒ PlainYearMonth
Returns a new instance of PlainYearMonth.
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/temporal/plain_year_month.rb', line 9 def initialize(year, month, day: nil, calendar_id: nil) @year = Units::Year.new(year) @month = Units::Month.new(month, @year) self.calendar_id = calendar_id return unless day @day = Units::Day.new(day, @month) @month.lower = @day end |
Instance Attribute Details
#calendar_id ⇒ Object
Returns the value of attribute calendar_id.
5 6 7 |
# File 'lib/temporal/plain_year_month.rb', line 5 def calendar_id @calendar_id end |
#month ⇒ Object (readonly)
Returns the value of attribute month.
5 6 7 |
# File 'lib/temporal/plain_year_month.rb', line 5 def month @month end |
#year ⇒ Object (readonly)
Returns the value of attribute year.
5 6 7 |
# File 'lib/temporal/plain_year_month.rb', line 5 def year @year end |
Instance Method Details
#day ⇒ Object
20 |
# File 'lib/temporal/plain_year_month.rb', line 20 def day = @day || IMPLICIT_DAY |
#era ⇒ Object
24 |
# File 'lib/temporal/plain_year_month.rb', line 24 def era = nil |
#era_year ⇒ Object
26 |
# File 'lib/temporal/plain_year_month.rb', line 26 def era_year = nil |
#month_code ⇒ Object
22 |
# File 'lib/temporal/plain_year_month.rb', line 22 def month_code = :"#{format("M%02d", month)}" |
#to_s(calendar_name: nil) ⇒ Object
28 29 30 31 32 33 34 35 36 |
# File 'lib/temporal/plain_year_month.rb', line 28 def to_s(calendar_name: nil) if calendar_name == :always "%4d-%02d-%02d[u-ca=%s]" % [@year, @month, day, calendar_id] elsif day "%4d-%02d-%02d" % [@year, @month, day] else "%4d-%02d" % [@year, @month] end end |