calendar_sniper 1.1.2 → 1.1.3
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/lib/calendar_sniper.rb +4 -1
- data/lib/calendar_sniper/version.rb +1 -1
- data/spec/parsing_spec.rb +17 -1
- 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: 620db522bc24dac549356ead4886806f513ec873
|
4
|
+
data.tar.gz: ab877c11ec5f74df80004f8351360f3c5e5f7e47
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b6362d151b7242c9ecbe24b6d169c77d23dfe5bf7e1a08d534c605acd1a1021c6133cce655aafb68834023f452909290d63052b13ed6d8ba5f73a8598bcbdd8d
|
7
|
+
data.tar.gz: 5f28470515faa64047cc812cbb34ae7711e26cd3410657ec103e04b0789ca4296753db537759f642169b53aa29c38ab1f70dde94b55eac5adb5b149ac10d8fca
|
data/lib/calendar_sniper.rb
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
require "calendar_sniper/version"
|
2
2
|
require 'active_support'
|
3
|
+
require 'active_support/core_ext/date'
|
4
|
+
require 'active_support/core_ext/date_time'
|
5
|
+
require 'active_support/core_ext/time'
|
3
6
|
|
4
7
|
module CalendarSniper
|
5
8
|
extend ActiveSupport::Concern
|
@@ -36,7 +39,7 @@ module CalendarSniper
|
|
36
39
|
|
37
40
|
def coalesce_date(from_date_or_string, by_direction)
|
38
41
|
if from_date_or_string.is_a?(String)
|
39
|
-
date_from_string =
|
42
|
+
date_from_string = Time.strptime(from_date_or_string, date_format_for_string(from_date_or_string))
|
40
43
|
set_time_for_direction(date_from_string, by_direction)
|
41
44
|
else
|
42
45
|
set_time_for_direction(from_date_or_string, by_direction)
|
data/spec/parsing_spec.rb
CHANGED
@@ -15,7 +15,23 @@ describe CalendarSniper::ClassMethods do
|
|
15
15
|
[ '%Y-%m-%d %l:%M:%S%z', '2013-01-01 2:50:00-0400']
|
16
16
|
].each do |format, example|
|
17
17
|
it "can parse #{example} as #{format}" do
|
18
|
-
expect(TestSniper.send(:coalesce_date, example, '=')).to eq(
|
18
|
+
expect(TestSniper.send(:coalesce_date, example, '=')).to eq(Time.strptime(example, format))
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'Uses the default time zone for greater than' do
|
23
|
+
Time.use_zone('Eastern Time (US & Canada)') do
|
24
|
+
dt = TestSniper.send(:coalesce_date, '1/01/2013', :>)
|
25
|
+
expect(dt.zone).to eq('EST')
|
26
|
+
expect(dt.strftime('%Y-%m-%d %H:%M:%S%z')).to eq('2013-01-01 00:00:00-0500')
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'Uses the default time zone for less than' do
|
31
|
+
Time.use_zone('Eastern Time (US & Canada)') do
|
32
|
+
dt = TestSniper.send(:coalesce_date, '1/01/2013', :<)
|
33
|
+
expect(dt.zone).to eq('EST')
|
34
|
+
expect(dt.strftime('%Y-%m-%d %H:%M:%S%z')).to eq('2013-01-01 23:59:59-0500')
|
19
35
|
end
|
20
36
|
end
|
21
37
|
|