Class: OpenEHR::AssumedLibraryTypes::ISO8601Date

Inherits:
Object
  • Object
show all
Includes:
Comparable, ISO8601DateModule
Defined in:
lib/open_ehr/assumed_library_types.rb

Constant Summary

Constants included from TimeDefinitions

TimeDefinitions::DAYS_IN_LEAP_YEAR, 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

Attributes included from ISO8601DateModule

#day, #month, #year

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ISO8601DateModule

#as_string, #day_unknown?, #is_extended?, #is_partial?, #month_unknown?, #to_days

Methods included from TimeDefinitions

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

Constructor Details

#initialize(string) ⇒ ISO8601Date

Returns a new instance of ISO8601Date.



259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
# File 'lib/open_ehr/assumed_library_types.rb', line 259

def initialize(string)
  /(\d{4})(?:-(\d{2})(?:-(\d{2})?)?)?/ =~ string
  if $1.nil?
    raise ArgumentError, 'data invalid'
  else
    self.year = $1.to_i
  end
  if $2.nil?
    self.month = nil
  else
    self.month = $2.to_i
  end
  if $3.nil?
    self.day = nil
  else
    self.day = $3.to_i
  end
end

Class Method Details

.valid_iso8601_date?(string) ⇒ Boolean

Returns:

  • (Boolean)


282
283
284
285
286
287
288
289
# File 'lib/open_ehr/assumed_library_types.rb', line 282

def self.valid_iso8601_date?(string)
  begin
    Date.parse(string)
  rescue
    return false
  end
  true
end

Instance Method Details

#<=>(other) ⇒ Object



278
279
280
# File 'lib/open_ehr/assumed_library_types.rb', line 278

def <=>(other)
  self.to_days <=> other.to_days
end