daterange 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 91d9f459fb0d506a14af0a74436c758cdb65f148
4
+ data.tar.gz: ef9420f88c7c2827c04b3eccfec7ae9dc7f6331b
5
+ SHA512:
6
+ metadata.gz: 681a36710c529f80d243e6f3997b1127320edc1570437b840bb9c9f4711a8e3fbad48c47c0327c965e89b6e511576c86db3099ba72c265cef982d0597c7b2f38
7
+ data.tar.gz: 95c650962d563edf8d5705d8b18a923d84b3ab4d82b59368a3ac085820071390b4c7b70f6a2c4044c8a2da7869ef77ac33f27bbb73879c6b08b0f447f13f0ec2
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format=doc
@@ -0,0 +1 @@
1
+ 2.1.2
data/Gemfile ADDED
@@ -0,0 +1,19 @@
1
+ source "https://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ gem "activesupport", ">= 2.3.5"
5
+
6
+ # Add dependencies to develop your gem here.
7
+ # Include everything needed to run rake, tests, features, etc.
8
+
9
+ group :development do
10
+ gem "rspec", "~> 3.0"
11
+ gem "rspec-its"
12
+ gem "yard", "~> 0.7"
13
+ gem "bundler", "~> 1.0"
14
+ gem "jeweler", "~> 2.0.1"
15
+ gem "simplecov", ">= 0"
16
+ gem "timecop"
17
+
18
+ gem "guard-rspec"
19
+ end
@@ -0,0 +1,127 @@
1
+ GEM
2
+ remote: https://rubygems.org/
3
+ specs:
4
+ activesupport (4.1.7)
5
+ i18n (~> 0.6, >= 0.6.9)
6
+ json (~> 1.7, >= 1.7.7)
7
+ minitest (~> 5.1)
8
+ thread_safe (~> 0.1)
9
+ tzinfo (~> 1.1)
10
+ addressable (2.3.6)
11
+ builder (3.2.2)
12
+ celluloid (0.16.0)
13
+ timers (~> 4.0.0)
14
+ coderay (1.1.0)
15
+ descendants_tracker (0.0.4)
16
+ thread_safe (~> 0.3, >= 0.3.1)
17
+ diff-lcs (1.2.5)
18
+ docile (1.1.5)
19
+ faraday (0.9.0)
20
+ multipart-post (>= 1.2, < 3)
21
+ ffi (1.9.6)
22
+ formatador (0.2.5)
23
+ git (1.2.8)
24
+ github_api (0.12.2)
25
+ addressable (~> 2.3)
26
+ descendants_tracker (~> 0.0.4)
27
+ faraday (~> 0.8, < 0.10)
28
+ hashie (>= 3.3)
29
+ multi_json (>= 1.7.5, < 2.0)
30
+ nokogiri (~> 1.6.3)
31
+ oauth2
32
+ guard (2.8.2)
33
+ formatador (>= 0.2.4)
34
+ listen (~> 2.7)
35
+ lumberjack (~> 1.0)
36
+ pry (>= 0.9.12)
37
+ thor (>= 0.18.1)
38
+ guard-rspec (4.3.1)
39
+ guard (~> 2.1)
40
+ rspec (>= 2.14, < 4.0)
41
+ hashie (3.3.1)
42
+ highline (1.6.21)
43
+ hitimes (1.2.2)
44
+ i18n (0.6.11)
45
+ jeweler (2.0.1)
46
+ builder
47
+ bundler (>= 1.0)
48
+ git (>= 1.2.5)
49
+ github_api
50
+ highline (>= 1.6.15)
51
+ nokogiri (>= 1.5.10)
52
+ rake
53
+ rdoc
54
+ json (1.8.1)
55
+ jwt (1.0.0)
56
+ listen (2.8.0)
57
+ celluloid (>= 0.15.2)
58
+ rb-fsevent (>= 0.9.3)
59
+ rb-inotify (>= 0.9)
60
+ lumberjack (1.0.9)
61
+ method_source (0.8.2)
62
+ mini_portile (0.6.1)
63
+ minitest (5.4.3)
64
+ multi_json (1.10.1)
65
+ multi_xml (0.5.5)
66
+ multipart-post (2.0.0)
67
+ nokogiri (1.6.4.1)
68
+ mini_portile (~> 0.6.0)
69
+ oauth2 (1.0.0)
70
+ faraday (>= 0.8, < 0.10)
71
+ jwt (~> 1.0)
72
+ multi_json (~> 1.3)
73
+ multi_xml (~> 0.5)
74
+ rack (~> 1.2)
75
+ pry (0.10.1)
76
+ coderay (~> 1.1.0)
77
+ method_source (~> 0.8.1)
78
+ slop (~> 3.4)
79
+ rack (1.5.2)
80
+ rake (10.3.2)
81
+ rb-fsevent (0.9.4)
82
+ rb-inotify (0.9.5)
83
+ ffi (>= 0.5.0)
84
+ rdoc (4.1.0)
85
+ rspec (3.0.0)
86
+ rspec-core (~> 3.0.0)
87
+ rspec-expectations (~> 3.0.0)
88
+ rspec-mocks (~> 3.0.0)
89
+ rspec-core (3.0.4)
90
+ rspec-support (~> 3.0.0)
91
+ rspec-expectations (3.0.4)
92
+ diff-lcs (>= 1.2.0, < 2.0)
93
+ rspec-support (~> 3.0.0)
94
+ rspec-its (1.1.0)
95
+ rspec-core (>= 3.0.0)
96
+ rspec-expectations (>= 3.0.0)
97
+ rspec-mocks (3.0.4)
98
+ rspec-support (~> 3.0.0)
99
+ rspec-support (3.0.4)
100
+ simplecov (0.9.1)
101
+ docile (~> 1.1.0)
102
+ multi_json (~> 1.0)
103
+ simplecov-html (~> 0.8.0)
104
+ simplecov-html (0.8.0)
105
+ slop (3.6.0)
106
+ thor (0.19.1)
107
+ thread_safe (0.3.4)
108
+ timecop (0.7.1)
109
+ timers (4.0.1)
110
+ hitimes
111
+ tzinfo (1.2.2)
112
+ thread_safe (~> 0.1)
113
+ yard (0.8.7.4)
114
+
115
+ PLATFORMS
116
+ ruby
117
+
118
+ DEPENDENCIES
119
+ activesupport (>= 2.3.5)
120
+ bundler (~> 1.0)
121
+ guard-rspec
122
+ jeweler (~> 2.0.1)
123
+ rspec (~> 3.0)
124
+ rspec-its
125
+ simplecov
126
+ timecop
127
+ yard (~> 0.7)
@@ -0,0 +1,38 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ # Note: The cmd option is now required due to the increasing number of ways
5
+ # rspec may be run, below are examples of the most common uses.
6
+ # * bundler: 'bundle exec rspec'
7
+ # * bundler binstubs: 'bin/rspec'
8
+ # * spring: 'bin/rsspec' (This will use spring if running and you have
9
+ # installed the spring binstubs per the docs)
10
+ # * zeus: 'zeus rspec' (requires the server to be started separetly)
11
+ # * 'just' rspec: 'rspec'
12
+ guard :rspec, cmd: 'bundle exec rspec' do
13
+ watch(%r{^spec/.+_spec\.rb$})
14
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
15
+ watch('spec/spec_helper.rb') { "spec" }
16
+
17
+ # Rails example
18
+ watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
19
+ watch(%r{^app/(.*)(\.erb|\.haml|\.slim)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
20
+ watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
21
+ watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
22
+ watch('config/routes.rb') { "spec/routing" }
23
+ watch('app/controllers/application_controller.rb') { "spec/controllers" }
24
+ watch('spec/rails_helper.rb') { "spec" }
25
+
26
+ # Capybara features specs
27
+ watch(%r{^app/views/(.+)/.*\.(erb|haml|slim)$}) { |m| "spec/features/#{m[1]}_spec.rb" }
28
+
29
+ # Turnip features and steps
30
+ watch(%r{^spec/acceptance/(.+)\.feature$})
31
+ watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' }
32
+ end
33
+
34
+
35
+ # guard :rubocop do
36
+ # watch(%r{.+\.rb$})
37
+ # watch(%r{(?:.+/)?\.rubocop\.yml$}) { |m| File.dirname(m[0]) }
38
+ # end
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2014 Theodor Tonum
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,39 @@
1
+ # DateRange
2
+
3
+ [![Version](http://img.shields.io/gem/v/daterange.svg?style=flat-square)](https://rubygems.org/gems/daterange)
4
+ [![Downloads](http://img.shields.io/gem/dt/daterange.svg?style=flat-square)](https://rubygems.org/gems/daterange)
5
+ [![Open Github issues](http://img.shields.io/github/issues/theodorton/daterange.svg?style=flat-square)](https://github.com/theodorton/daterange/issues)
6
+
7
+ Parse strings like `yesterday`, `previous_5_months`, `this_hour` to date/time ranges.
8
+
9
+ ```shell
10
+ $ gem install daterange
11
+ ```
12
+
13
+ ```ruby
14
+ require 'daterange'
15
+
16
+ range = DateRange.parse('today')
17
+ range.min
18
+ # => Wed, 24 Dec 2014 00:00:00 +0000
19
+ range.max
20
+ # => Wed, 24 Dec 2014 23:59:59 +0000
21
+ ```
22
+
23
+ Based on [Keen.io Timeframes](https://keen.io/docs/data-analysis/timeframe/).
24
+
25
+ # Contributing to daterange
26
+
27
+ 1. Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
28
+ 2. Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
29
+ 3. Fork the project.
30
+ 4. Start a feature/bugfix branch.
31
+ 5. Commit and push until you are happy with your contribution.
32
+ 6. Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
33
+ 7. Open a Pull request for your branch
34
+ 8. Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
35
+
36
+ # Copyright
37
+
38
+ Copyright (c) 2014 Theodor Tonum. See LICENSE for
39
+ further details.
@@ -0,0 +1,43 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://guides.rubygems.org/specification-reference/ for more options
17
+ gem.name = "daterange"
18
+ gem.homepage = "http://github.com/theodorton/daterange"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{Parse strings to date ranges}
21
+ gem.description = %Q{Parse keen-like timeframes to date ranges}
22
+ gem.email = "theodor@tonum.no"
23
+ gem.authors = ["Theodor Tonum"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rspec/core'
29
+ require 'rspec/core/rake_task'
30
+ RSpec::Core::RakeTask.new(:spec) do |spec|
31
+ spec.pattern = FileList['spec/**/*_spec.rb']
32
+ end
33
+
34
+ desc "Code coverage detail"
35
+ task :simplecov do
36
+ ENV['COVERAGE'] = "true"
37
+ Rake::Task['spec'].execute
38
+ end
39
+
40
+ task :default => :spec
41
+
42
+ require 'yard'
43
+ YARD::Rake::YardocTask.new
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 1.0.0
@@ -0,0 +1,63 @@
1
+ require 'active_support/core_ext/integer'
2
+ require 'active_support/core_ext/time'
3
+ require 'active_support/core_ext/date'
4
+ require 'active_support/core_ext/date_time'
5
+
6
+ class DateRange
7
+ def self.parse(string)
8
+ _start, _end = _parse(string)
9
+
10
+ if _start && _end
11
+ (_start.._end)
12
+ else
13
+ nil
14
+ end
15
+ end
16
+
17
+ private
18
+
19
+ UNITS = %w(minute hour day week month year)
20
+
21
+ REGEX_PATTERNS = {
22
+ this_unit: /\Athis_(#{UNITS.join('|')})\Z/,
23
+ this_n_unit: /\Athis_(\d+)_(#{UNITS.join('|')})s?\Z/,
24
+ prev_unit: /\Aprevious_(#{UNITS.join('|')})s?\Z/,
25
+ prev_n_unit: /\Aprevious_(\d+)_(#{UNITS.join('|')})s?\Z/
26
+ }
27
+
28
+ def self._parse(string)
29
+ case string
30
+ when REGEX_PATTERNS[:this_unit]
31
+ unit = REGEX_PATTERNS[:this_unit].match(string)[1]
32
+ [
33
+ now.public_send("beginning_of_#{unit}"),
34
+ now.public_send("end_of_#{unit}")
35
+ ]
36
+ when REGEX_PATTERNS[:this_n_unit]
37
+ matches = REGEX_PATTERNS[:this_n_unit].match(string)
38
+ n, unit = matches[1], matches[2]
39
+ [
40
+ (now.public_send("beginning_of_#{unit}") - (Integer(n)-1).public_send(unit)),
41
+ now.public_send("end_of_#{unit}")
42
+ ]
43
+ when REGEX_PATTERNS[:prev_n_unit]
44
+ matches = REGEX_PATTERNS[:prev_n_unit].match(string)
45
+ n, unit = matches[1], matches[2]
46
+ [
47
+ now.public_send("beginning_of_#{unit}") - Integer(n).public_send(unit),
48
+ now.public_send("end_of_#{unit}") - 1.public_send(unit)
49
+ ]
50
+ when REGEX_PATTERNS[:prev_unit]
51
+ unit = REGEX_PATTERNS[:prev_unit].match(string)[1]
52
+ _parse("previous_1_#{unit}")
53
+ when 'today'
54
+ _parse('this_day')
55
+ when 'yesterday'
56
+ _parse('previous_day')
57
+ end
58
+ end
59
+
60
+ def self.now
61
+ DateTime.now.utc
62
+ end
63
+ end
@@ -0,0 +1,189 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe DateRange do
4
+ describe "type" do
5
+ specify { expect(DateRange.parse('today')).to be_kind_of(Range) }
6
+ end
7
+
8
+ describe "this_minute" do
9
+ subject { DateRange.parse('this_minute') }
10
+
11
+ its(:min) { should eq DateTime.new(2014, 1, 12, 12, 0, 0) }
12
+ its(:max) { should eq DateTime.new(2014, 1, 12, 12, 0, 59) }
13
+ end
14
+
15
+ describe "this_hour" do
16
+ subject { DateRange.parse('this_hour') }
17
+
18
+ its(:min) { should eq DateTime.new(2014, 1, 12, 12, 0, 0) }
19
+ its(:max) { should eq DateTime.new(2014, 1, 12, 12, 59, 59) }
20
+ end
21
+
22
+ describe "this_day" do
23
+ subject(:this_day) { DateRange.parse('this_day') }
24
+
25
+ its(:min) { should eq DateTime.new(2014, 1, 12, 0, 0, 0) }
26
+ its(:max) { should eq DateTime.new(2014, 1, 12, 23, 59, 59) }
27
+ end
28
+
29
+ describe "this_week" do
30
+ subject(:this_week) { DateRange.parse('this_week') }
31
+
32
+ its(:min) { should eq DateTime.new(2014, 1, 6, 0, 0, 0) }
33
+ its(:max) { should eq DateTime.new(2014, 1, 12, 23, 59, 59) }
34
+ end
35
+
36
+ describe "this_month" do
37
+ subject(:this_month) { DateRange.parse('this_month') }
38
+
39
+ its(:min) { should eq DateTime.new(2014, 1, 1, 0, 0, 0) }
40
+ its(:max) { should eq DateTime.new(2014, 1, 31, 23, 59, 59) }
41
+ end
42
+
43
+ describe "this_year" do
44
+ subject(:this_year) { DateRange.parse('this_year') }
45
+
46
+ its(:min) { should eq DateTime.new(2014, 1, 1, 0, 0, 0) }
47
+ its(:max) { should eq DateTime.new(2014, 12, 31, 23, 59, 59) }
48
+ end
49
+
50
+ describe "this_n_minutes" do
51
+ subject(:this_n_minutes) { DateRange.parse('this_5_minutes') }
52
+
53
+ its(:min) { should eq DateTime.new(2014, 1, 12, 11, 56, 0) }
54
+ its(:max) { should eq DateTime.new(2014, 1, 12, 12, 0, 59) }
55
+ end
56
+
57
+ describe "this_n_hours" do
58
+ subject(:this_n_hours) { DateRange.parse('this_5_hours') }
59
+
60
+ its(:min) { should eq DateTime.new(2014, 1, 12, 8, 0, 0) }
61
+ its(:max) { should eq DateTime.new(2014, 1, 12, 12, 59, 59) }
62
+ end
63
+
64
+ describe "this_n_days" do
65
+ subject(:this_n_days) { DateRange.parse('this_5_days') }
66
+
67
+ its(:min) { should eq DateTime.new(2014, 1, 8, 0, 0, 0) }
68
+ its(:max) { should eq DateTime.new(2014, 1, 12, 23, 59, 59) }
69
+ end
70
+
71
+ describe "this_n_weeks" do
72
+ subject(:this_n_weeks) { DateRange.parse('this_2_weeks') }
73
+
74
+ its(:min) { should eq DateTime.new(2013, 12, 30, 0, 0, 0) }
75
+ its(:max) { should eq DateTime.new(2014, 1, 12, 23, 59, 59) }
76
+ end
77
+
78
+ describe "this_n_months" do
79
+ subject(:this_n_months) { DateRange.parse('this_3_months') }
80
+
81
+ its(:min) { should eq DateTime.new(2013, 11, 1, 0, 0, 0) }
82
+ its(:max) { should eq DateTime.new(2014, 1, 31, 23, 59, 59) }
83
+ end
84
+
85
+ describe "this_n_years" do
86
+ subject(:this_n_years) { DateRange.parse('this_4_years') }
87
+
88
+ its(:min) { should eq DateTime.new(2011, 1, 1, 0, 0, 0) }
89
+ its(:max) { should eq DateTime.new(2014, 12, 31, 23, 59, 59) }
90
+ end
91
+
92
+ describe "previous_n_minutes" do
93
+ subject(:previous_n_minutes) { DateRange.parse('previous_5_minutes') }
94
+
95
+ its(:min) { should eq DateTime.new(2014, 1, 12, 11, 55, 0) }
96
+ its(:max) { should eq DateTime.new(2014, 1, 12, 11, 59, 59) }
97
+
98
+ context "when the plural s-suffix is missing" do
99
+ subject(:previous_n_minute) { DateRange.parse('previous_5_minute') }
100
+
101
+ it { should eq previous_n_minutes }
102
+ end
103
+ end
104
+
105
+ describe "previous_n_hours" do
106
+ subject(:previous_n_hours) { DateRange.parse('previous_5_hours') }
107
+
108
+ its(:min) { should eq DateTime.new(2014, 1, 12, 7, 0, 0) }
109
+ its(:max) { should eq DateTime.new(2014, 1, 12, 11, 59, 59) }
110
+ end
111
+
112
+ describe "previous_n_days" do
113
+ subject(:previous_n_days) { DateRange.parse('previous_5_days') }
114
+
115
+ its(:min) { should eq DateTime.new(2014, 1, 7, 0, 0, 0) }
116
+ its(:max) { should eq DateTime.new(2014, 1, 11, 23, 59, 59) }
117
+ end
118
+
119
+ describe "previous_n_weeks" do
120
+ subject(:previous_n_weeks) { DateRange.parse('previous_2_weeks') }
121
+
122
+ its(:min) { should eq DateTime.new(2013, 12, 23, 0, 0, 0) }
123
+ its(:max) { should eq DateTime.new(2014, 1, 5, 23, 59, 59) }
124
+ end
125
+
126
+ describe "previous_n_months" do
127
+ subject(:previous_n_months) { DateRange.parse('previous_3_months') }
128
+
129
+ its(:min) { should eq DateTime.new(2013, 10, 1, 0, 0, 0) }
130
+ its(:max) { should eq DateTime.new(2013, 12, 31, 23, 59, 59) }
131
+ end
132
+
133
+ describe "previous_n_years" do
134
+ subject(:previous_n_years) { DateRange.parse('previous_4_years') }
135
+
136
+ its(:min) { should eq DateTime.new(2010, 1, 1, 0, 0, 0) }
137
+ its(:max) { should eq DateTime.new(2013, 12, 31, 23, 59, 59) }
138
+ end
139
+
140
+ describe "aliases" do
141
+ describe "today" do
142
+ subject { DateRange.parse('today') }
143
+
144
+ it { should eq DateRange.parse('this_day') }
145
+ end
146
+
147
+ describe "previous_minute" do
148
+ subject { DateRange.parse('previous_minute') }
149
+
150
+ it { should eq DateRange.parse('previous_1_minute') }
151
+ end
152
+
153
+ describe "previous_hour" do
154
+ subject { DateRange.parse('previous_hour') }
155
+
156
+ it { should eq DateRange.parse('previous_1_hour') }
157
+ end
158
+
159
+ describe "previous_day" do
160
+ subject { DateRange.parse('previous_day') }
161
+
162
+ it { should eq DateRange.parse('previous_1_day') }
163
+ end
164
+
165
+ describe "yesterday" do
166
+ subject { DateRange.parse('yesterday') }
167
+
168
+ it { should eq DateRange.parse('previous_1_day') }
169
+ end
170
+
171
+ describe "previous_week" do
172
+ subject { DateRange.parse('previous_week') }
173
+
174
+ it { should eq DateRange.parse('previous_1_week') }
175
+ end
176
+
177
+ describe "previous_month" do
178
+ subject { DateRange.parse('previous_month') }
179
+
180
+ it { should eq DateRange.parse('previous_1_month') }
181
+ end
182
+
183
+ describe "previous_year" do
184
+ subject { DateRange.parse('previous_year') }
185
+
186
+ it { should eq DateRange.parse('previous_1_year') }
187
+ end
188
+ end
189
+ end
@@ -0,0 +1,39 @@
1
+ require 'simplecov'
2
+
3
+ module SimpleCov::Configuration
4
+ def clean_filters
5
+ @filters = []
6
+ end
7
+ end
8
+
9
+ SimpleCov.configure do
10
+ clean_filters
11
+ load_adapter 'test_frameworks'
12
+ end
13
+
14
+ ENV["COVERAGE"] && SimpleCov.start do
15
+ add_filter "/.rvm/"
16
+ end
17
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
18
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
19
+
20
+ require 'rspec'
21
+ require 'rspec/its'
22
+ require 'timecop'
23
+ require 'daterange'
24
+
25
+ # Requires supporting files with custom matchers and macros, etc,
26
+ # in ./support/ and its subdirectories.
27
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
28
+
29
+ RSpec.configure do |config|
30
+ config.filter_run :focus => true
31
+ config.filter_run_excluding :skip => true
32
+ config.run_all_when_everything_filtered = true
33
+
34
+ config.around(:each) do |example|
35
+ Timecop.travel(DateTime.new(2014, 1, 12, 12, 0, 1)) do
36
+ example.run
37
+ end
38
+ end
39
+ end
metadata ADDED
@@ -0,0 +1,184 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: daterange
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Theodor Tonum
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-12-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 2.3.5
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 2.3.5
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '3.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '3.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec-its
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: yard
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.7'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.7'
69
+ - !ruby/object:Gem::Dependency
70
+ name: bundler
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: jeweler
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 2.0.1
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 2.0.1
97
+ - !ruby/object:Gem::Dependency
98
+ name: simplecov
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: timecop
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: guard-rspec
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ description: Parse keen-like timeframes to date ranges
140
+ email: theodor@tonum.no
141
+ executables: []
142
+ extensions: []
143
+ extra_rdoc_files:
144
+ - LICENSE
145
+ - README.md
146
+ files:
147
+ - ".document"
148
+ - ".rspec"
149
+ - ".ruby-version"
150
+ - Gemfile
151
+ - Gemfile.lock
152
+ - Guardfile
153
+ - LICENSE
154
+ - README.md
155
+ - Rakefile
156
+ - VERSION
157
+ - lib/daterange.rb
158
+ - spec/daterange_spec.rb
159
+ - spec/spec_helper.rb
160
+ homepage: http://github.com/theodorton/daterange
161
+ licenses:
162
+ - MIT
163
+ metadata: {}
164
+ post_install_message:
165
+ rdoc_options: []
166
+ require_paths:
167
+ - lib
168
+ required_ruby_version: !ruby/object:Gem::Requirement
169
+ requirements:
170
+ - - ">="
171
+ - !ruby/object:Gem::Version
172
+ version: '0'
173
+ required_rubygems_version: !ruby/object:Gem::Requirement
174
+ requirements:
175
+ - - ">="
176
+ - !ruby/object:Gem::Version
177
+ version: '0'
178
+ requirements: []
179
+ rubyforge_project:
180
+ rubygems_version: 2.2.2
181
+ signing_key:
182
+ specification_version: 4
183
+ summary: Parse strings to date ranges
184
+ test_files: []