Module: Casualdate

Defined in:
lib/casualdate.rb,
lib/language.rb,
lib/casualdate/version.rb

Overview

The Casualdate module

Author:

  • Daniel Thwaites

Constant Summary collapse

VERSION =
'0.1.0-alpha'.freeze

Instance Method Summary collapse

Instance Method Details

#compare_dates(dateone, datetwo) ⇒ Boolean

Compares two date objects to see which one is later

Parameters:

  • dateone (Date)

    The first date, usually today

  • datetwo (Date)

    The second date

Returns:

  • (Boolean)

    True if the first date is earlier

Author:

  • Daniel Thwaites


36
37
38
# File 'lib/casualdate.rb', line 36

def compare_dates(dateone, datetwo)
  dateone < datetwo
end

#get_current_date_objectDate

Gets a Date object for today

Returns:

  • (Date)

    Today's Date object

Author:

  • Daniel Thwaites


14
15
16
# File 'lib/casualdate.rb', line 14

def get_current_date_object
  Date.today
end

#get_date_difference(dateone, datetwo) ⇒ Integer

Gets the difference between two Date objects

Parameters:

  • dateone (Date)

    The first date, usually today

  • datetwo (Date)

    The second date

Returns:

  • (Integer)

    Difference in days

Author:

  • Daniel Thwaites


25
26
27
# File 'lib/casualdate.rb', line 25

def get_date_difference(dateone, datetwo)
  (dateone - datetwo).abs
end

#get_language(direction, amount) ⇒ String

Gets a piece of language based on how many days difference there is, and whether that is backwards or forwards.

Parameters:

  • direction (Boolean)

    True if the date is in the future

  • amount (Integer)

    The amount of days difference

Returns:

  • (String)

    Language for the day

Author:

  • Daniel Thwaites


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
# File 'lib/language.rb', line 10

def get_language(direction, amount)
  return 'today' if amount == 0
  if direction
    # Future
    if amount == 1
      return 'tomorrow'
    elsif amount == 2
      return 'the day after tomorrow'
    elsif amount == 6
      return 'yesterday next week'
    elsif amount == 7
      return 'this day next week'
    elsif amount == 8
      return 'tomorrow next week'
    else
      return 'in ' + amount.to_s + ' days'
    end
  else
    # Past
    if amount == 1
      return 'yesterday'
    elsif amount == 2
      return 'the day before yesterday'
    elsif amount == 6
      return 'tomorrow last week'
    elsif amount == 7
      return 'this day last week'
    elsif amount == 8
      return 'yesterday last week'
    else
      return amount.to_s + ' days ago'
    end
  end
end