summaryrefslogtreecommitdiff
path: root/lib/leap_cli/x509/utils.rb
blob: 98ff9c0b7fe9c073f7d612d868f5703afefdb0d0 (plain)
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
module LeapCli; module X509

  #
  # TIME HELPERS
  #
  # note: we use 'yesterday' instead of 'today', because times are in UTC, and
  # some people on the planet are behind UTC!
  #

  def self.yesterday
    t = Time.now - 24*24*60
    Time.utc t.year, t.month, t.day
  end

  def self.yesterday_advance(string)
    number, unit = string.split(' ')
    unless ['years', 'months', 'days', 'hours', 'minutes'].include? unit
      bail!("The time property '#{string}' is missing a unit (one of: years, months, days, hours, minutes).")
    end
    unless number.to_i.to_s == number
      bail!("The time property '#{string}' is missing a number.")
    end
    yesterday.advance(unit.to_sym => number.to_i)
  end

end; end