Changeset 150


Ignore:
Timestamp:
Jul 1, 2009, 1:40:42 AM (15 years ago)
Author:
KOBAYASHI, Shinji
Message:

refs #49

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  
    33# Ticket refs #49
    44require 'assumed_library_types'
     5
    56
    67module OpenEHR
     
    5455
    5556            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)
    5758            end
    5859
     
    9192          end
    9293         
    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'
    95124            end
    96125          end
    97126
    98           class DV_Date_Time
     127          class DV_Date_Time < DV_Date
     128            include OpenEHR::Assumed_Library_Types::ISO8601_TIME_MODULE
     129           
    99130            def initialize
    100131            end
Note: See TracChangeset for help on using the changeset viewer.