Changeset 344 for ruby/branches


Ignore:
Timestamp:
Nov 12, 2009, 7:13:10 PM (14 years ago)
Author:
KOBAYASHI, Shinji
Message:

ref #55
time calculation might be refactored

Location:
ruby/branches/0.5
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • ruby/branches/0.5/lib/open_ehr/rm/data_structures/history.rb

    r343 r344  
    33# http://www.openehr.org/uml/release-1.0.1/Browsable/_9_0_76d0249_1109157527311_729550_7234Report.html
    44# refs #55
     5require 'time'
    56include OpenEHR::RM::DataStructures
    67include OpenEHR::RM::Common::Archetyped
     
    6566          end
    6667        end
     68
     69        class PointEvent < Event
     70
     71        end
     72
     73        class IntervalEvent < Event
     74          attr_reader :width, :math_function
     75          attr_accessor :sample_count
     76
     77          def initialize(args = { })
     78            super(args)
     79            self.width = args[:width]
     80            self.math_function = args[:math_function]
     81            self.sample_count = args[:sample_count]
     82          end
     83
     84          def width=(width)
     85            raise ArgumentError, 'width is mandatory' if width.nil?
     86            @width = width
     87          end
     88
     89          def math_function=(math_function)
     90            if math_function.nil?
     91              raise ArgumentError, 'math_function is mandatory'
     92            end
     93            @math_function = math_function
     94          end
     95
     96          def interval_start_time
     97            date_time = ::Time.iso8601(time.as_string)
     98            start_time = (@width.years).years.ago date_time
     99            start_time = (@width.months).months.ago start_time
     100            start_time = (@width.days).days.ago start_time
     101            start_time = (@width.hours).hours.ago start_time
     102            start_time = (@width.minutes).minutes.ago start_time
     103            seconds = @width.seconds
     104            unless @width.fractional_second.nil?
     105              seconds += @width.fractional_second
     106            end
     107            start_time = seconds.ago start_time
     108            return DvDateTime.new(:value => start_time.iso8601)
     109          end
     110        end
    67111      end # end of History
    68112    end # end of DataStructure
  • ruby/branches/0.5/spec/lib/open_ehr/rm/data_structures/history/event_spec.rb

    r343 r344  
    4242    @event.offset.value.should == 'P0Y0M0W0DT23H58M53S'
    4343  end
    44 
    4544end
Note: See TracChangeset for help on using the changeset viewer.