Index: ruby/branches/0.5/lib/open_ehr/assumed_library_types.rb
===================================================================
--- ruby/branches/0.5/lib/open_ehr/assumed_library_types.rb	(revision 284)
+++ ruby/branches/0.5/lib/open_ehr/assumed_library_types.rb	(revision 285)
@@ -109,4 +109,7 @@
 
       def self.valid_hour?(h,m = nil, s = nil)
+        if h.nil?
+          return false
+        end
         if !m.nil? and !valid_minute?(m)
           return false
@@ -223,5 +226,7 @@
 
       def hour=(hour)
-        raise ArgumentError, "hour is not valid" if !ISO8601_TIME.valid_hour?(hour, @minute, @second)
+        unless ISO8601Time.valid_hour?(hour, @minute, @second)
+          raise ArgumentError, "hour is not valid"
+        end
         @hour = hour
       end
@@ -232,5 +237,5 @@
 
       def minute=(minute)
-        raise ArgumentError, "minute is not valid" if !minute.nil? and !ISO8601_TIME.valid_minute?(minute)
+        raise ArgumentError, "minute is not valid" if !minute.nil? and !ISO8601Time.valid_minute?(minute)
         @minute = minute
       end
@@ -242,5 +247,5 @@
       def second=(second)
         raise ArgumentError, "minute not defined" if @minute.nil? and !second.nil?
-        raise ArgumentError, "second is not valid" if !second.nil? and !ISO8601_TIME.valid_second?(second)
+        raise ArgumentError, "second is not valid" if !second.nil? and !ISO8601Time.valid_second?(second)
         @second = second
       end
@@ -249,14 +254,13 @@
         raise ArgumentError, "minute not defined" if minute_unknown? and !fractional_second.nil?
         raise ArgumentError, "second not defined" if second_unknown? and !fractional_second.nil?
-        raise ArgumentError, "fractional second should be lower than 1.0" if !fractional_second.nil? and fractional_second >= 1.0
+        if !fractional_second.nil? &&
+            (fractional_second < 0.0 || fractional_second >= 1.0)
+          raise ArgumentError, 'fractional second should be between 0.0 - 1.0'
+        end
         @fractional_second = fractional_second
       end
 
       def has_fractional_second?
-        if @fractional_second.nil?
-          return false
-        else
-          return true
-        end
+        return !@fractional_second.nil?
       end
 
@@ -333,10 +337,11 @@
         end
       end
+
       def self.valid_iso8601_time?(s)
-        if /(\d{2}):?(\d{2})?(:?)(\d{2})?((\.|,)(\d+))?(Z|([+-](\d{2}):?(\d{2})))?/ =~ s
+        if /^(\d{2}):?(\d{2})?(:?)(\d{2})?((\.|,)(\d+))?(T?)(Z|([+-](\d{2}):?(\d{2})))?$/ =~ s
 # ISO 8601 regular expression by H. Yuki
 #  http://digit.que.ne.jp/work/wiki.cgi?Perl%E3%83%A1%E3%83%A2%2FW3C%E5%BD%A2%E5%BC%8F%E3%81%AE%E6%97%A5%E6%99%82%E3%81%AE%E8%A7%A3%E6%9E%90
 # (\d{4})(?:-(\d{2})(?:-(\d{2})(?:T(\d{2}):(\d{2})(?::(\d{2})(?:\.(\d))?)?(Z|([+-]\d{2}):(\d{2}))?)?)?)?
-          hh = $1; mm = $2; ss = $4; msec = $7; tz = $8
+          hh = $1; mm = $2; ss = $4; msec = $7; tz = $9
           if hh.to_i == HOURS_IN_DAY and (mm.nil? or mm.to_i == 0) and (ss.nil? or ss.to_i == 0) and (msec.nil? or msec.to_i==0)
             return true
@@ -364,6 +369,4 @@
                 return false
               end
-            else
-              return false
             end
           end
Index: ruby/branches/0.5/spec/lib/open_ehr/assumed_library_types/iso8601_time_spec.rb
===================================================================
--- ruby/branches/0.5/spec/lib/open_ehr/assumed_library_types/iso8601_time_spec.rb	(revision 285)
+++ ruby/branches/0.5/spec/lib/open_ehr/assumed_library_types/iso8601_time_spec.rb	(revision 285)
@@ -0,0 +1,234 @@
+require File.dirname(__FILE__) + '/../../../spec_helper'
+include OpenEHR::AssumedLibraryTypes
+
+describe ISO8601Time do
+  before(:each) do
+    @iso8601time = ISO8601Time.new('15:55:37.32+0900')
+  end
+
+  it 'should be an instance of ISO8601Time' do
+    @iso8601time.should be_an_instance_of ISO8601Time
+  end
+
+  it 's hour should be 15' do
+    @iso8601time.hour.should == 15
+  end
+
+  it 's minute should be 55' do
+    @iso8601time.minute.should == 55
+  end
+
+  it 's second should be 37'do
+    @iso8601time.second.should == 37
+  end
+
+  it 's fractional second should be 0.32' do
+    @iso8601time.fractional_second == 0.32
+  end
+
+  it 'have fractional_second' do
+    @iso8601time.should have_fractional_second
+  end
+
+  it 's time zone should +0900' do
+    @iso8601time.timezone == '+0900'
+  end
+
+  it 'should be 15:55:37.32+0900 as_string' do
+    @iso8601time.as_string.should == '15:55:37.32+0900'
+  end
+
+  it 'decimal sign should not be comma' do
+    @iso8601time.is_decimal_sign_comma?.should_not be_true
+  end
+
+  it 'should be extended' do
+    @iso8601time.is_extended?.should be_true
+  end
+
+  it 'should not be partial' do
+    @iso8601time.is_partial?.should_not be true
+  end
+
+  describe 'hour behavior' do
+    it 'should raise ArgumentError with nil hour' do
+      lambda {
+        @iso8601time.hour = nil
+      }.should raise_error ArgumentError
+    end
+
+    it 'should not raise ArgumentError with -1 hour' do
+      lambda {
+        @iso8601time.hour = -1
+      }.should raise_error ArgumentError
+    end        
+
+    it 'should not raise ArgumentError with 0 hour' do
+      lambda {
+        @iso8601time.hour = 0
+      }.should_not raise_error ArgumentError
+    end
+
+    it 'should not raise ArgumentError with 23 hour' do
+      lambda {
+        @iso8601time.hour = 23
+      }.should_not raise_error ArgumentError
+    end
+
+    it 'should not raise ArgumentError with 24 hour' do
+      lambda {
+        @iso8601time.hour = 24
+      }.should raise_error ArgumentError
+    end
+  end
+
+  describe 'minute behavior' do
+    it 'should raise ArgumentError with -1 miniute' do
+      lambda {
+        @iso8601time.minute = -1
+      }.should raise_error ArgumentError
+    end
+
+    it 'should not raise ArgumentError with 0 minute' do
+      lambda {
+        @iso8601time.minute = 0
+      }.should_not raise_error ArgumentError
+    end
+
+    it 'should not raise ArgumentError with 59 minute' do
+      lambda {
+        @iso8601time.minute = 59
+      }.should_not raise_error ArgumentError
+    end
+
+    it 'should raise ArgumentError with 60 minute' do
+      lambda {
+        @iso8601time.minute = 60
+      }.should raise_error ArgumentError
+    end
+  end
+
+  describe 'second behavior' do
+    it 'should raise ArgumentError with -1 miniute' do
+      lambda {
+        @iso8601time.second = -1
+      }.should raise_error ArgumentError
+    end
+
+    it 'should not raise ArgumentError with 0 second' do
+      lambda {
+        @iso8601time.second = 0
+      }.should_not raise_error ArgumentError
+    end
+
+    it 'should not raise ArgumentError with 59 second' do
+      lambda {
+        @iso8601time.second = 59
+      }.should_not raise_error ArgumentError
+    end
+
+    it 'should raise ArgumentError with 60 second' do
+      lambda {
+        @iso8601time.second = 60
+      }.should raise_error ArgumentError
+    end
+  end
+
+  describe 'fractional second behavior' do
+    it 'should raise ArgumentError less than -0.0' do
+      lambda {
+        @iso8601time.fractional_second = -0.1
+      }.should raise_error ArgumentError
+    end
+
+    it 'should raise ArgumentError more than 1.0' do
+      lambda {
+        @iso8601time.fractional_second = 1.0
+      }.should raise_error ArgumentError
+    end
+  end
+
+  describe 'timezone behavior' do
+    it 'should raise ArgumentError with invalid timezone' do
+      lambda {
+        @iso8601time.timezone = '+AbD:111'
+      }.should raise_error ArgumentError
+    end
+
+    it 'should allow ArgumentError with nil timezone' do
+      lambda {
+        @iso8601time.timezone = nil
+      }.should_not raise_error ArgumentError
+    end
+  end
+
+  describe 'constructor behavior' do
+    it 'should_not raise ArgumentError with 21:18:09.01' do
+      lambda {
+        ISO8601Time.new('21:18:09.01')
+      }.should_not raise_error ArgumentError
+    end
+
+    it 'should_not raise ArgumentError with 21:18:09' do
+      lambda {
+        ISO8601Time.new('21:18:09')
+      }.should_not raise_error ArgumentError
+    end
+
+    it 'should_not raise ArgumentError with 21:18' do
+      lambda {
+        ISO8601Time.new('21:18')
+      }.should_not raise_error ArgumentError
+    end
+
+    it 'should_not raise ArgumentError with 21' do
+      lambda {
+        ISO8601Time.new('21')
+      }.should_not raise_error ArgumentError
+    end
+
+    it 'should raise ArgumentError with malformation' do
+      lambda {
+        ISO8601Time.new('ABDCD')
+      }.should raise_error ArgumentError
+    end
+  end
+
+  describe 'ISO8601 time validation' do
+    it 'should be valid iso8601 Time' do
+      ISO8601Time.should be_valid_iso8601_time '21:24:30.05+09:00'
+    end
+
+    it 'should not be valid with over 24 hour' do
+      ISO8601Time.should_not be_valid_iso8601_time '24:24:30.05+09:00'
+    end
+
+    it 'should be valid with over 24:00:00' do
+      ISO8601Time.should be_valid_iso8601_time '24:00:00.00'
+    end
+
+    it 'should not vaild with under 0 hour' do
+      ISO8601Time.should_not be_valid_iso8601_time '-1:24:30.05+09:00'
+    end
+
+    it 'should not valid with more than 60 minutes' do
+      ISO8601Time.should_not be_valid_iso8601_time '21:60:30'
+    end
+
+    it 'should not valid with more than 60 seconds' do
+      ISO8601Time.should_not be_valid_iso8601_time '21:34:60'
+    end
+
+    it 'should not valid with invalid hour in timezone' do
+      ISO8601Time.should_not be_valid_iso8601_time '21:24:30.05+24:00'
+    end
+
+    it 'should not valid with invalid minute in timezone' do
+      ISO8601Time.should_not be_valid_iso8601_time '21:24:30.05+22:60'
+    end
+
+    it 'should not valid with invalid minute in timezone' do
+      ISO8601Time.should_not be_valid_iso8601_time '21:24:30.05TAABZ'
+    end
+  end
+end
Index: ruby/branches/0.5/spec/lib/open_ehr/assumed_library_types/iso_8601_date_spec.rb
===================================================================
--- ruby/branches/0.5/spec/lib/open_ehr/assumed_library_types/iso_8601_date_spec.rb	(revision 284)
+++ ruby/branches/0.5/spec/lib/open_ehr/assumed_library_types/iso_8601_date_spec.rb	(revision 285)
@@ -35,7 +35,10 @@
   end
 
+  it 'should parse valid adte form' do
+    ISO8601Date.should be_valid_iso8601_date '2009-09-22'
+  end
 
   it 'should not parse invalid date form' do
-    ISO8601Date.valid_iso8601_date?('2009-13-54').should_not be_true
+    ISO8601Date.should_not be_valid_iso8601_date '2009-13-54'
   end
 
