condensation 1.2.0 → 1.3.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.
- checksums.yaml +4 -4
- data/LICENSE.txt +1 -1
- data/lib/condensation/filters/days_since.rb +3 -1
- data/lib/condensation/filters/days_until.rb +3 -1
- data/lib/condensation/filters/weeks_since.rb +24 -0
- data/lib/condensation/filters/weeks_until.rb +24 -0
- data/lib/condensation/filters.rb +2 -0
- data/lib/condensation/version.rb +1 -1
- data/lib/condensation.rb +3 -1
- data/spec/condensation/filters/days_until_spec.rb +1 -1
- data/spec/condensation/filters/weeks_since_spec.rb +68 -0
- data/spec/condensation/filters/weeks_until_spec.rb +75 -0
- metadata +8 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 39333154e19007dc82061393ece503e3da8b5904
|
4
|
+
data.tar.gz: af24e07e4f2a0a3541f36e5d11e879e0a28c8111
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1ee704b9cc8b14be441ddea8b36c1c3fc6314f02ba8f62dbfba4f6f1bffc764bab9c4ba9a611a1caa49701a41de21232b2a88637178e4c3cf252f19b2be00872
|
7
|
+
data.tar.gz: 79d694031a622e764e1701cf5d2e9a577aa96b8c4b2d46e0d8b6e559241048137e489163c7eeca4fe6726a633306ba139224ba904be5493882837448233e6a9c
|
data/LICENSE.txt
CHANGED
@@ -3,6 +3,8 @@ require 'time'
|
|
3
3
|
module Condensation
|
4
4
|
module Filters
|
5
5
|
module DaysSince
|
6
|
+
SECONDS_PER_DAY = 86400
|
7
|
+
|
6
8
|
def days_since(input)
|
7
9
|
return if input.nil?
|
8
10
|
|
@@ -15,7 +17,7 @@ module Condensation
|
|
15
17
|
return unless value.is_a?(Time)
|
16
18
|
|
17
19
|
diff = Time.now - value
|
18
|
-
[diff.to_i /
|
20
|
+
[diff.to_i / SECONDS_PER_DAY, 0].max
|
19
21
|
end
|
20
22
|
end
|
21
23
|
end
|
@@ -3,6 +3,8 @@ require 'time'
|
|
3
3
|
module Condensation
|
4
4
|
module Filters
|
5
5
|
module DaysUntil
|
6
|
+
SECONDS_PER_DAY = 86400
|
7
|
+
|
6
8
|
def days_until(input)
|
7
9
|
return if input.nil?
|
8
10
|
|
@@ -15,7 +17,7 @@ module Condensation
|
|
15
17
|
return unless value.is_a?(Time)
|
16
18
|
|
17
19
|
diff = value - Time.now
|
18
|
-
[diff.to_i /
|
20
|
+
[diff.to_i / SECONDS_PER_DAY, 0].max
|
19
21
|
end
|
20
22
|
end
|
21
23
|
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'time'
|
2
|
+
|
3
|
+
module Condensation
|
4
|
+
module Filters
|
5
|
+
module WeeksSince
|
6
|
+
SECONDS_PER_WEEK = 86400 * 7
|
7
|
+
|
8
|
+
def weeks_since(input)
|
9
|
+
return if input.nil?
|
10
|
+
|
11
|
+
if input.is_a?(Time)
|
12
|
+
value = input
|
13
|
+
else
|
14
|
+
value = Time.parse(input) rescue nil
|
15
|
+
end
|
16
|
+
|
17
|
+
return unless value.is_a?(Time)
|
18
|
+
|
19
|
+
diff = Time.now - value
|
20
|
+
[diff.to_i / SECONDS_PER_WEEK, 0].max
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'time'
|
2
|
+
|
3
|
+
module Condensation
|
4
|
+
module Filters
|
5
|
+
module WeeksUntil
|
6
|
+
SECONDS_PER_WEEK = 86400 * 7
|
7
|
+
|
8
|
+
def weeks_until(input)
|
9
|
+
return if input.nil?
|
10
|
+
|
11
|
+
if input.is_a?(Time)
|
12
|
+
value = input
|
13
|
+
else
|
14
|
+
value = Time.parse(input) rescue nil
|
15
|
+
end
|
16
|
+
|
17
|
+
return unless value.is_a?(Time)
|
18
|
+
|
19
|
+
diff = value - Time.now
|
20
|
+
[diff.to_i / SECONDS_PER_WEEK, 0].max
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/lib/condensation/filters.rb
CHANGED
@@ -9,3 +9,5 @@ require "condensation/filters/advance_date_to_next"
|
|
9
9
|
require "condensation/filters/at_midnight"
|
10
10
|
require "condensation/filters/in_time_zone"
|
11
11
|
require "condensation/filters/timestamp"
|
12
|
+
require "condensation/filters/weeks_since"
|
13
|
+
require "condensation/filters/weeks_until"
|
data/lib/condensation/version.rb
CHANGED
data/lib/condensation.rb
CHANGED
@@ -61,7 +61,7 @@ describe Condensation::Filters::DaysUntil do
|
|
61
61
|
|
62
62
|
it "should handle empty string input" do
|
63
63
|
created_at = ""
|
64
|
-
template = Liquid::Template.parse("{{ created_at |
|
64
|
+
template = Liquid::Template.parse("{{ created_at | days_until }}")
|
65
65
|
result = render_with_filter(template, { "created_at" => created_at })
|
66
66
|
result.must_equal ""
|
67
67
|
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../../spec_helper.rb'
|
2
|
+
|
3
|
+
describe Condensation::Filters::WeeksSince do
|
4
|
+
def render_with_filter(template, context)
|
5
|
+
template.render(context, :filters => [Condensation::Filters::WeeksSince])
|
6
|
+
end
|
7
|
+
|
8
|
+
let(:now) do
|
9
|
+
Time.utc(2014, 5, 30, 0, 0, 0)
|
10
|
+
end
|
11
|
+
|
12
|
+
before do
|
13
|
+
Timecop.freeze(now)
|
14
|
+
end
|
15
|
+
|
16
|
+
after do
|
17
|
+
Timecop.return
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should handle UTC ISO 8601 dates" do
|
21
|
+
created_at = "2014-05-15T10:00:00Z"
|
22
|
+
template = Liquid::Template.parse("{{ created_at | weeks_since }}")
|
23
|
+
result = render_with_filter(template, { "created_at" => created_at })
|
24
|
+
result.must_equal "2"
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should handle non-UTC ISO 8601 dates" do
|
28
|
+
created_at = "2014-05-15T20:00:00-07:00"
|
29
|
+
template = Liquid::Template.parse("{{ created_at | weeks_since }}")
|
30
|
+
result = render_with_filter(template, { "created_at" => created_at })
|
31
|
+
result.must_equal "1"
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should handle Time input" do
|
35
|
+
created_at = Time.utc(2014, 5, 1, 0, 0, 0)
|
36
|
+
template = Liquid::Template.parse("{{ created_at | weeks_since }}")
|
37
|
+
result = render_with_filter(template, { "created_at" => created_at })
|
38
|
+
result.must_equal "4"
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should handle malformed dates" do
|
42
|
+
created_at = "foo"
|
43
|
+
template = Liquid::Template.parse("{{ created_at | weeks_since }}")
|
44
|
+
result = render_with_filter(template, { "created_at" => created_at })
|
45
|
+
result.must_equal ""
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should be zero for times in the future" do
|
49
|
+
created_at = "2014-06-01T20:00:00Z"
|
50
|
+
template = Liquid::Template.parse("{{ created_at | weeks_since }}")
|
51
|
+
result = render_with_filter(template, { "created_at" => created_at })
|
52
|
+
result.must_equal "0"
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should handle empty string input" do
|
56
|
+
created_at = ""
|
57
|
+
template = Liquid::Template.parse("{{ created_at | weeks_since }}")
|
58
|
+
result = render_with_filter(template, { "created_at" => created_at })
|
59
|
+
result.must_equal ""
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should handle nil input" do
|
63
|
+
created_at = nil
|
64
|
+
template = Liquid::Template.parse("{{ created_at | weeks_since }}")
|
65
|
+
result = render_with_filter(template, { "created_at" => created_at })
|
66
|
+
result.must_equal ""
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../../spec_helper.rb'
|
2
|
+
|
3
|
+
describe Condensation::Filters::WeeksUntil do
|
4
|
+
def render_with_filter(template, context)
|
5
|
+
template.render(context, :filters => [Condensation::Filters::WeeksUntil])
|
6
|
+
end
|
7
|
+
|
8
|
+
let(:now) do
|
9
|
+
Time.utc(2014, 5, 15, 0, 0, 0)
|
10
|
+
end
|
11
|
+
|
12
|
+
before do
|
13
|
+
Timecop.freeze(now)
|
14
|
+
end
|
15
|
+
|
16
|
+
after do
|
17
|
+
Timecop.return
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should handle UTC ISO 8601 dates" do
|
21
|
+
created_at = "2014-05-30T10:00:00Z"
|
22
|
+
template = Liquid::Template.parse("{{ created_at | weeks_until }}")
|
23
|
+
result = render_with_filter(template, { "created_at" => created_at })
|
24
|
+
result.must_equal "2"
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should handle non-UTC ISO 8601 dates" do
|
28
|
+
created_at = "2014-05-30T20:00:00-07:00"
|
29
|
+
template = Liquid::Template.parse("{{ created_at | weeks_until }}")
|
30
|
+
result = render_with_filter(template, { "created_at" => created_at })
|
31
|
+
result.must_equal "2"
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should handle YMD formatted dates" do
|
35
|
+
created_at = "2014-05-30"
|
36
|
+
template = Liquid::Template.parse("{{ created_at | weeks_until }}")
|
37
|
+
result = render_with_filter(template, { "created_at" => created_at })
|
38
|
+
result.must_equal "2"
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should handle Time input" do
|
42
|
+
created_at = Time.utc(2014, 6, 15, 0, 0, 0)
|
43
|
+
template = Liquid::Template.parse("{{ created_at | weeks_until }}")
|
44
|
+
result = render_with_filter(template, { "created_at" => created_at })
|
45
|
+
result.must_equal "4"
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should handle malformed dates" do
|
49
|
+
created_at = "foo"
|
50
|
+
template = Liquid::Template.parse("{{ created_at | weeks_until }}")
|
51
|
+
result = render_with_filter(template, { "created_at" => created_at })
|
52
|
+
result.must_equal ""
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should be zero for days in the past" do
|
56
|
+
created_at = "2014-05-01T20:00:00Z"
|
57
|
+
template = Liquid::Template.parse("{{ created_at | weeks_until }}")
|
58
|
+
result = render_with_filter(template, { "created_at" => created_at })
|
59
|
+
result.must_equal "0"
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should handle empty string input" do
|
63
|
+
created_at = ""
|
64
|
+
template = Liquid::Template.parse("{{ created_at | weeks_until }}")
|
65
|
+
result = render_with_filter(template, { "created_at" => created_at })
|
66
|
+
result.must_equal ""
|
67
|
+
end
|
68
|
+
|
69
|
+
it "should handle nil input" do
|
70
|
+
created_at = nil
|
71
|
+
template = Liquid::Template.parse("{{ created_at | weeks_until }}")
|
72
|
+
result = render_with_filter(template, { "created_at" => created_at })
|
73
|
+
result.must_equal ""
|
74
|
+
end
|
75
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: condensation
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Derrick Reimer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-02-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -127,6 +127,8 @@ files:
|
|
127
127
|
- lib/condensation/filters/strip_commas.rb
|
128
128
|
- lib/condensation/filters/timestamp.rb
|
129
129
|
- lib/condensation/filters/url_encode.rb
|
130
|
+
- lib/condensation/filters/weeks_since.rb
|
131
|
+
- lib/condensation/filters/weeks_until.rb
|
130
132
|
- lib/condensation/sanitizer.rb
|
131
133
|
- lib/condensation/version.rb
|
132
134
|
- spec/condensation/filters/advance_date_to_next_spec.rb
|
@@ -140,6 +142,8 @@ files:
|
|
140
142
|
- spec/condensation/filters/strip_commas_spec.rb
|
141
143
|
- spec/condensation/filters/timestamp_spec.rb
|
142
144
|
- spec/condensation/filters/url_encode_spec.rb
|
145
|
+
- spec/condensation/filters/weeks_since_spec.rb
|
146
|
+
- spec/condensation/filters/weeks_until_spec.rb
|
143
147
|
- spec/condensation/sanitizer_spec.rb
|
144
148
|
- spec/condensation_spec.rb
|
145
149
|
- spec/spec_helper.rb
|
@@ -180,6 +184,8 @@ test_files:
|
|
180
184
|
- spec/condensation/filters/strip_commas_spec.rb
|
181
185
|
- spec/condensation/filters/timestamp_spec.rb
|
182
186
|
- spec/condensation/filters/url_encode_spec.rb
|
187
|
+
- spec/condensation/filters/weeks_since_spec.rb
|
188
|
+
- spec/condensation/filters/weeks_until_spec.rb
|
183
189
|
- spec/condensation/sanitizer_spec.rb
|
184
190
|
- spec/condensation_spec.rb
|
185
191
|
- spec/spec_helper.rb
|