icu_utils 1.2.1 → 1.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/icu_utils/date.rb +2 -7
- data/lib/icu_utils/version.rb +1 -1
- data/spec/date_spec.rb +32 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 00770614bdea719215c4d382a203b68b141b4c0f
|
4
|
+
data.tar.gz: 187677d1ab5db950e1fa4f36f760ec34f7de90a6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 05779d4d2a55d2de9bc27c92c10ee131913dd25f2e7d101dff4696df7ad3268c8f0643d9ac6d99e6d42d7f40556d13ce49a69096f1de398092baf0da4f2c4e47
|
7
|
+
data.tar.gz: e1def33b43f99c0ce58d5ff16fa604ea2aa69cc1f466eb2392c4e3c2a3e2a251080d428e01ffd173009d515609f38c0e86eb6ab0fcc11d963988cbec5c048833
|
data/Gemfile.lock
CHANGED
data/lib/icu_utils/date.rb
CHANGED
@@ -49,19 +49,14 @@ module ICU
|
|
49
49
|
valid
|
50
50
|
end
|
51
51
|
|
52
|
-
# after: must be after %{restriction}
|
53
|
-
# before: must be before %{restriction}
|
54
|
-
# invalid: invalid
|
55
|
-
# invalid_date: invalid date
|
56
|
-
# on_or_after: must be on or after %{restriction}
|
57
|
-
# on_or_before: must be on or before %{restriction}
|
58
|
-
|
59
52
|
private
|
60
53
|
|
61
54
|
def to_date(thing)
|
62
55
|
thing = thing.call if thing.respond_to?(:call)
|
63
56
|
if thing.is_a?(Date)
|
64
57
|
thing.dup
|
58
|
+
elsif thing.to_s.downcase == "today"
|
59
|
+
thing = ::Date.today
|
65
60
|
else
|
66
61
|
thing = ::Date.parse(thing.to_s)
|
67
62
|
end
|
data/lib/icu_utils/version.rb
CHANGED
data/spec/date_spec.rb
CHANGED
@@ -208,5 +208,37 @@ module ICU
|
|
208
208
|
expect(d.reasons[1]).to eq restriction: penny.to_s
|
209
209
|
end
|
210
210
|
end
|
211
|
+
|
212
|
+
context "symbol constraints" do
|
213
|
+
it "before" do
|
214
|
+
d = ICU::Date.new(penny, before: :today)
|
215
|
+
expect(d).to be_valid
|
216
|
+
expect(d.date).to eq penny
|
217
|
+
expect(d.reasons).to be_empty
|
218
|
+
end
|
219
|
+
|
220
|
+
it "after" do
|
221
|
+
d = ICU::Date.new(yesterday, after: "TODAY")
|
222
|
+
expect(d).to_not be_valid
|
223
|
+
expect(d.date).to eq yesterday
|
224
|
+
expect(d.reasons[0]).to eq "errors.messages.after"
|
225
|
+
expect(d.reasons[1]).to eq restriction: today.to_s
|
226
|
+
end
|
227
|
+
|
228
|
+
it "on or before" do
|
229
|
+
d = ICU::Date.new(today, on_or_before: "Today")
|
230
|
+
expect(d).to be_valid
|
231
|
+
expect(d.date).to eq today
|
232
|
+
expect(d.reasons).to be_empty
|
233
|
+
end
|
234
|
+
|
235
|
+
it "on or after" do
|
236
|
+
d = ICU::Date.new(mark, on_or_after: "today")
|
237
|
+
expect(d).to_not be_valid
|
238
|
+
expect(d.date).to eq mark
|
239
|
+
expect(d.reasons[0]).to eq "errors.messages.on_or_after"
|
240
|
+
expect(d.reasons[1]).to eq restriction: today.to_s
|
241
|
+
end
|
242
|
+
end
|
211
243
|
end
|
212
244
|
end
|