zeus.ugent.be/lib/helpers/time.rb

24 lines
644 B
Ruby
Raw Normal View History

2016-12-29 13:37:22 +01:00
module TimeHelper
def christmastime?
2017-02-09 02:31:56 +01:00
timehelper([[Time.new(Time.now.year, 12, 6), Time.new(Time.now.year, 12, 31)]])
2017-02-06 14:15:06 +01:00
end
def studytime?
year = Time.now.year
timehelper([
2017-02-09 02:31:56 +01:00
[Time.new(year, 12, 14), Time.new(year, 12, 31)],
[Time.new(year, 1, 1), Time.new(year, 2, 7)],
[Time.new(year, 5, 15), Time.new(year, 6, 30)],
[Time.new(year, 8, 5), Time.new(year, 9, 10)]
])
2017-02-06 14:15:06 +01:00
end
def timehelper(ranges)
2017-02-09 02:31:56 +01:00
ranges.any? { |range| periodhelper(*range) }
2017-02-06 14:15:06 +01:00
end
def periodhelper(startdate, enddate)
Time.now.between?(startdate, enddate)
2016-12-29 13:37:22 +01:00
end
end