Ignore:
Timestamp:
Jan 21, 2010, 6:54:57 PM (14 years ago)
Author:
KOBAYASHI, Shinji
Message:

refs #71

File:
1 edited

Legend:

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

    r397 r398  
    135135
    136136    module ISO8601DateModule
    137       include Comparable
    138137      attr_reader :year, :month, :day
    139138
     
    182181      end
    183182     
    184       def <=>(other)
    185         (@year*TimeDefinitions::NOMINAL_DAYS_IN_YEAR +
    186          @month*TimeDefinitions::NOMINAL_DAYS_IN_MONTH + @day) <=>
    187           (other.year*TimeDefinitions::NOMINAL_DAYS_IN_YEAR +
    188            other.month*TimeDefinitions::NOMINAL_DAYS_IN_MONTH + other.month)
    189       end
    190183      protected
    191184      def leapyear?(year)
     
    198191    end
    199192
     193    def nilthenzero(value)
     194      return value ? value : 0
     195    end
     196
    200197    class ISO8601Date < TimeDefinitions
    201       include ISO8601DateModule
     198      include ISO8601DateModule, Comparable
    202199      def initialize(string)
    203200        /(\d{4})(?:-(\d{2})(?:-(\d{2})?)?)?/ =~ string
     
    217214          self.day = $3.to_i
    218215        end
     216      end
     217
     218      def <=>(other)
     219        magnitude =
     220          nilthenzero(@year)*TimeDefinitions::NOMINAL_DAYS_IN_YEAR +
     221          nilthenzero(@month)*TimeDefinitions::NOMINAL_DAYS_IN_MONTH +
     222          nilthenzero(@day)
     223        other_magnitude =
     224          nilthenzero(other.year)*TimeDefinitions::NOMINAL_DAYS_IN_YEAR +
     225          nilthenzero(other.month)*TimeDefinitions::NOMINAL_DAYS_IN_MONTH +
     226          nilthenzero(other.day)
     227        magnitude <=> other_magnitude
    219228      end
    220229
     
    312321        return s
    313322      end
     323
     324     
    314325    end
    315326
    316327    class ISO8601Time < TimeDefinitions
    317       include ISO8601TimeModule
     328      include ISO8601TimeModule, Comparable
    318329      def initialize(string)
    319330        /(\d{2}):?(\d{2})?(:?)(\d{2})?((\.|,)(\d+))?(Z|([+-](\d{2}):?(\d{2})))?/ =~ string
     
    343354          self.timezone = $8
    344355        end
     356      end
     357
     358      def <=>(other)
     359        magnitude = (nilthenzero(@hour)*60 + nilthenzero(@minute))*60 +
     360          nilthenzero(@second) +
     361          nilthenzero(@fractional_second)
     362        other_magnitude = (nilthenzero(other.hour) * 60 +
     363                           nilthenzero(other.minute)) * 60 +
     364          nilthenzero(other.second) +
     365          nilthenzero(other.fractional_second)
     366        magnitude <=> other_magnitude
    345367      end
    346368
Note: See TracChangeset for help on using the changeset viewer.