Changeset 149 for ruby/trunk/lib/models/rm/data_types/quantity/date_time.rb
- Timestamp:
- Jun 30, 2009, 11:59:58 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
ruby/trunk/lib/models/rm/data_types/quantity/date_time.rb
r142 r149 2 2 # http://www.openehr.org/uml/release-1.0.1/Browsable/_9_0_76d0249_1109696321450_28117_5362Report.html 3 3 # Ticket refs #49 4 require 'assumed_library_types' 5 4 6 module OpenEHR 5 7 module RM … … 10 12 attr_reader :value 11 13 12 def initialize(value) 14 def initialize(value, magnitude_status=nil, accuracy=nil, 15 normal_range=nil, normal_status=nil, 16 other_reference_ranges=nil) 13 17 self.value = value 18 self.magnitude_status = magnitude_status 19 self.accuracy = accuracy 20 self.normal_range = normal_range 21 self.normal_status = normal_status 22 self.other_reference_ranges = other_reference_ranges 14 23 end 15 24 16 25 def value=(value) 17 if value. empty? or value.nil?26 if value.nil? or value.empty? 18 27 raise ArgumentError, 'invalid value' 19 28 end 20 29 @value = value 21 end22 23 def diff(value)24 raise NotImplementedError, 'diff must be implemented'25 30 end 26 31 end … … 28 33 class DV_Date < DV_Temporal 29 34 include OpenEHR::Assumed_Library_Types::ISO8601_DATE_MODULE 30 def initialize 31 35 36 DAYS_IN_MONTH = [0,31,28,31,30,31,30,31,31,30,31,30,31] 37 38 def initialize(value, magnitude_status=nil, accuracy=nil, 39 normal_range=nil, normal_status=nil, 40 other_reference_range=nil) 41 super(value, magnitude_status, accuracy, normal_range, 42 normal_status, other_reference_range) 32 43 end 33 44 45 def value=(value) 46 super(value) 47 iso8601_date = Assumed_Library_Types::ISO8601_DATE.new(value) 48 @year = iso8601_date.year 49 @month = iso8601_date.month 50 @day = iso8601_date.day 51 end 52 53 undef magnitude= 54 55 def magnitude 56 return Date.new(@year, @month, @day)-Date.new(1601,1,1) 57 end 58 59 def diff(other) 60 if self.magnitude > other.magnitude 61 past, future = other, self 62 else 63 past, future = self, other 64 end 65 year, month, day = 0, 0, 0 66 if (future.day >= past.day) 67 day = future.day - past.day 68 else 69 month -= 1 70 previous_month = future.month - 1 71 if previous_month <= 0 72 previous_month = 12 73 end 74 day = DAYS_IN_MONTH[previous_month] + future.day - past.day 75 if leapyear?(future.year) && (previous_month == 2) 76 day += 1 77 end 78 end 79 week = day / 7 80 if (future.month >= past.month) 81 month += future.month - past.month 82 else 83 year -= 1 84 month += future.month + 12 - past.month 85 end 86 year += future.year - past.year 87 return DV_Duration.new( 88 'P' + year.to_s + 'Y' + month.to_s + 'M' + 89 week.to_s + 'W' + day.to_s + 'D') 90 end 34 91 end 35 92 … … 43 100 end 44 101 end 102 103 class DV_Duration < DV_Amount 104 include Assumed_Library_Types::ISO8601_DURATION_MODULE 105 attr_reader :value 106 107 def initialize(value, magnitude_status=nil, accuracy=nil, 108 accuracy_percent=nil, normal_range=nil, 109 normal_status = nil, other_reference_ranges=nil) 110 self.value = value 111 end 112 113 def value=(value) 114 raise ArgumentError, 'value must be not nil' if value.nil? 115 @value = value 116 iso8601_duration = Assumed_Library_Types::ISO8601_DURATION.new(value) 117 self.years = iso8601_duration.years 118 self.months = iso8601_duration.months 119 self.weeks = iso8601_duration.weeks 120 self.days = iso8601_duration.days 121 self.hours = iso8601_duration.hours 122 self.minutes = iso8601_duration.minutes 123 self.seconds = iso8601_duration.seconds 124 self.fractional_second = iso8601_duration.fractional_second 125 end 126 127 def magnitude 128 return ((((@year + @month/MONTH_IN_YEAR)*NOMINAL_DAYS_IN_MONTH) + 129 @week * DAYS_IN_WEEK + @days) * HOURS_IN_DAY * MINUTES_IN_HOUR* 130 SECONDS_IN_MINUTE) + @second + @fractional_second 131 end 132 133 undef magnitude= 134 135 end 45 136 end # of Date_Time 46 137 end # of Quantity
Note:
See TracChangeset
for help on using the changeset viewer.