Changeset 83 for ruby/trunk


Ignore:
Timestamp:
Jul 20, 2008, 8:19:06 PM (16 years ago)
Author:
KOBAYASHI, Shinji
Message:

refs #36
almost all fixed ISO8601_TIME

Location:
ruby/trunk/lib/models
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • ruby/trunk/lib/models/assumed_library_types.rb

    r81 r83  
     1# This module is related to the ticket #36
    12require 'date'
    23require 'time'
     
    8889      end
    8990
    90       def self.valid_hour?(h,m,s)
    91         valid_minute?(m) and valid_second?(s) and ((h >= 0 and h < HOURS_IN_DAY) or (h == HOURS_IN_DAY and m == 0 and s == 0))
     91      def self.valid_hour?(h,m = nil, s = nil)
     92        if !m.nil? and !valid_minute?(m)
     93          return false
     94        end
     95        if !s.nil? and (!m.nil? and !valid_second?(s))
     96          return false
     97        end
     98        (h >= 0 and h < HOURS_IN_DAY) or (h == HOURS_IN_DAY and m == 0 and s == 0)
    9299      end
    93100      def self.valid_minute?(mi)
     
    161168
    162169    class ISO8601_TIME < TIME_DEFINITIONS
    163       attr_reader :hh, :mm, :ss, :msec, :tz
    164       def initialize(hh = nil, mm = nil, ss = nil, msec = nil, tz = nil)
    165        
     170      attr_reader :hour, :minute, :second, :fractional_second, :timezone
     171      def initialize(hh, mm = nil, ss = nil, msec = nil, tz = nil)
     172        raise ArgumentError, "Not valid hour format" if !ISO8601_TIME.valid_hour?(hh,mm,ss)
     173        @hour = hh; @minute = mm; @second = ss
     174        @fractional_second = msec; @timezone = tz
     175      end
     176      def hour=(hour)
     177        raise ArgumentError, "hour is not valid" if !ISO8601_TIME.valid_hour?(hour, @minute, @second)
     178        @hour = hour
     179      end
     180      def minute_unknown?
     181        @minute.nil?
     182      end
     183      def minute=(minute)
     184        raise ArgumentError, "minute is not valid" if !minute.nil? and !ISO8601_TIME.valid_minute?(minute)
     185        @minute = minute
     186      end
     187      def second_unknown?
     188        @second.nil?
     189      end
     190      def second=(second)
     191        raise ArgumentError, "minute not defined" if @minute.nil?
     192        raise ArgumentError, "second is not valid" if !second.nil? and !ISO8601_TIME.valid_second?(second)
     193        @second = second
     194      end
     195      def fractional_second=(fractional_second)
     196        raise ArgumentError, "minute not defined" if minute_unknown?
     197        raise ArgumentError, "second not defined" if second_unknown?
     198        raise ArgumentError, "fractional second should be lower than 1.0" if fractional_second >= 1.0
     199        @fractional_second = fractional_second
     200      end
     201      def has_fractional_second?
     202        if @fractional_second.nil?
     203          return false
     204        else
     205          return true
     206        end
     207      end
     208      def is_decimal_sign_comma?
     209        true
     210      end
     211      def is_extended?
     212        true
     213      end
     214      def is_partial?
     215        second_unknown? or minute_unknown?
    166216      end
    167217      def as_string
    168         s = @hh
    169         if !@mm.nil?
    170           s += ":" + @mm
    171           if !@ss.nil?
    172             s += ":" + @ss
    173             if !@msec.nil?
    174               s += "," + @msec
    175               if !@tz.nil?
    176                 s += @tz
     218        s = sprintf("%02d", @hour)
     219        if !@minute.nil?
     220          s += ":" + sprintf("%02d",@minute)
     221          if !@second.nil?
     222            s += ":" + sprintf("%02d", @second)
     223            if !@fractional_second.nil?
     224              s += "," + @fractional_second.to_s[2..-1]
     225              if !@timezone.nil?
     226                s += @timezone
    177227              end
    178228            end
     
    187237# (\d{4})(?:-(\d{2})(?:-(\d{2})(?:T(\d{2}):(\d{2})(?::(\d{2})(?:\.(\d))?)?(Z|([+-]\d{2}):(\d{2}))?)?)?)?
    188238          hh = $1; mm = $2; ss = $4; msec = $7; tz = $8
    189           if hh.to_i == HOURS_IN_DAY and (mm.nil? or mm.to_i == "00") and (ss.nil? or ss.to_i == "00")
     239          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)
    190240            return true
    191241          end
  • ruby/trunk/lib/models/rm/common/generic.rb

    r4 r83  
     1# This module is a implementation of the bellow UML
     2# http://www.openehr.org/uml/release-1.0.1/Browsable/_9_5_1_76d0249_1140169202660_257304_813Report.html
     3# Related to the ticket #62
    14module OpenEHR
    25  module RM
Note: See TracChangeset for help on using the changeset viewer.