class OpenEHR::RM::DataTypes::Quantity::DateTime::DvDate
Constants
- DAYS_IN_MONTH
Public Instance Methods
diff(other)
click to toggle source
# File lib/openehr/rm/data_types/quantity/date_time.rb, line 52 def diff(other) if self.magnitude > other.magnitude past, future = other, self else past, future = self, other end year, month, day = 0, 0, 0 if (future.day >= past.day) day = future.day - past.day else month = -1 previous_month = future.month - 1 if previous_month == 0 previous_month = 12 end day = DAYS_IN_MONTH[previous_month] + future.day - past.day if leapyear?(future.year) && (previous_month == 2) day += 1 end end week = day / 7 if (future.month >= past.month) month += future.month - past.month else year -= 1 month += future.month + 12 - past.month end if month < 0 year -= 1 month += 12 end year += future.year - past.year return DvDuration.new(:value => 'P' + year.to_s + 'Y' + month.to_s + 'M' + week.to_s + 'W' + day.to_s + 'D') end
magnitude()
click to toggle source
# File lib/openehr/rm/data_types/quantity/date_time.rb, line 48 def magnitude return Date.new(@year, @month, @day)-Date.new(0000,1,1) end
value=(value)
click to toggle source
Calls superclass method
OpenEHR::RM::DataTypes::Quantity::DateTime::DvTemporal#value=
# File lib/openehr/rm/data_types/quantity/date_time.rb, line 40 def value=(value) super(value) iso8601_date = OpenEHR::AssumedLibraryTypes::ISO8601Date.new(value) @year = iso8601_date.year @month = iso8601_date.month @day = iso8601_date.day end