-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdate.rb
35 lines (31 loc) · 903 Bytes
/
date.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# Add more extensions to Date beyond those provided by "active_support/core_ext/date"
class Date
def before?(date, inclusive=false)
!!(self < date) unless inclusive
!!(self <= date)
end
def after?(date, inclusive=false)
return !!(self > date) unless inclusive
!!(self >= date)
end
def on_or_after?(date)
after?(date, true)
end
def on_or_before?(date)
before?(date, true)
end
def between?(start_date, end_date, inclusive='()')
case inclusive
when '[]'
return !!(on_or_after?(start_date) && on_or_before?(end_date))
when '(]'
return !!(after?(start_date) && on_or_before?(end_date))
when '[)'
return !!(on_or_after?(start_date) && before?(end_date))
when '()'
return !!(after?(start_date) && before?(end_date))
else
return !!(after?(start_date) && before?(end_date))
end
end
end