Sha256: 2e3216293b787a4151b3471706c1ab269fbde3af8eb2654e29a8b0b69fd26127

Contents?: true

Size: 953 Bytes

Versions: 8

Compression:

Stored size: 953 Bytes

Contents

module Timely
  module Date
    def at_time(hour = nil, minute = nil, second = nil)
      if hour.is_a?(::Time)
        time = hour
        hour, minute, second = time.hour, time.min, time.sec
      end

      ::Time.local(year, month, day, hour, minute, second)
    end

    alias_method :at, :at_time

    # returns true if date between from and to
    # however if from and/or to are nil, it ignores that query
    # e.g. date.between?(from, nil) is "date > from",
    #      date.between?(from, nil) is "date < to"
    #      date.between?(nil, nil)  is true
    def between?(from, to)
      from = from.to_date if from && !from.is_a?(Date)
      to   = to.to_date if to && !to.is_a?(Date)

      if from && to
        self >= from && self <= to
      elsif from
        self >= from
      elsif to
        self <= to
      else
        true # i.e. no restrictive range return true
      end
    end
  end
end

class Date
  include Timely::Date
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
timely-0.5.0 lib/timely/date.rb
timely-0.4.2 lib/timely/date.rb
timely-0.4.1 lib/timely/date.rb
timely-0.4.0 lib/timely/date.rb
timely-0.3.4 lib/timely/date.rb
timely-0.3.2 lib/timely/date.rb
timely-0.3.1 lib/timely/date.rb
timely-0.3.0 lib/timely/date.rb