Module: GoogleApi::Date

Defined in:
lib/google_api/date.rb

Constant Summary collapse

DATE_FORMAT =
/\A[0-9]{4}-[0-9]{2}-[0-9]{2}\Z/

Instance Method Summary collapse

Instance Method Details

#day_older?(date) ⇒ Boolean

Returns:

  • (Boolean)


44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/google_api/date.rb', line 44

def day_older?(date)
  
  if date.is_a?(String)
    date = Date.parse(date)
  end

  if (Date.today <=> date.to_date) > 0
    return true
  end

  return false
end

#more_months?(d1, d2) ⇒ Boolean

Returns:

  • (Boolean)


28
29
30
31
32
33
34
# File 'lib/google_api/date.rb', line 28

def more_months?(d1, d2)

  d1 = Date.parse(d1) if d1.is_a?(String)
  d2 = Date.parse(d2) if d2.is_a?(String)

  d1.month != d2.month
end

#more_years?(d1, d2) ⇒ Boolean

Returns:

  • (Boolean)


36
37
38
39
40
41
42
# File 'lib/google_api/date.rb', line 36

def more_years?(d1, d2)

  d1 = Date.parse(d1) if d1.is_a?(String)
  d2 = Date.parse(d2) if d2.is_a?(String)

  d1.year != d2.year
end

#nowObject



20
21
22
# File 'lib/google_api/date.rb', line 20

def now
  Date.today
end

#prev_monthObject



24
25
26
# File 'lib/google_api/date.rb', line 24

def prev_month
  Date.today.prev_month
end

#to_date(date) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/google_api/date.rb', line 8

def to_date(date)
  if date.is_a?(String)
    unless date =~ DATE_FORMAT
      raise GoogleApi::DateError, "Date: #{date} must match with #{DATE_FORMAT}."
    end

    date = Date.parse(date)
  end

  date.to_date
end