Module: OpenEHR::AssumedLibraryTypes::ISO8601DateModule

Includes:
TimeDefinitions
Included in:
ISO8601Date, ISO8601DateTimeModule, RM::DataTypes::Quantity::DateTime::DvDate
Defined in:
lib/openehr/assumed_library_types.rb

Overview

end of TimeDefinitions

Constant Summary

Constants included from TimeDefinitions

TimeDefinitions::DAYS_IN_LEAP_YEAR, TimeDefinitions::DAYS_IN_MONTH, TimeDefinitions::DAYS_IN_WEEK, TimeDefinitions::DAYS_IN_YEAR, TimeDefinitions::HOURS_IN_DAY, TimeDefinitions::MAX_DAYS_IN_MONTH, TimeDefinitions::MAX_DAYS_IN_YEAR, TimeDefinitions::MINUTES_IN_HOUR, TimeDefinitions::MONTH_IN_YEAR, TimeDefinitions::NOMINAL_DAYS_IN_MONTH, TimeDefinitions::NOMINAL_DAYS_IN_YEAR, TimeDefinitions::SECONDS_IN_MINUTE

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from TimeDefinitions

valid_day?, valid_hour?, valid_minute?, valid_month?, valid_second?, valid_year?

Instance Attribute Details

#dayObject

Returns the value of attribute day.



197
198
199
# File 'lib/openehr/assumed_library_types.rb', line 197

def day
  @day
end

#monthObject

Returns the value of attribute month.



197
198
199
# File 'lib/openehr/assumed_library_types.rb', line 197

def month
  @month
end

#yearObject

Returns the value of attribute year.



197
198
199
# File 'lib/openehr/assumed_library_types.rb', line 197

def year
  @year
end

Instance Method Details

#as_stringObject



217
218
219
220
221
222
223
224
225
# File 'lib/openehr/assumed_library_types.rb', line 217

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_unknown?Boolean

Returns:

  • (Boolean)


238
239
240
# File 'lib/openehr/assumed_library_types.rb', line 238

def day_unknown?
  @day.nil?
end

#is_extended?Boolean

Returns:

  • (Boolean)


242
243
244
# File 'lib/openehr/assumed_library_types.rb', line 242

def is_extended?
  true
end

#is_partial?Boolean

Returns:

  • (Boolean)


246
247
248
# File 'lib/openehr/assumed_library_types.rb', line 246

def is_partial?
  month_unknown? or day_unknown?
end

#leapyear?(year) ⇒ Boolean

Returns:

  • (Boolean)


250
251
252
253
254
255
256
# File 'lib/openehr/assumed_library_types.rb', line 250

def leapyear?(year)
  case
  when (year % 400) == 0 then true
  when (year % 100) == 0 then false
  else year % 4 == 0
  end
end

#month_unknown?Boolean

Returns:

  • (Boolean)


234
235
236
# File 'lib/openehr/assumed_library_types.rb', line 234

def month_unknown?
  @month.nil?
end

#to_daysObject



227
228
229
230
231
232
# File 'lib/openehr/assumed_library_types.rb', line 227

def to_days
  days = nilthenzero(@year)*TimeDefinitions::NOMINAL_DAYS_IN_YEAR +
    nilthenzero(@month)*TimeDefinitions::NOMINAL_DAYS_IN_MONTH +
    nilthenzero(@day)
  return days
end