Changeset 150 for ruby/trunk
- Timestamp:
- Jul 1, 2009, 1:40:42 AM (15 years ago)
- Location:
- ruby/trunk/lib/models
- Files:
-
- 2 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
ruby/trunk/lib/models/rm/data_types/quantity/date_time.rb
r149 r150 3 3 # Ticket refs #49 4 4 require 'assumed_library_types' 5 5 6 6 7 module OpenEHR … … 54 55 55 56 def magnitude 56 return Date.new(@year, @month, @day)-Date.new( 1601,1,1)57 return Date.new(@year, @month, @day)-Date.new(0000,1,1) 57 58 end 58 59 … … 91 92 end 92 93 93 class DV_Time 94 def initialize 94 class DV_Time < DV_Temporal 95 include OpenEHR::Assumed_Library_Types::ISO8601_TIME_MODULE 96 def initialize(value, magnitude_status=nil, accuracy=nil, 97 normal_range=nil, normal_status=nil, 98 other_reference_range=nil) 99 super(value, magnitude_status, accuracy, normal_range, 100 normal_status, other_reference_range) 101 end 102 103 def value=(value) 104 super(value) 105 iso8601_time = Assumed_Library_Types::ISO8601_TIME.new(value) 106 @hour = iso8601_time.hour 107 @minute = iso8601_time.minute 108 @second = iso8601_time.second 109 @fractional_second = iso8601_time.fractional_second 110 end 111 112 def magnitude 113 return @hour * 60 * 60 + @minute * 60 + @second + @fractional_second 114 end 115 116 def diff(other) 117 diff = (other.magnitude - self.magnitude).abs 118 hour = (diff / 60 / 60).to_i 119 minute = ((diff - hour*60*60)/60).to_i 120 second = (diff - hour * 60 *60 - minute * 60).to_i 121 fractional_second = ((diff - diff.to_i)*1000.0).to_i/1000.0 122 return 'P0Y0M0W0DT' + hour.to_s + 'H' + minute.to_s + 'M' + 123 second.to_s + fractional_second.to_s[1..-1] + 'S' 95 124 end 96 125 end 97 126 98 class DV_Date_Time 127 class DV_Date_Time < DV_Date 128 include OpenEHR::Assumed_Library_Types::ISO8601_TIME_MODULE 129 99 130 def initialize 100 131 end
Note:
See TracChangeset
for help on using the changeset viewer.