Class: Temporal::PlainMonthDay

Inherits:
Object
  • Object
show all
Defined in:
lib/temporal/plain_month_day.rb

Constant Summary collapse

IMPLICIT_YEAR =
1972

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(month, day, year: nil, calendar_id: nil) ⇒ PlainMonthDay

Returns a new instance of PlainMonthDay.



9
10
11
12
13
14
15
# File 'lib/temporal/plain_month_day.rb', line 9

def initialize(month, day, year: nil, calendar_id: nil)
  @year = (Units::Year.new(year) if 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_idObject

Returns the value of attribute calendar_id.



5
6
7
# File 'lib/temporal/plain_month_day.rb', line 5

def calendar_id
  @calendar_id
end

#dayObject (readonly)

Returns the value of attribute day.



5
6
7
# File 'lib/temporal/plain_month_day.rb', line 5

def day
  @day
end

#monthObject (readonly)

Returns the value of attribute month.



5
6
7
# File 'lib/temporal/plain_month_day.rb', line 5

def month
  @month
end

Instance Method Details

#eraObject



23
# File 'lib/temporal/plain_month_day.rb', line 23

def era = nil

#month_codeObject



21
# File 'lib/temporal/plain_month_day.rb', line 21

def month_code = :"#{format("M%02d", month)}"

#to_s(calendar_name: nil) ⇒ Object



25
26
27
28
29
30
31
32
33
# File 'lib/temporal/plain_month_day.rb', line 25

def to_s(calendar_name: nil)
  if calendar_name == :always
    "#{year}-#{@month}-#{@day}[u-ca=#{calendar_id}]"
  elsif year
    "#{year}-#{@month}-#{@day}"
  else
    "#{@month}-#{@day}"
  end
end

#yearObject



17
18
19
# File 'lib/temporal/plain_month_day.rb', line 17

def year
  @year || IMPLICIT_YEAR
end