Class: DateTime

Inherits:
Object
  • Object
show all
Defined in:
lib/abstractive/timespans.rb

Instance Method Summary collapse

Instance Method Details

#+(x) ⇒ Object



103
104
105
106
107
108
109
110
111
# File 'lib/abstractive/timespans.rb', line 103

def +(x)
   case x
     when Days;      return Abstractive::TimeSpans.plus_span(self, x.to_seconds)
     when Hours;     return DateTime.new(year, month, day, hour+x.to_i, min, sec, strftime("%:z"))
     when Minutes;   return DateTime.new(year, month, day, hour, min+x.to_i, sec, strftime("%:z"))
     when Seconds;   return DateTime.new(year, month, day, hour, min, sec+x.to_i, strftime("%:z"))
     else;           return self.old_add(x)
   end
end

#-(x) ⇒ Object



94
95
96
97
98
99
100
101
102
# File 'lib/abstractive/timespans.rb', line 94

def -(x)
   case x
     when Days;      return Abstractive::TimeSpans.minus_span(self, x.to_seconds)
     when Hours;     return DateTime.new(year, month, day, hour-x.to_i, min, sec, strftime("%:z"))
     when Minutes;   return DateTime.new(year, month, day, hour, min-x.to_i, sec, strftime("%:z"))
     when Seconds;   return DateTime.new(year, month, day, hour, min, sec-x.to_i, strftime("%:z"))
     else;           return self.old_subtract(x)
   end
end

#old_addObject



93
# File 'lib/abstractive/timespans.rb', line 93

alias old_add +

#old_subtractObject



92
# File 'lib/abstractive/timespans.rb', line 92

alias old_subtract -