Index: /ruby/trunk/lib/open_ehr/am/archetype/constraint_model/primitive.rb
===================================================================
--- /ruby/trunk/lib/open_ehr/am/archetype/constraint_model/primitive.rb	(revision 396)
+++ /ruby/trunk/lib/open_ehr/am/archetype/constraint_model/primitive.rb	(revision 397)
@@ -133,5 +133,44 @@
           end
 
-          
+          class CDate < CPrimitive
+            attr_accessor :range, :timezone_validity
+            attr_reader :month_validity, :day_validity
+
+            def initialize(args = { })
+              super(args)
+              self.range = args[:range]
+              consistency_validity(args[:month_validity], args[:day_validity])
+              @month_validity = args[:month_validity]
+              @day_validity = args[:day_validity]
+              self.timezone_validity = args[:timezone_validity]
+            end
+
+            def month_validity=(month_validity)
+              consistency_validity(month_validity, @day_validity)
+              @month_validity = month_validity
+            end
+
+            def day_validity=(day_validity)
+              consistency_validity(@month_validity, day_validity)
+              @day_validity = day_validity
+            end
+
+            def validity_is_range?
+              return !@range.nil?
+            end
+
+            private
+            def consistency_validity(month_validity, day_validity)
+              if (month_validity == ValidityKind::OPTIONAL) &&
+                  !((day_validity == ValidityKind::OPTIONAL) ||
+                    (day_validity == ValidityKind::DISALLOWED))
+                raise ArgumentError, 'month_validity inconsistent'
+              end
+              if (month_validity == ValidityKind::DISALLOWED) &&
+                  !(day_validity == ValidityKind::DISALLOWED)
+                raise ArgumentError, 'month validity disallowed'
+              end
+            end
+          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 396)
+++ /ruby/trunk/lib/open_ehr/assumed_library_types.rb	(revision 397)
@@ -135,4 +135,5 @@
 
     module ISO8601DateModule
+      include Comparable
       attr_reader :year, :month, :day
 
@@ -180,5 +181,11 @@
         month_unknown? or day_unknown?
       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)
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 396)
+++ /ruby/trunk/lib/open_ehr/rm/data_types/quantity/date_time.rb	(revision 397)
@@ -181,4 +181,8 @@
             end
 
+            def <=>(other)
+              self.magnitude <=> other.magnitude
+            end
+
             private
 
Index: /ruby/trunk/spec/lib/open_ehr/am/archetype/constraint_model/primitive/c_date_spec.rb
===================================================================
--- /ruby/trunk/spec/lib/open_ehr/am/archetype/constraint_model/primitive/c_date_spec.rb	(revision 397)
+++ /ruby/trunk/spec/lib/open_ehr/am/archetype/constraint_model/primitive/c_date_spec.rb	(revision 397)
@@ -0,0 +1,81 @@
+require File.dirname(__FILE__) + '/../../../../../../spec_helper'
+include OpenEHR::AM::Archetype
+include OpenEHR::AM::Archetype::ConstraintModel::Primitive
+include OpenEHR::AssumedLibraryTypes
+
+describe CDate do
+  before(:each) do
+    default_value = ISO8601Date.new('2010-01-18')
+    assumed_value = ISO8601Date.new('2007-02-19')
+    
+    range = Interval.new(:lower => ISO8601Date.new('2001-01-01'),
+                         :upper => ISO8601Date.new('2010-12-31'))
+    @c_date = CDate.new(:default_value => default_value,
+                        :assumed_value => assumed_value,
+                        :range => range,
+                        :month_validity => ValidityKind::MANDATORY,
+                        :day_validity => ValidityKind::OPTIONAL,
+                        :timezone_validity => ValidityKind::DISALLOWED)
+  end
+
+  it 'should be an instance of CDate' do
+    @c_date.should be_an_instance_of CDate
+  end
+
+  it 'range should be assigned properly' do
+    @c_date.range.upper.month.should be_equal 12
+  end
+
+  it 'month_validity should be assigned properly by constructor' do
+    @c_date.month_validity.should be_equal ValidityKind::MANDATORY
+  end
+
+  it 'validity_is_range should be true if range is assigned' do
+    @c_date.should be_validity_is_range
+  end
+
+  it 'validity_is_range should not be true if range is nil' do
+    @c_date.range = nil
+    @c_date.should_not be_validity_is_range
+  end
+
+  it 'day_validity should be assigned properly by constructor' do
+    @c_date.day_validity.should be_equal ValidityKind::OPTIONAL
+  end
+
+  it 'timezone should be assigned properly' do
+    @c_date.timezone_validity.should be_equal ValidityKind::DISALLOWED
+  end
+
+  describe 'method' do
+    it 'month_validity should be assigned by method properly' do
+      @c_date.month_validity = ValidityKind::OPTIONAL
+      @c_date.month_validity.should be_equal ValidityKind::OPTIONAL
+    end
+
+    it 'day_validity should be assigned by method properly' do
+      @c_date.day_validity = ValidityKind::MANDATORY
+      @c_date.day_validity.should be_equal ValidityKind::MANDATORY
+    end
+
+    it 'should raise ArgumentError if month_validity is optional and day validity is mandatory' do
+      @c_date.day_validity = ValidityKind::MANDATORY
+      lambda {
+        @c_date.month_validity = ValidityKind::OPTIONAL
+      }.should raise_error ArgumentError
+    end
+
+    it 'should raise ArgumentError if month_validity is disallowed and day_validity is mandatory' do
+      @c_date.day_validity = ValidityKind::MANDATORY
+      lambda {
+        @c_date.month_validity = ValidityKind::DISALLOWED
+      }.should raise_error ArgumentError
+    end
+
+    it 'should raise ArgumentError if month_validity is disallowed and day_validity is optional' do
+      lambda {
+        @c_date.month_validity = ValidityKind::DISALLOWED
+      }.should raise_error ArgumentError
+    end
+  end
+end
Index: /ruby/trunk/spec/lib/open_ehr/am/archetype/constraint_model/primitive/c_string_spec.rb
===================================================================
--- /ruby/trunk/spec/lib/open_ehr/am/archetype/constraint_model/primitive/c_string_spec.rb	(revision 396)
+++ /ruby/trunk/spec/lib/open_ehr/am/archetype/constraint_model/primitive/c_string_spec.rb	(revision 397)
@@ -23,6 +23,11 @@
   end
 
-  it 'pattern should be assigned properly' do
+  it 'pattern should be assigned properly by constructor' do
     @c_string.pattern.should == 't[a-z]st'
+  end
+
+  it 'pattern should be assigned properly by method' do
+    @c_string.pattern = '.*'
+    @c_string.pattern.should == '.*'
   end
 
@@ -47,6 +52,11 @@
     end
 
-    it 'list should be assigned properly' do
+    it 'list should be assigned properly by constructor' do
       @c_string.list.should == ['test', 'behavior']
+    end
+
+    it 'list shoudl be assigned properly by method' do
+      @c_string.list = ['spec']
+      @c_string.list.should == ['spec']
     end
 
