datey 1.0.1 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/datey/formatter.rb +36 -29
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4c021b138f9ffc9f5120511ea6475344f9d5a857
4
- data.tar.gz: 9104ed36edc2508bf3528273e6351df06a2b8081
3
+ metadata.gz: 945c401e07ea2b21c51056482e42e2aaa47c4d51
4
+ data.tar.gz: cc7b40742f06334ca2fac9f892d965b839c58c63
5
5
  SHA512:
6
- metadata.gz: 27a9baed1791e3ff02905d3556372bb1fe1e1ffdf399ccbf90ee1d60a4f0da7e000a853bdf64d4cb8d8db024a9a8b37140c34daf78373751df02e051510d396a
7
- data.tar.gz: 8c7a17904134ec19e0d9eda890386c4fae44a44a5d59b4de3b25f3bce688200163d17e9d16fcc292d5942af34156d4c42bdf7ea9f70dc8cdcf3942bae0636bc4
6
+ metadata.gz: 8eb14d6c0edb6765b8810deb82ced3873911cd357678dfdb2242a944ca7af1cc7016f31c694db1dac3b7749dc5e1401fcda9a1192cbb479e5db9282259fd4029
7
+ data.tar.gz: 56ed4a11fcb83f1a4185b05075394f71344101b4d8aa425d0e210c040c06bd631ceb7e28cbe76d94077ee21bbb256b13983b5f856419def5fa6425d0d031190f
@@ -8,52 +8,59 @@ module Datey
8
8
  @time = time
9
9
  @context = context
10
10
  end
11
-
11
+
12
12
  #
13
13
  # Return the date and time
14
14
  #
15
- def date_and_time
16
- @time.is_a?(Time) ? "#{date} at #{time}" : date
15
+ def date_and_time(options = {})
16
+ @time.is_a?(Time) ? "#{date(options)} at #{time(options)}" : date(options = {})
17
17
  end
18
-
19
- #
18
+
19
+ #
20
20
  # Return the time nicely
21
21
  #
22
- def time
22
+ def time(options = {})
23
23
  if @time.is_a?(Time)
24
24
  @time.strftime("%l#{@time.min > 0 ? ":%M" : ''}%P").strip
25
25
  else
26
26
  nil
27
27
  end
28
28
  end
29
-
29
+
30
30
  #
31
31
  # Return the formatted date (no time)
32
32
  #
33
- def date
33
+ def date(options = {})
34
+ non_relative_prefix = options[:non_relative_prefix] || "on "
34
35
  if interrogator.today?
35
- "Today"
36
+ result = "today"
36
37
  elsif interrogator.yesterday?
37
- "Yesterday"
38
+ result = "yesterday"
38
39
  elsif interrogator.tomorrow?
39
- "Tomorrow"
40
+ result = "tomorrow"
40
41
  elsif @context == :future && interrogator.next_x_days?(6)
41
- name_of_day
42
+ result = non_relative_prefix + name_of_day
42
43
  elsif @context == :future && interrogator.next_week?
43
- "Next #{name_of_day}"
44
+ result = "next #{name_of_day}"
44
45
  elsif @context == :past && interrogator.last_x_days?(6)
45
- name_of_day
46
+ result = non_relative_prefix + name_of_day
46
47
  elsif @context == :past && interrogator.last_x_days?(12)
47
- "Last #{name_of_day}"
48
+ result = "last #{name_of_day}"
48
49
  elsif @context == :past && interrogator.next_x_days?(6)
49
- "Next #{name_of_day}"
50
+ result = "next #{name_of_day}"
50
51
  else
51
- string = "#{name_of_day} #{day_of_month} #{name_of_month}"
52
- string += " #{@time.year}" if include_year_in_dates?
53
- string
52
+ result = non_relative_prefix + "#{name_of_day} #{day_of_month} #{name_of_month}"
53
+ result += " #{@time.year}" if include_year_in_dates?
54
+ result
54
55
  end
56
+
57
+ unless options[:capitalize] == false
58
+ result[0] = result[0].upcase
59
+ end
60
+
61
+ result
55
62
  end
56
-
63
+
57
64
  #
58
65
  # Return the day of the month ordinalized
59
66
  #
@@ -66,45 +73,45 @@ module Datey
66
73
  end
67
74
  "#{@time.day}#{ordinal}"
68
75
  end
69
-
76
+
70
77
  #
71
78
  # Return the name of the day
72
79
  #
73
80
  def name_of_day(style = :full)
74
81
  @time.strftime(style == :full ? "%A" : "%a")
75
82
  end
76
-
83
+
77
84
  #
78
85
  # Return the name of the month
79
86
  #
80
87
  def name_of_month(style = :full)
81
88
  @time.strftime(style == :full ? "%B" : "%b")
82
89
  end
83
-
90
+
84
91
  private
85
-
92
+
86
93
  #
87
94
  # Return an interrogator object for the date we're formatting
88
95
  #
89
96
  def interrogator
90
97
  @interrogator ||= Interrogator.new(@time.to_date)
91
98
  end
92
-
99
+
93
100
  #
94
101
  # Should years be included in dates?
95
102
  #
96
103
  def include_year_in_dates?
97
104
  if @time.year != Date.today.year
98
- # If the year was in the past, always include the year
105
+ # If the year was in the past, always include the year
99
106
  return true
100
107
  end
101
-
108
+
102
109
  if @time.year == Date.today.year && @time.month < (Date.today.month - 4)
103
110
  # If the year is this year, include if it happened more than 6 months
104
111
  # ago.
105
112
  return true
106
113
  end
107
114
  end
108
-
115
+
109
116
  end
110
- end
117
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: datey
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Cooke
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-17 00:00:00.000000000 Z
11
+ date: 2015-04-15 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A Ruby library for formatting & interrogating dates & times
14
14
  email: