summaryrefslogtreecommitdiff
path: root/vendor/certificate_authority/lib/certificate_authority/core_extensions.rb
blob: 0508f9a2278561088fe7c3fec42ce12cb9e99552 (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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#
# ActiveSupport has these modifications. Now that we don't use ActiveSupport,
# these are added here as a kindness.
#

require 'date'

unless nil.respond_to?(:blank?)
  class NilClass
    def blank?
      true
    end
  end
end

unless String.respond_to?(:blank?)
  class String
    def blank?
      self.empty?
    end
  end
end

class Date

  def today
    t = Time.now.utc
    Date.new(t.year, t.month, t.day)
  end

  def utc
    self.to_datetime.to_time.utc
  end

  unless Date.respond_to?(:advance)
    def advance(options)
      options = options.dup
      d = self
      d = d >> options.delete(:years) * 12 if options[:years]
      d = d >> options.delete(:months)     if options[:months]
      d = d +  options.delete(:weeks) * 7  if options[:weeks]
      d = d +  options.delete(:days)       if options[:days]
      d
    end
  end
end