datey 1.0.1 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/datey/formatter.rb +36 -29
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 945c401e07ea2b21c51056482e42e2aaa47c4d51
|
4
|
+
data.tar.gz: cc7b40742f06334ca2fac9f892d965b839c58c63
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8eb14d6c0edb6765b8810deb82ced3873911cd357678dfdb2242a944ca7af1cc7016f31c694db1dac3b7749dc5e1401fcda9a1192cbb479e5db9282259fd4029
|
7
|
+
data.tar.gz: 56ed4a11fcb83f1a4185b05075394f71344101b4d8aa425d0e210c040c06bd631ceb7e28cbe76d94077ee21bbb256b13983b5f856419def5fa6425d0d031190f
|
data/lib/datey/formatter.rb
CHANGED
@@ -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
|
-
"
|
36
|
+
result = "today"
|
36
37
|
elsif interrogator.yesterday?
|
37
|
-
"
|
38
|
+
result = "yesterday"
|
38
39
|
elsif interrogator.tomorrow?
|
39
|
-
"
|
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
|
-
"
|
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
|
-
"
|
48
|
+
result = "last #{name_of_day}"
|
48
49
|
elsif @context == :past && interrogator.next_x_days?(6)
|
49
|
-
"
|
50
|
+
result = "next #{name_of_day}"
|
50
51
|
else
|
51
|
-
|
52
|
-
|
53
|
-
|
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
|
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:
|
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:
|