Included Modules

Class Index [+]

Quicksearch

When::TM::PeriodDuration

ISO 8601 (JIS X0301) の時間間隔に基づいて定義された When::TM::Duration の subclass

Attributes

date[RW]

期間の日付要素

  type : [Numeric]
week[RW]

期間の週日要素

  type : [Numeric]
time[RW]

期間の時刻要素

  type : [Numeric]

Public Class Methods

new(*args) click to toggle source

オブジェクトの生成

  引数パターン1
    date  : [Numeric]
      期間の日付要素
    time  : [Numeric]
      期間の時刻要素
    week  : [Numeric]
      期間の週日要素

  引数パターン2
    value : Numeric
        (index に対応する桁での)時間間隔
    index : Numeric
      When::Coordinates で定義している分解能定数に対応する列挙型
        YEAR, ... ,SECOND
    range : Range
      生成する桁の範囲(デフォルト : YEAR..SECOND)
      # File when/tmobjects.rb, line 1090
1090:     def initialize(*args)
1091:       @options = (args[1].kind_of?(Hash)) ? (args.pop.reject {|key,value| value == nil}) : {}
1092: 
1093:       unless args[0].kind_of?(Numeric)
1094:         @date, @time, @week = args
1095:         return
1096:       end
1097: 
1098:       value, index, range = args
1099:       range = YEAR..SECOND unless (range)
1100:       max   = range.first
1101:       min   = range.last
1102:       min  += 1 if (range.exclude_end?)
1103:       if (index < max)
1104:         if (index > MONTH)
1105:           max    = index.floor
1106:         else
1107:           value *= 10**(max-index)
1108:           index  = max
1109:         end
1110:       elsif (index > min)
1111:         if (index <= DAY)
1112:           min    = index.ceil
1113:         else
1114:           value *= 0.1**(index-min)
1115:           index  = min
1116:         end
1117:       end
1118:       value = value.to_i unless value.kind_of?(Pair) || value.to_i != value.to_f
1119:       @date = Array.new(1-max, 0) if (max <= DAY) && (index <= DAY)
1120:       @time = Array.new(1+min, 0) if (min >  DAY) && (index  > DAY)
1121:       if (index == WEEK)
1122:         @week    = [value, 0]
1123:         @date[DAY-1] = 7 * value
1124:       elsif (index <= DAY)
1125:         @date[index-1] = value
1126:       else
1127:         @time[index]   = value
1128:       end
1129:     end

Public Instance Methods

*(times) click to toggle source

乗算

  times   : Numeric

  returns : When::TM::PeriodDuration
      # File when/tmobjects.rb, line 1003
1003:     def *(times)
1004:       period = self.dup
1005:       period.date = @date.map {|v| times * v} if @date
1006:       period.week = @week.map {|v| times * v} if @week
1007:       period.time = @time.map {|v| times * v} if @time
1008:       return period
1009:     end
-@() click to toggle source

符号反転

  returns : When::TM::PeriodDuration
      # File when/tmobjects.rb, line 1039
1039:     def -@
1040:       period = self.dup
1041:       period.date = @date.map {|v| -v} if @date
1042:       period.week = @week.map {|v| -v} if @week
1043:       period.time = @time.map {|v| -v} if @time
1044:       return period
1045:     end
[](index) click to toggle source

要素の参照

  index   : Numeric
    When::Coordinates で定義している分解能定数に対応する列挙型
      YEAR, ... ,SECOND
  returns : Numeric
     # File when/tmobjects.rb, line 904
904:     def [](index)
905:       if (index == WEEK)
906:         return nil unless (@week)
907:         return @week[0]
908:       elsif (index <= 0)
909:         return nil unless (@date)
910:         return @date[index-1]
911:       else
912:         return nil unless (@time)
913:         return @time[index]
914:       end
915:     end
days() click to toggle source

期間に含まれる日数を示す

  type : Numeric
     # File when/tmobjects.rb, line 956
956:     def days
957:       return nil unless (@date)
958:       return @date[DAY-1].to_s
959:     end
designator() click to toggle source

持続期間であることを文字’P’で示す

  type : String
     # File when/tmobjects.rb, line 921
921:     def designator
922:       return 'P'
923:     end
hours() click to toggle source

期間に含まれる時間数を示す

  type : Numeric
     # File when/tmobjects.rb, line 974
974:     def hours
975:       return nil unless (@time)
976:       return @time[HOUR].to_s
977:     end
minutes() click to toggle source

期間に含まれる分数を示す

  type : Numeric
     # File when/tmobjects.rb, line 983
983:     def minutes
984:       return nil unless (@time)
985:       return @time[MINUTE].to_s
986:     end
months() click to toggle source

期間に含まれる月数を示す

  type : Numeric
     # File when/tmobjects.rb, line 938
938:     def months
939:       return nil unless (@date)
940:       return @date[MONTH-1].to_s
941:     end
seconds() click to toggle source

期間に含まれる秒数を示す

  type : Numeric
     # File when/tmobjects.rb, line 992
992:     def seconds
993:       return nil unless (@time)
994:       return @time[SECOND].to_s
995:     end
sign() click to toggle source

符号

  returns : Integer
    0 との比較により、負,0,正の値を返す
      # File when/tmobjects.rb, line 1016
1016:     def sign
1017:      if @week
1018:        @week.each do |w|
1019:          return 1 if +w < 0
1020:        end
1021:      end
1022:      if @date
1023:        @date.each do |d|
1024:          return 1 if +d < 0
1025:        end
1026:      end
1027:      if @time
1028:        @time.each do |t|
1029:          return 1 if +t < 0
1030:        end
1031:      end
1032:      return 1
1033:     end
timeIndicator() click to toggle source
Alias for: time_indicator
time_indicator() click to toggle source

期間が1日より短い時間単位を含むとき文字’T’で示す

  type : String
     # File when/tmobjects.rb, line 965
965:     def time_indicator
966:       return (@time) ? 'T' : nil
967:     end
Also aliased as: timeIndicator
to_s() click to toggle source

文字列化

  returns : String
      # File when/tmobjects.rb, line 1051
1051:     def to_s
1052:      period = 'P'
1053:      if @week
1054:        period += @week[0].abs.to_s + 'W'
1055:        period += @week[1].abs.to_s + 'D' unless @week[1] == 0
1056:      elsif @date
1057:        (-@date.length..1).each do |i|
1058:          period += @date[i].abs.to_s + PRECISION_NAME[i+1][0..0] unless @date[i] == 0
1059:        end
1060:      end
1061:      if @time
1062:        period += 'T'
1063:        (1..@time.length-1).each do |i|
1064:          period += @time[i].abs.to_s + PRECISION_NAME[i][0..0] unless @time[i] == 0
1065:        end
1066:      end
1067:      period = '-' + period if sign < 0
1068:      return period
1069:     end
weeks() click to toggle source

期間に含まれる週数を示す

  type : Numeric
     # File when/tmobjects.rb, line 947
947:     def weeks
948:       return nil unless (@week)
949:       return @week[0].to_s
950:     end
years() click to toggle source

期間に含まれる年数を示す

  type : Numeric
     # File when/tmobjects.rb, line 929
929:     def years
930:       return nil unless (@date)
931:       return @date[YEAR-1].to_s
932:     end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.