Index: ruby/trunk/lib/open_ehr/am/archetype/constraint_model/primitive.rb
===================================================================
--- ruby/trunk/lib/open_ehr/am/archetype/constraint_model/primitive.rb	(revision 397)
+++ ruby/trunk/lib/open_ehr/am/archetype/constraint_model/primitive.rb	(revision 398)
@@ -173,4 +173,8 @@
             end
           end
+
+          class CTime < CPrimitive
+
+          end
         end # of Primitive
       end # of CostraintModel
Index: ruby/trunk/lib/open_ehr/assumed_library_types.rb
===================================================================
--- ruby/trunk/lib/open_ehr/assumed_library_types.rb	(revision 397)
+++ ruby/trunk/lib/open_ehr/assumed_library_types.rb	(revision 398)
@@ -135,5 +135,4 @@
 
     module ISO8601DateModule
-      include Comparable
       attr_reader :year, :month, :day
 
@@ -182,10 +181,4 @@
       end
       
-      def <=>(other)
-        (@year*TimeDefinitions::NOMINAL_DAYS_IN_YEAR +
-         @month*TimeDefinitions::NOMINAL_DAYS_IN_MONTH + @day) <=>
-          (other.year*TimeDefinitions::NOMINAL_DAYS_IN_YEAR +
-           other.month*TimeDefinitions::NOMINAL_DAYS_IN_MONTH + other.month)
-      end
       protected
       def leapyear?(year)
@@ -198,6 +191,10 @@
     end
 
+    def nilthenzero(value)
+      return value ? value : 0
+    end
+
     class ISO8601Date < TimeDefinitions
-      include ISO8601DateModule
+      include ISO8601DateModule, Comparable
       def initialize(string)
         /(\d{4})(?:-(\d{2})(?:-(\d{2})?)?)?/ =~ string
@@ -217,4 +214,16 @@
           self.day = $3.to_i
         end
+      end
+
+      def <=>(other)
+        magnitude =
+          nilthenzero(@year)*TimeDefinitions::NOMINAL_DAYS_IN_YEAR +
+          nilthenzero(@month)*TimeDefinitions::NOMINAL_DAYS_IN_MONTH +
+          nilthenzero(@day)
+        other_magnitude =
+          nilthenzero(other.year)*TimeDefinitions::NOMINAL_DAYS_IN_YEAR +
+          nilthenzero(other.month)*TimeDefinitions::NOMINAL_DAYS_IN_MONTH +
+          nilthenzero(other.day)
+        magnitude <=> other_magnitude
       end
 
@@ -312,8 +321,10 @@
         return s
       end
+
+      
     end
 
     class ISO8601Time < TimeDefinitions
-      include ISO8601TimeModule
+      include ISO8601TimeModule, Comparable
       def initialize(string)
         /(\d{2}):?(\d{2})?(:?)(\d{2})?((\.|,)(\d+))?(Z|([+-](\d{2}):?(\d{2})))?/ =~ string
@@ -343,4 +354,15 @@
           self.timezone = $8
         end
+      end
+
+      def <=>(other)
+        magnitude = (nilthenzero(@hour)*60 + nilthenzero(@minute))*60 +
+          nilthenzero(@second) +
+          nilthenzero(@fractional_second)
+        other_magnitude = (nilthenzero(other.hour) * 60 +
+                           nilthenzero(other.minute)) * 60 +
+          nilthenzero(other.second) +
+          nilthenzero(other.fractional_second)
+        magnitude <=> other_magnitude
       end
 
Index: ruby/trunk/lib/open_ehr/rm/data_types/quantity/date_time.rb
===================================================================
--- ruby/trunk/lib/open_ehr/rm/data_types/quantity/date_time.rb	(revision 397)
+++ ruby/trunk/lib/open_ehr/rm/data_types/quantity/date_time.rb	(revision 398)
@@ -181,10 +181,5 @@
             end
 
-            def <=>(other)
-              self.magnitude <=> other.magnitude
-            end
-
             private
-
             def split_date_time(date_time)
               /^(.*)T(.*)$/ =~ date_time.as_string
Index: ruby/trunk/spec/lib/open_ehr/am/archetype/constraint_model/primitive/c_time_spec.rb
===================================================================
--- ruby/trunk/spec/lib/open_ehr/am/archetype/constraint_model/primitive/c_time_spec.rb	(revision 398)
+++ ruby/trunk/spec/lib/open_ehr/am/archetype/constraint_model/primitive/c_time_spec.rb	(revision 398)
@@ -0,0 +1,19 @@
+require File.dirname(__FILE__) + '/../../../../../../spec_helper'
+include OpenEHR::AM::Archetype::ConstraintModel::Primitive
+include OpenEHR::AssumedLibraryTypes
+
+describe CTime do
+  before(:each) do
+    default_value = ISO8601Time.new('01:23:45.1')
+    assumed_value = ISO8601Time.new('22:02:33.2')
+    range = Interval.new(:lower => ISO8601Time.new('01:01:22.3'),
+                         :upper => ISO8601Time.new('23:55:59.4'))
+    @c_time = CTime.new(:default_value => default_value,
+                        :assumed_value => assumed_value,
+                        :range => range)
+  end
+
+  it 'should be an instance of CTime' do
+    @c_time.should be_an_instance_of CTime
+  end
+end
