Class: OpenEHR::RM::DataTypes::Quantity::DateTime::DvDate

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

#day, #month, #year

Attributes inherited from OpenEHR::RM::DataTypes::Quantity::DvAbsoluteQuantity

#accuracy

Attributes inherited from OpenEHR::RM::DataTypes::Quantity::DvQuantified

#magnitude_status

Attributes inherited from OpenEHR::RM::DataTypes::Quantity::DvOrdered

#normal_range, #normal_status, #other_refference_ranges

Attributes inherited from Basic::DataValue

#value

Instance Method Summary collapse

Methods included from AssumedLibraryTypes::ISO8601DateModule

#as_string, #day_unknown?, #is_extended?, #is_partial?, #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

#initialize

Methods inherited from OpenEHR::RM::DataTypes::Quantity::DvAbsoluteQuantity

#add, #initialize, #subtract

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

#==, #initialize

Constructor Details

This class inherits a constructor from OpenEHR::RM::DataTypes::Quantity::DateTime::DvTemporal

Instance Method Details

#diff(other) ⇒ Object



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
88
# File 'lib/open_ehr/rm/data_types/quantity/date_time.rb', line 53

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

#magnitudeObject



49
50
51
# File 'lib/open_ehr/rm/data_types/quantity/date_time.rb', line 49

def magnitude
  return Date.new(@year, @month, @day)-Date.new(0000,1,1)
end

#value=(value) ⇒ Object



41
42
43
44
45
46
47
# File 'lib/open_ehr/rm/data_types/quantity/date_time.rb', line 41

def value=(value)
  super(value)
  iso8601_date = ISO8601Date.new(value)
  @year = iso8601_date.year
  @month = iso8601_date.month
  @day = iso8601_date.day
end