module OpenEHR::AssumedLibraryTypes::ISO8601DateModule

Attributes

day[R]
month[R]
year[R]

Public Instance Methods

as_string() click to toggle source
# File lib/open_ehr/assumed_library_types.rb, line 214
def as_string
  if (!@year.nil? and !@month.nil? and !@day.nil?)
    Date.new(@year, @month, @day).to_s
  elsif (!@year.nil? and !@month.nil? and @day.nil?)
    Date.new(@year, @month).to_s[0,7]
  elsif (!@year.nil? and @month.nil? and @day.nil?)
    Date.new(@year).to_s[0,4]
  end          
end
day=(day) click to toggle source
# File lib/open_ehr/assumed_library_types.rb, line 208
def day=(day)
  
  raise ArgumentError, "Day is not valid" unless day.nil? or TimeDefinitions.valid_day?(@year, @month, day)
  @day = day
end
day_unknown?() click to toggle source
# File lib/open_ehr/assumed_library_types.rb, line 235
def day_unknown?
  @day.nil?
end
is_extended?() click to toggle source
# File lib/open_ehr/assumed_library_types.rb, line 239
def is_extended?
  true
end
is_partial?() click to toggle source
# File lib/open_ehr/assumed_library_types.rb, line 243
def is_partial?
  month_unknown? or day_unknown?
end
month=(month) click to toggle source
# File lib/open_ehr/assumed_library_types.rb, line 203
def month=(month)
  raise ArgumentError, "Month is not valid" unless month.nil? or TimeDefinitions.valid_month?(month)
  @month = month
end
month_unknown?() click to toggle source
# File lib/open_ehr/assumed_library_types.rb, line 231
def month_unknown?
  @month.nil?
end
to_days() click to toggle source
# File lib/open_ehr/assumed_library_types.rb, line 224
def to_days
  days = nilthenzero(@year)*TimeDefinitions::NOMINAL_DAYS_IN_YEAR +
    nilthenzero(@month)*TimeDefinitions::NOMINAL_DAYS_IN_MONTH +
    nilthenzero(@day)
  return days
end
year=(year) click to toggle source
# File lib/open_ehr/assumed_library_types.rb, line 196
def year=(year)
  unless TimeDefinitions.valid_year?(year)
    raise ArgumentError, "Year is not valid"
  end
  @year = year
end

Protected Instance Methods

leapyear?(year) click to toggle source
# File lib/open_ehr/assumed_library_types.rb, line 248
def leapyear?(year)
  case
  when (year % 400) == 0 then true
  when (year % 100) == 0 then false
  else year % 4 == 0
  end
end