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:
- AssumedLibraryTypes::ISO8601DateModule
- Defined in:
- lib/openehr/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 AssumedLibraryTypes::TimeDefinitions
AssumedLibraryTypes::TimeDefinitions::DAYS_IN_LEAP_YEAR, AssumedLibraryTypes::TimeDefinitions::DAYS_IN_WEEK, AssumedLibraryTypes::TimeDefinitions::DAYS_IN_YEAR, AssumedLibraryTypes::TimeDefinitions::HOURS_IN_DAY, AssumedLibraryTypes::TimeDefinitions::MAX_DAYS_IN_MONTH, AssumedLibraryTypes::TimeDefinitions::MAX_DAYS_IN_YEAR, AssumedLibraryTypes::TimeDefinitions::MINUTES_IN_HOUR, AssumedLibraryTypes::TimeDefinitions::MONTH_IN_YEAR, AssumedLibraryTypes::TimeDefinitions::NOMINAL_DAYS_IN_MONTH, AssumedLibraryTypes::TimeDefinitions::NOMINAL_DAYS_IN_YEAR, AssumedLibraryTypes::TimeDefinitions::SECONDS_IN_MINUTE
Constants included from Support::Definition::BasicDefinition
Support::Definition::BasicDefinition::CR, Support::Definition::BasicDefinition::LF
Instance Attribute Summary
Attributes included from AssumedLibraryTypes::ISO8601DateModule
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_reference_ranges
Attributes inherited from Basic::DataValue
Instance Method Summary collapse
Methods included from AssumedLibraryTypes::ISO8601DateModule
#as_string, #day_unknown?, #is_extended?, #is_partial?, #leapyear?, #month_unknown?, #to_days
Methods included from AssumedLibraryTypes::TimeDefinitions
valid_day?, valid_hour?, valid_minute?, valid_month?, valid_second?, valid_year?
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?
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
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 87 |
# 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 ⇒ Object
48 49 50 |
# 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) ⇒ Object
40 41 42 43 44 45 46 |
# 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 |