module TimeStep::DateTimeExt
Public Instance Methods
compare_d(other)
click to toggle source
# File lib/timesteps/timestep_datetime_ext.rb, line 33 def compare_d (other) sday = self.day + self.fraction + self.offset oday = other.day + other.fraction + other.offset if sday > oday return 1 elsif sday < oday return -1 else return 0 end end
compare_md(other)
click to toggle source
# File lib/timesteps/timestep_datetime_ext.rb, line 15 def compare_md (other) sday = self.day + self.fraction + self.offset oday = other.day + other.fraction + other.offset if self.month > other.month return 1 elsif self.month < other.month return -1 else if sday > oday return 1 elsif sday < oday return -1 else return 0 end end end
difference_in_months(other)
click to toggle source
Calculate difference between the object and other object in months.
@return [Integer]
# File lib/timesteps/timestep_datetime_ext.rb, line 57 def difference_in_months (other) my = self other = other.new_offset(self.offset) return 12*(my.year - other.year) + my.month - other.month + my.compare_d(other).quo(2) end
difference_in_years(other)
click to toggle source
Calculate difference between the object and other object in years.
@return [Integer]
# File lib/timesteps/timestep_datetime_ext.rb, line 48 def difference_in_years (other) my = self other = other.new_offset(self.offset) return my.year - other.year + my.compare_md(other).quo(2) end
fraction()
click to toggle source
Returns time fraction in day units.
@return [Rational]
# File lib/timesteps/timestep_datetime_ext.rb, line 11 def fraction () return (60*(60*hour + minute) + second + second_fraction).quo(86400) end