]> jaekl.net Git - oct_sched.git/blob - lib/date_utils.rb
Add basic reporting on cancellations and annual (scheduled) trip totals.
[oct_sched.git] / lib / date_utils.rb
1 # frozen_string_literal: true
2
3 require "date"
4 require "pry"
5
6 class DateUtils
7   def initialize
8   end
9
10   def date_for(date_hash)
11     "#{date_hash[:year]}#{date_hash[:month].to_s.rjust(2, "0")}#{date_hash[:day].to_s.rjust(2, "0")}"
12   end
13
14   def hyphenated_date_for(date_hash)
15     "#{date_hash[:year]}-#{date_hash[:month].to_s.rjust(2, "0")}-#{date_hash[:day].to_s.rjust(2, "0")}"
16   end
17
18   def today
19     # Beware:  This assumes your system is in America/Toronto time.
20     now = Date.today
21     {
22       year: now.year,
23       month: now.month,
24       day: now.day,
25     }
26   end
27
28   def weekday_for(date_hash)
29     Date.new(date_hash[:year], date_hash[:month], date_hash[:day]).wday
30   end
31 end