lib/glue/time.rb in glue-0.20.0 vs lib/glue/time.rb in glue-0.21.0

- old
+ new

@@ -1,8 +1,8 @@ # * George Moschovitis <gm@navel.gr> # (c) 2004-2005 Navel, all rights reserved. -# $Id: time.rb 1 2005-04-11 11:04:30Z gmosx $ +# $Id: time.rb 182 2005-07-22 10:07:50Z gmosx $ require 'time.rb' module Glue; @@ -18,68 +18,68 @@ # - SOS: add test units. # - add aliases for those methods in Kernel ? module TimeUtils - NOW = Time.now - NEVER = Time.mktime(2038) - ZERO = Time.mktime(1972) + NOW = Time.now + NEVER = Time.mktime(2038) + ZERO = Time.mktime(1972) - # Convert the time to a nice String representation. - - def self.date_time(time) - return nil unless time - return time.strftime("%d-%m-%Y %H:%M") - end - - # This method calculates the days extrema given two time objects. - # start time is the given time1 at 00:00:00 - # end time is the given time2 at 23:59:59:999 - # - # Input: - # - the two times (if only time1 is provided then you get an extrema - # of exactly one day extrema. - # - # Output - # - the time range. you can get the start/end times using - # range methods. - - def self.days_extrema(time1, time2=nil) - time2 = time1 if (not time2.valid? Time) - time2 = NEVER if (time2 <= time1) - start_time = Time.self.start_of_day(time1) - end_time = self.end_of_day(time2) - return (start_time..end_time) - end + # Convert the time to a nice String representation. + + def self.date_time(time) + return nil unless time + return time.strftime("%d-%m-%Y %H:%M") + end + + # This method calculates the days extrema given two time objects. + # start time is the given time1 at 00:00:00 + # end time is the given time2 at 23:59:59:999 + # + # Input: + # - the two times (if only time1 is provided then you get an extrema + # of exactly one day extrema. + # + # Output + # - the time range. you can get the start/end times using + # range methods. + + def self.days_extrema(time1, time2=nil) + time2 = time1 if (not time2.valid? Time) + time2 = NEVER if (time2 <= time1) + start_time = Time.self.start_of_day(time1) + end_time = self.end_of_day(time2) + return (start_time..end_time) + end - # Set time to start of day - - def self.start_of_day(time) - return Time.mktime(time.year, time.month, time.day, 0, 0, 0, 0) - end + # Set time to start of day + + def self.start_of_day(time) + return Time.mktime(time.year, time.month, time.day, 0, 0, 0, 0) + end - - # Set time to end of day - - def self.end_of_day(time) - return Time.mktime(time.year, time.month, time.day, 23, 59, 59, 999) - end + + # Set time to end of day + + def self.end_of_day(time) + return Time.mktime(time.year, time.month, time.day, 23, 59, 59, 999) + end - # Returns true only if day of time is included in the - # range (stime..etime). Only year days are checked. - - def self.time_in_day_range(time, stime=ZERO, etime=NEVER) - if (etime <= stime) - Logger.debug "Invalid end time (#{etime} < #{stime})" if $DBG - etime = NEVER - end + # Returns true only if day of time is included in the + # range (stime..etime). Only year days are checked. + + def self.time_in_day_range(time, stime=ZERO, etime=NEVER) + if (etime <= stime) + Logger.debug "Invalid end time (#{etime} < #{stime})" if $DBG + etime = NEVER + end - stime = start_of_day(stime) - etime = end_of_day(etime) + stime = start_of_day(stime) + etime = end_of_day(etime) - return (stime..etime).include?(time) - end + return (stime..etime).include?(time) + end end end