Class: Temporal::PlainYearMonth

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

Constant Summary collapse

IMPLICIT_DAY =
1

Instance Attribute Summary collapse

Instance Method Summary collapse

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_idObject

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

#monthObject (readonly)

Returns the value of attribute month.



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

def month
  @month
end

#yearObject (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

#dayObject



20
# File 'lib/temporal/plain_year_month.rb', line 20

def day = @day || IMPLICIT_DAY

#eraObject



24
# File 'lib/temporal/plain_year_month.rb', line 24

def era = nil

#era_yearObject



26
# File 'lib/temporal/plain_year_month.rb', line 26

def era_year = nil

#month_codeObject



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