Class: OpenEHR::RM::DataTypes::Quantity::DateTime::DvDate
- Inherits:
-
DvTemporal
- Object
- Basic::DataValue
- OpenEHR::RM::DataTypes::Quantity::DvOrdered
- OpenEHR::RM::DataTypes::Quantity::DvQuantified
- OpenEHR::RM::DataTypes::Quantity::DvAbsoluteQuantity
- DvTemporal
- OpenEHR::RM::DataTypes::Quantity::DateTime::DvDate
- Includes:
- ISO8601DateModule
- Defined in:
- lib/open_ehr/rm/data_types/quantity/date_time.rb
Constant Summary collapse
- DAYS_IN_MONTH =
[0,31,28,31,30,31,30,31,31,30,31,30,31]
Constants included from Support::Definition::BasicDefinition
Support::Definition::BasicDefinition::CR, Support::Definition::BasicDefinition::LF
Instance Attribute Summary
Attributes inherited from OpenEHR::RM::DataTypes::Quantity::DvAbsoluteQuantity
Attributes inherited from OpenEHR::RM::DataTypes::Quantity::DvQuantified
Attributes inherited from OpenEHR::RM::DataTypes::Quantity::DvOrdered
#normal_range, #normal_status, #other_refference_ranges
Attributes inherited from Basic::DataValue
Instance Method Summary collapse
Methods inherited from DvTemporal
Methods inherited from OpenEHR::RM::DataTypes::Quantity::DvAbsoluteQuantity
Methods inherited from OpenEHR::RM::DataTypes::Quantity::DvQuantified
#<=>, #accuracy_unknown?, #initialize, valid_magnitude_status?
Methods inherited from OpenEHR::RM::DataTypes::Quantity::DvOrdered
#<=>, #initialize, #is_normal?, #is_simple?, #is_strictly_comparable_to?, #other_reference_ranges=
Methods inherited from Basic::DataValue
Constructor Details
This class inherits a constructor from OpenEHR::RM::DataTypes::Quantity::DateTime::DvTemporal
Instance Method Details
#diff(other) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/open_ehr/rm/data_types/quantity/date_time.rb', line 51 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 ⇒ Object
47 48 49 |
# File 'lib/open_ehr/rm/data_types/quantity/date_time.rb', line 47 def magnitude return Date.new(@year, @month, @day)-Date.new(0000,1,1) end |
#value=(value) ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/open_ehr/rm/data_types/quantity/date_time.rb', line 39 def value=(value) super(value) iso8601_date = ISO8601Date.new(value) @year = iso8601_date.year @month = iso8601_date.month @day = iso8601_date.day end |