Changeset 285


Ignore:
Timestamp:
Sep 22, 2009, 9:59:24 PM (11 years ago)
Author:
KOBAYASHI, Shinji
Message:

ISO8601Date ISO8601Time completed

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

Legend:

Unmodified
Added
Removed
  • ruby/branches/0.5/lib/open_ehr/assumed_library_types.rb

    r282 r285  
    109109
    110110      def self.valid_hour?(h,m = nil, s = nil)
     111        if h.nil?
     112          return false
     113        end
    111114        if !m.nil? and !valid_minute?(m)
    112115          return false
     
    223226
    224227      def hour=(hour)
    225         raise ArgumentError, "hour is not valid" if !ISO8601_TIME.valid_hour?(hour, @minute, @second)
     228        unless ISO8601Time.valid_hour?(hour, @minute, @second)
     229          raise ArgumentError, "hour is not valid"
     230        end
    226231        @hour = hour
    227232      end
     
    232237
    233238      def minute=(minute)
    234         raise ArgumentError, "minute is not valid" if !minute.nil? and !ISO8601_TIME.valid_minute?(minute)
     239        raise ArgumentError, "minute is not valid" if !minute.nil? and !ISO8601Time.valid_minute?(minute)
    235240        @minute = minute
    236241      end
     
    242247      def second=(second)
    243248        raise ArgumentError, "minute not defined" if @minute.nil? and !second.nil?
    244         raise ArgumentError, "second is not valid" if !second.nil? and !ISO8601_TIME.valid_second?(second)
     249        raise ArgumentError, "second is not valid" if !second.nil? and !ISO8601Time.valid_second?(second)
    245250        @second = second
    246251      end
     
    249254        raise ArgumentError, "minute not defined" if minute_unknown? and !fractional_second.nil?
    250255        raise ArgumentError, "second not defined" if second_unknown? and !fractional_second.nil?
    251         raise ArgumentError, "fractional second should be lower than 1.0" if !fractional_second.nil? and fractional_second >= 1.0
     256        if !fractional_second.nil? &&
     257            (fractional_second < 0.0 || fractional_second >= 1.0)
     258          raise ArgumentError, 'fractional second should be between 0.0 - 1.0'
     259        end
    252260        @fractional_second = fractional_second
    253261      end
    254262
    255263      def has_fractional_second?
    256         if @fractional_second.nil?
    257           return false
    258         else
    259           return true
    260         end
     264        return !@fractional_second.nil?
    261265      end
    262266
     
    333337        end
    334338      end
     339
    335340      def self.valid_iso8601_time?(s)
    336         if /(\d{2}):?(\d{2})?(:?)(\d{2})?((\.|,)(\d+))?(Z|([+-](\d{2}):?(\d{2})))?/ =~ s
     341        if /^(\d{2}):?(\d{2})?(:?)(\d{2})?((\.|,)(\d+))?(T?)(Z|([+-](\d{2}):?(\d{2})))?$/ =~ s
    337342# ISO 8601 regular expression by H. Yuki
    338343#  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
    339344# (\d{4})(?:-(\d{2})(?:-(\d{2})(?:T(\d{2}):(\d{2})(?::(\d{2})(?:\.(\d))?)?(Z|([+-]\d{2}):(\d{2}))?)?)?)?
    340           hh = $1; mm = $2; ss = $4; msec = $7; tz = $8
     345          hh = $1; mm = $2; ss = $4; msec = $7; tz = $9
    341346          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)
    342347            return true
     
    364369                return false
    365370              end
    366             else
    367               return false
    368371            end
    369372          end
  • ruby/branches/0.5/spec/lib/open_ehr/assumed_library_types/iso_8601_date_spec.rb

    r280 r285  
    3535  end
    3636
     37  it 'should parse valid adte form' do
     38    ISO8601Date.should be_valid_iso8601_date '2009-09-22'
     39  end
    3740
    3841  it 'should not parse invalid date form' do
    39     ISO8601Date.valid_iso8601_date?('2009-13-54').should_not be_true
     42    ISO8601Date.should_not be_valid_iso8601_date '2009-13-54'
    4043  end
    4144
Note: See TracChangeset for help on using the changeset viewer.