Module: Timely::Date

Included in:
Date
Defined in:
lib/timely/date.rb

Instance Method Summary collapse

Instance Method Details

#at_time(hour = nil, minute = nil, second = nil) ⇒ Object Also known as: at



5
6
7
8
9
10
11
12
13
14
# File 'lib/timely/date.rb', line 5

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

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

#between?(from, to) ⇒ Boolean

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

Returns:

  • (Boolean)


23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/timely/date.rb', line 23

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