Index: ruby/branches/0.5/lib/open_ehr/assumed_library_types.rb
===================================================================
--- ruby/branches/0.5/lib/open_ehr/assumed_library_types.rb	(revision 342)
+++ ruby/branches/0.5/lib/open_ehr/assumed_library_types.rb	(revision 343)
@@ -583,5 +583,7 @@
         self.minutes = $13.to_i
         self.seconds = $15.to_i
-        self.fractional_second = $16.to_f
+        unless $16.nil?
+          self.fractional_second = $16.to_f
+        end
       end
     end # end of ISO8601Duration
Index: ruby/branches/0.5/lib/open_ehr/rm/data_structures/history.rb
===================================================================
--- ruby/branches/0.5/lib/open_ehr/rm/data_structures/history.rb	(revision 342)
+++ ruby/branches/0.5/lib/open_ehr/rm/data_structures/history.rb	(revision 343)
@@ -4,4 +4,5 @@
 # refs #55
 include OpenEHR::RM::DataStructures
+include OpenEHR::RM::Common::Archetyped
 
 module OpenEHR
@@ -39,5 +40,28 @@
         end
 
-        class Event
+        class Event < Locatable
+          attr_reader :data, :time
+          attr_accessor :state
+
+          def initialize(args = { })
+            super(args)
+            self.data = args[:data]
+            self.time = args[:time]
+            self.state = args[:state]
+          end
+
+          def data=(data)
+            raise ArgumentError, 'data is mandatory' if data.nil?
+            @data = data
+          end
+
+          def time=(time)
+            raise ArgumentError, 'time is mandatory' if time.nil?
+            @time = time
+          end
+
+          def offset
+            return @time.diff(@parent.origin)
+          end
         end
       end # end of History
Index: ruby/branches/0.5/lib/open_ehr/rm/data_types/quantity/date_time.rb
===================================================================
--- ruby/branches/0.5/lib/open_ehr/rm/data_types/quantity/date_time.rb	(revision 342)
+++ ruby/branches/0.5/lib/open_ehr/rm/data_types/quantity/date_time.rb	(revision 343)
@@ -100,5 +100,9 @@
 
             def magnitude
-              return @hour * 60 * 60 + @minute * 60 + @second + @fractional_second
+              if @fractional_second.nil?
+                return @hour * 60 * 60 + @minute * 60 + @second
+              else
+                return @hour * 60 * 60 + @minute * 60 + @second + @fractional_second
+              end
             end
 
@@ -109,8 +113,12 @@
               second = (diff - hour * 60 *60 - minute * 60).to_i
               fractional_second = ((diff - diff.to_i)*1000000.0).to_i/1000000.0
-              return DvDuration.new(:value =>
-                        'P0Y0M0W0DT' + hour.to_s + 'H' +
-                        minute.to_s + 'M' +
-                        second.to_s + fractional_second.to_s[1..-1] + 'S')
+              str = 'P0Y0M0W0DT' + hour.to_s + 'H' +
+                minute.to_s + 'M' + second.to_s
+              if @fractional_second.nil?
+                str += 'S'
+              else
+                str += fractional_second.to_s[1..-1] + 'S'
+              end
+              return DvDuration.new(:value => str)
             end
           end
@@ -161,11 +169,14 @@
               minute = ((time_diff - hour*60*60)/60).to_i
               second = (time_diff - hour * 60 *60 - minute * 60).to_i
-              fractional_second = 
-                ((time_diff - time_diff.to_i)*1000000.0).to_i/1000000.0
-              return DvDuration.new(:value => 
-                        date_duration.value + 'T' +
-                        hour.to_s + 'H' +
-                        minute.to_s + 'M' +
-                        second.to_s + fractional_second.to_s[1..-1] + 'S')
+              str = date_duration.value + 'T' + hour.to_s + 'H' +
+                minute.to_s + 'M' + second.to_s
+              if @fractional_second.nil?
+                return DvDuration.new(:value => str +'S')
+              else
+                fractional_second =
+                  ((time_diff - time_diff.to_i)*1000000.0).to_i/1000000.0
+                return DvDuration.new(:value => str +
+                                      fractional_second.to_s[1..-1] + 'S')
+              end
             end
 
@@ -174,5 +185,5 @@
             def split_date_time(date_time)
               /^(.*)T(.*)$/ =~ date_time.as_string
-              return DvDate.new($1), DvTime.new($2)
+              return DvDate.new(:value => $1), DvTime.new(:value => $2)
             end
           end
Index: ruby/branches/0.5/spec/lib/open_ehr/rm/data_structures/history/event_spec.rb
===================================================================
--- ruby/branches/0.5/spec/lib/open_ehr/rm/data_structures/history/event_spec.rb	(revision 343)
+++ ruby/branches/0.5/spec/lib/open_ehr/rm/data_structures/history/event_spec.rb	(revision 343)
@@ -0,0 +1,45 @@
+require File.dirname(__FILE__) + '/../../../../../spec_helper'
+include OpenEHR::RM::DataStructures::History
+include OpenEHR::RM::DataStructures::ItemStructure
+include OpenEHR::RM::DataTypes::Text
+include OpenEHR::RM::DataTypes::Quantity::DateTime
+
+describe Event do
+  before(:each) do
+    time = DvDateTime.new(:value => '2009-11-12T10:19:33')
+    state = stub(ItemStructure, :archetype_node_id => 'at0002')
+    origin = DvDateTime.new(:value => '2009-11-11T10:20:40')
+    parent = stub(History, :origin => origin)
+    @event = Event.new(:archetype_node_id => 'at0001',
+                       :name => DvText.new(:value => 'Event test'),
+                       :time => time,
+                       :data => 'data',
+                       :state => state,
+                       :parent => parent)
+  end
+
+  it 'should be an instance of Event' do
+    @event.should be_an_instance_of Event
+  end
+
+  it 'data should be assigned properly' do
+    @event.data.should == 'data'
+  end
+
+  it 'time should be assigned properly' do
+    @event.time.value.should == '2009-11-12T10:19:33'
+  end
+
+  it 'state should be assigned properly' do
+    @event.state.archetype_node_id.should == 'at0002'
+  end
+
+  it 'parent should be properly assigned' do
+    @event.parent.origin.value.should == '2009-11-11T10:20:40'
+  end
+
+  it 'offset should be diff of parent.origin from time' do
+    @event.offset.value.should == 'P0Y0M0W0DT23H58M53S'
+  end
+
+end
Index: ruby/branches/0.5/spec/lib/open_ehr/rm/data_structures/history/history_spec.rb
===================================================================
--- ruby/branches/0.5/spec/lib/open_ehr/rm/data_structures/history/history_spec.rb	(revision 342)
+++ ruby/branches/0.5/spec/lib/open_ehr/rm/data_structures/history/history_spec.rb	(revision 343)
@@ -4,4 +4,5 @@
 include OpenEHR::RM::DataTypes::Text
 include OpenEHR::RM::DataTypes::Quantity::DateTime
+
 describe History do
   before(:each) do
Index: ruby/branches/0.5/spec/lib/open_ehr/rm/data_types/quantity/date_time/dv_date_time_spec.rb
===================================================================
--- ruby/branches/0.5/spec/lib/open_ehr/rm/data_types/quantity/date_time/dv_date_time_spec.rb	(revision 342)
+++ ruby/branches/0.5/spec/lib/open_ehr/rm/data_types/quantity/date_time/dv_date_time_spec.rb	(revision 343)
@@ -18,3 +18,8 @@
     @dv_date_time.should == DvDateTime.new(:value => '2009-09-29T15:03:22.3')
   end
+
+  it 'diff should be caluculated from past to future' do
+    future = DvDateTime.new(:value => '2009-10-29T16:23:30.3')
+    @dv_date_time.diff(future).value.should == 'P0Y1M0W0DT1H20M8.0S'
+  end
 end
