by_star 2.2.1 → 3.0.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 +5 -13
- data/.gitignore +5 -5
- data/.travis.yml +61 -35
- data/CHANGELOG.md +44 -35
- data/Gemfile +18 -25
- data/MIT-LICENSE +20 -20
- data/README.md +577 -540
- data/Rakefile +18 -18
- data/UPGRADING +6 -12
- data/by_star.gemspec +34 -32
- data/cleaner.rb +24 -24
- data/lib/by_star.rb +17 -16
- data/lib/by_star/base.rb +68 -70
- data/lib/by_star/between.rb +156 -120
- data/lib/by_star/directional.rb +37 -33
- data/lib/by_star/kernel/date.rb +50 -19
- data/lib/by_star/kernel/time.rb +41 -41
- data/lib/by_star/normalization.rb +127 -118
- data/lib/by_star/orm/active_record/by_star.rb +61 -69
- data/lib/by_star/orm/mongoid/by_star.rb +76 -73
- data/lib/by_star/orm/mongoid/reorder.rb +23 -0
- data/lib/by_star/version.rb +3 -3
- data/spec/database.yml +15 -15
- data/spec/fixtures/active_record/models.rb +12 -10
- data/spec/fixtures/active_record/schema.rb +19 -19
- data/spec/fixtures/mongoid/models.rb +31 -29
- data/spec/fixtures/shared/seeds.rb +26 -26
- data/spec/gemfiles/Gemfile.master +6 -0
- data/spec/gemfiles/Gemfile.rails40 +7 -0
- data/spec/gemfiles/Gemfile.rails41 +7 -0
- data/spec/gemfiles/Gemfile.rails42 +7 -0
- data/spec/gemfiles/Gemfile.rails50 +10 -0
- data/spec/gemfiles/Gemfile.rails51 +10 -0
- data/spec/integration/active_record/active_record_spec.rb +38 -53
- data/spec/integration/mongoid/mongoid_spec.rb +37 -46
- data/spec/integration/shared/between_times.rb +82 -0
- data/spec/integration/shared/by_calendar_month.rb +55 -55
- data/spec/integration/shared/by_cweek.rb +54 -0
- data/spec/integration/shared/by_day.rb +96 -108
- data/spec/integration/shared/by_direction.rb +172 -153
- data/spec/integration/shared/by_fortnight.rb +48 -48
- data/spec/integration/shared/by_month.rb +50 -50
- data/spec/integration/shared/by_quarter.rb +49 -49
- data/spec/integration/shared/by_week.rb +54 -54
- data/spec/integration/shared/by_weekend.rb +49 -49
- data/spec/integration/shared/by_year.rb +48 -48
- data/spec/integration/shared/offset_parameter.rb +32 -31
- data/spec/integration/shared/order_parameter.rb +36 -0
- data/spec/integration/shared/relative.rb +174 -174
- data/spec/integration/shared/scope_parameter.rb +73 -72
- data/spec/spec_helper.rb +29 -29
- data/spec/unit/kernel_date_spec.rb +113 -60
- data/spec/unit/kernel_time_spec.rb +57 -57
- data/spec/unit/normalization_spec.rb +305 -255
- metadata +61 -62
data/Rakefile
CHANGED
@@ -1,18 +1,18 @@
|
|
1
|
-
require 'bundler'
|
2
|
-
require 'rspec/core/rake_task'
|
3
|
-
|
4
|
-
Bundler::GemHelper.install_tasks
|
5
|
-
RSpec::Core::RakeTask.new(:spec)
|
6
|
-
|
7
|
-
def orm_test(orm)
|
8
|
-
RSpec::Core::RakeTask.new(orm) do |task|
|
9
|
-
task.pattern = "./spec/{unit,integration/#{orm}}/{,/*/**}/*_spec.rb"
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
namespace :spec do
|
14
|
-
orm_test 'active_record'
|
15
|
-
orm_test 'mongoid'
|
16
|
-
end
|
17
|
-
|
18
|
-
task default: :spec
|
1
|
+
require 'bundler'
|
2
|
+
require 'rspec/core/rake_task'
|
3
|
+
|
4
|
+
Bundler::GemHelper.install_tasks
|
5
|
+
RSpec::Core::RakeTask.new(:spec)
|
6
|
+
|
7
|
+
def orm_test(orm)
|
8
|
+
RSpec::Core::RakeTask.new(orm) do |task|
|
9
|
+
task.pattern = "./spec/{unit,integration/#{orm}}/{,/*/**}/*_spec.rb"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
namespace :spec do
|
14
|
+
orm_test 'active_record'
|
15
|
+
orm_test 'mongoid'
|
16
|
+
end
|
17
|
+
|
18
|
+
task default: :spec
|
data/UPGRADING
CHANGED
@@ -1,12 +1,6 @@
|
|
1
|
-
Upgrading ByStar
|
2
|
-
----------------
|
3
|
-
|
4
|
-
*
|
5
|
-
|
6
|
-
|
7
|
-
* Mongoid: the `between` method has been removed as of version 2.2.0, as it conflicts with the native Mongoid `between`
|
8
|
-
method. Please use `between_times` instead.
|
9
|
-
|
10
|
-
* Chronic gem (used for time string parsing) has been removed as a hard dependency for ByStar,
|
11
|
-
however it is still supported. If you would like to use Chronic with ByStar, please explicitly
|
12
|
-
include `gem chronic` into your Gemfile.
|
1
|
+
Upgrading ByStar
|
2
|
+
----------------
|
3
|
+
|
4
|
+
* Chronic gem (used for time string parsing) has been removed as a hard dependency for ByStar,
|
5
|
+
however it is still supported. If you would like to use Chronic with ByStar, please explicitly
|
6
|
+
include `gem chronic` into your Gemfile.
|
data/by_star.gemspec
CHANGED
@@ -1,32 +1,34 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
|
-
require File.expand_path("../lib/by_star/version", __FILE__)
|
3
|
-
|
4
|
-
Gem::Specification.new do |s|
|
5
|
-
s.name = "by_star"
|
6
|
-
s.version = ByStar::VERSION
|
7
|
-
s.authors = ["Ryan Bigg", "Johnny Shields"]
|
8
|
-
s.email = ["radarlistener@gmail.com"]
|
9
|
-
s.homepage = "http://github.com/radar/by_star"
|
10
|
-
s.summary = "ActiveRecord and Mongoid extension for easier date scopes and time ranges"
|
11
|
-
s.description = "ActiveRecord and Mongoid extension for easier date scopes and time ranges"
|
12
|
-
|
13
|
-
s.
|
14
|
-
|
15
|
-
s.
|
16
|
-
|
17
|
-
s.
|
18
|
-
|
19
|
-
s.add_development_dependency "
|
20
|
-
s.add_development_dependency "
|
21
|
-
s.add_development_dependency "
|
22
|
-
s.add_development_dependency "
|
23
|
-
s.add_development_dependency "
|
24
|
-
s.add_development_dependency "
|
25
|
-
s.add_development_dependency "
|
26
|
-
s.add_development_dependency "
|
27
|
-
|
28
|
-
s.
|
29
|
-
|
30
|
-
s.
|
31
|
-
s.
|
32
|
-
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path("../lib/by_star/version", __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = "by_star"
|
6
|
+
s.version = ByStar::VERSION
|
7
|
+
s.authors = ["Ryan Bigg", "Johnny Shields"]
|
8
|
+
s.email = ["radarlistener@gmail.com"]
|
9
|
+
s.homepage = "http://github.com/radar/by_star"
|
10
|
+
s.summary = "ActiveRecord and Mongoid extension for easier date scopes and time ranges"
|
11
|
+
s.description = "ActiveRecord and Mongoid extension for easier date scopes and time ranges"
|
12
|
+
|
13
|
+
s.required_ruby_version = '>= 2.0.0'
|
14
|
+
|
15
|
+
s.post_install_message = File.read('UPGRADING') if File.exists?('UPGRADING')
|
16
|
+
|
17
|
+
s.add_dependency "activesupport", "> 3"
|
18
|
+
|
19
|
+
s.add_development_dependency "chronic"
|
20
|
+
s.add_development_dependency "bundler"
|
21
|
+
s.add_development_dependency "sqlite3"
|
22
|
+
s.add_development_dependency "activerecord"
|
23
|
+
s.add_development_dependency "mongoid"
|
24
|
+
s.add_development_dependency "pg"
|
25
|
+
s.add_development_dependency "mysql2", "~> 0.3.10"
|
26
|
+
s.add_development_dependency "rspec-rails", "~> 3.1"
|
27
|
+
s.add_development_dependency "timecop", "~> 0.3"
|
28
|
+
s.add_development_dependency "pry"
|
29
|
+
|
30
|
+
s.files = `git ls-files`.split($/)
|
31
|
+
s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
32
|
+
s.test_files = s.files.grep(%r{^(test|spec|features)/})
|
33
|
+
s.require_paths = ['lib']
|
34
|
+
end
|
data/cleaner.rb
CHANGED
@@ -1,25 +1,25 @@
|
|
1
|
-
files = Dir["**/*"]
|
2
|
-
ignored_files = [
|
3
|
-
/log\/.*/,
|
4
|
-
]
|
5
|
-
|
6
|
-
files.delete_if do |file|
|
7
|
-
if File.directory?(file)
|
8
|
-
true
|
9
|
-
else
|
10
|
-
ignored_files.any? do |condition|
|
11
|
-
if condition.is_a?(String)
|
12
|
-
file == condition
|
13
|
-
else
|
14
|
-
condition.match(file)
|
15
|
-
end
|
16
|
-
end || false
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
for file in files - ignored_files
|
21
|
-
if File.file?(file)
|
22
|
-
lines = File.readlines(file).map { |line| line.gsub(/^\s+$/, "\n") }
|
23
|
-
File.open(file, "w+") { |f| f.write(lines.join) }
|
24
|
-
end
|
1
|
+
files = Dir["**/*"]
|
2
|
+
ignored_files = [
|
3
|
+
/log\/.*/,
|
4
|
+
]
|
5
|
+
|
6
|
+
files.delete_if do |file|
|
7
|
+
if File.directory?(file)
|
8
|
+
true
|
9
|
+
else
|
10
|
+
ignored_files.any? do |condition|
|
11
|
+
if condition.is_a?(String)
|
12
|
+
file == condition
|
13
|
+
else
|
14
|
+
condition.match(file)
|
15
|
+
end
|
16
|
+
end || false
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
for file in files - ignored_files
|
21
|
+
if File.file?(file)
|
22
|
+
lines = File.readlines(file).map { |line| line.gsub(/^\s+$/, "\n") }
|
23
|
+
File.open(file, "w+") { |f| f.write(lines.join) }
|
24
|
+
end
|
25
25
|
end
|
data/lib/by_star.rb
CHANGED
@@ -1,16 +1,17 @@
|
|
1
|
-
require 'by_star/kernel/time'
|
2
|
-
require 'by_star/kernel/date'
|
3
|
-
require 'by_star/normalization'
|
4
|
-
require 'by_star/between'
|
5
|
-
require 'by_star/directional'
|
6
|
-
require 'by_star/base'
|
7
|
-
|
8
|
-
if defined?(ActiveRecord)
|
9
|
-
require 'by_star/orm/active_record/by_star'
|
10
|
-
ActiveRecord::Base.send :include, ByStar::ActiveRecord
|
11
|
-
ActiveRecord::Relation.send :extend, ByStar::ActiveRecord::ClassMethods
|
12
|
-
end
|
13
|
-
|
14
|
-
if defined?(Mongoid)
|
15
|
-
require 'by_star/orm/mongoid/
|
16
|
-
|
1
|
+
require 'by_star/kernel/time'
|
2
|
+
require 'by_star/kernel/date'
|
3
|
+
require 'by_star/normalization'
|
4
|
+
require 'by_star/between'
|
5
|
+
require 'by_star/directional'
|
6
|
+
require 'by_star/base'
|
7
|
+
|
8
|
+
if defined?(ActiveRecord)
|
9
|
+
require 'by_star/orm/active_record/by_star'
|
10
|
+
ActiveRecord::Base.send :include, ByStar::ActiveRecord
|
11
|
+
ActiveRecord::Relation.send :extend, ByStar::ActiveRecord::ClassMethods
|
12
|
+
end
|
13
|
+
|
14
|
+
if defined?(Mongoid)
|
15
|
+
require 'by_star/orm/mongoid/reorder'
|
16
|
+
require 'by_star/orm/mongoid/by_star'
|
17
|
+
end
|
data/lib/by_star/base.rb
CHANGED
@@ -1,70 +1,68 @@
|
|
1
|
-
module ByStar
|
2
|
-
|
3
|
-
module Base
|
4
|
-
|
5
|
-
include ByStar::Between
|
6
|
-
include ByStar::Directional
|
7
|
-
|
8
|
-
def by_star_field(*args)
|
9
|
-
options = args.extract_options!
|
10
|
-
@by_star_start_field ||= args[0]
|
11
|
-
@by_star_end_field ||= args[1]
|
12
|
-
@by_star_offset ||= options[:offset]
|
13
|
-
@by_star_scope ||= options[:scope]
|
14
|
-
end
|
15
|
-
|
16
|
-
def by_star_offset(options = {})
|
17
|
-
(options[:offset] || @by_star_offset || 0).seconds
|
18
|
-
end
|
19
|
-
|
20
|
-
def by_star_start_field(options={})
|
21
|
-
field = options[:field] ||
|
22
|
-
options[:start_field] ||
|
23
|
-
@by_star_start_field ||
|
24
|
-
by_star_default_field
|
25
|
-
field.to_s
|
26
|
-
end
|
27
|
-
|
28
|
-
def by_star_end_field(options={})
|
29
|
-
field = options[:field] ||
|
30
|
-
options[:end_field] ||
|
31
|
-
@by_star_end_field ||
|
32
|
-
by_star_start_field
|
33
|
-
field.to_s
|
34
|
-
end
|
35
|
-
|
36
|
-
def by_star_scope(options={})
|
37
|
-
scope = options[:scope] || @by_star_scope || self
|
38
|
-
if scope.is_a?(Proc)
|
39
|
-
if scope.arity == 0
|
40
|
-
return instance_exec(&scope)
|
41
|
-
elsif options[:scope_args]
|
42
|
-
return instance_exec(*Array(options[:scope_args]), &scope)
|
43
|
-
else
|
44
|
-
raise 'ByStar :scope
|
45
|
-
end
|
46
|
-
else
|
47
|
-
return scope
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
protected
|
52
|
-
|
53
|
-
# Wrapper function which extracts time and options for each by_star query.
|
54
|
-
# Note the following syntax examples are valid:
|
55
|
-
#
|
56
|
-
# Post.by_month
|
57
|
-
# Post.by_month(2, :
|
58
|
-
# Post.by_month(Time.now)
|
59
|
-
# Post.by_month(Time.now, :
|
60
|
-
# Post.by_month(:
|
61
|
-
#
|
62
|
-
def with_by_star_options(*args, &block)
|
63
|
-
options = args.extract_options!.symbolize_keys!
|
64
|
-
time = args.first
|
65
|
-
time
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
end
|
70
|
-
end
|
1
|
+
module ByStar
|
2
|
+
|
3
|
+
module Base
|
4
|
+
|
5
|
+
include ByStar::Between
|
6
|
+
include ByStar::Directional
|
7
|
+
|
8
|
+
def by_star_field(*args)
|
9
|
+
options = args.extract_options!
|
10
|
+
@by_star_start_field ||= args[0]
|
11
|
+
@by_star_end_field ||= args[1]
|
12
|
+
@by_star_offset ||= options[:offset]
|
13
|
+
@by_star_scope ||= options[:scope]
|
14
|
+
end
|
15
|
+
|
16
|
+
def by_star_offset(options = {})
|
17
|
+
(options[:offset] || @by_star_offset || 0).seconds
|
18
|
+
end
|
19
|
+
|
20
|
+
def by_star_start_field(options={})
|
21
|
+
field = options[:field] ||
|
22
|
+
options[:start_field] ||
|
23
|
+
@by_star_start_field ||
|
24
|
+
by_star_default_field
|
25
|
+
field.to_s
|
26
|
+
end
|
27
|
+
|
28
|
+
def by_star_end_field(options={})
|
29
|
+
field = options[:field] ||
|
30
|
+
options[:end_field] ||
|
31
|
+
@by_star_end_field ||
|
32
|
+
by_star_start_field
|
33
|
+
field.to_s
|
34
|
+
end
|
35
|
+
|
36
|
+
def by_star_scope(options={})
|
37
|
+
scope = options[:scope] || @by_star_scope || self
|
38
|
+
if scope.is_a?(Proc)
|
39
|
+
if scope.arity == 0
|
40
|
+
return instance_exec(&scope)
|
41
|
+
elsif options[:scope_args]
|
42
|
+
return instance_exec(*Array(options[:scope_args]), &scope)
|
43
|
+
else
|
44
|
+
raise 'ByStar :scope Proc requires :scope_args to be specified.'
|
45
|
+
end
|
46
|
+
else
|
47
|
+
return scope
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
protected
|
52
|
+
|
53
|
+
# Wrapper function which extracts time and options for each by_star query.
|
54
|
+
# Note the following syntax examples are valid:
|
55
|
+
#
|
56
|
+
# Post.by_month # defaults to current time
|
57
|
+
# Post.by_month(2, year: 2004) # February, 2004
|
58
|
+
# Post.by_month(Time.now)
|
59
|
+
# Post.by_month(Time.now, field: "published_at")
|
60
|
+
# Post.by_month(field: "published_at")
|
61
|
+
#
|
62
|
+
def with_by_star_options(*args, &block)
|
63
|
+
options = args.extract_options!.symbolize_keys!
|
64
|
+
time = args.first || Time.zone.now
|
65
|
+
block.call(time, options)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
data/lib/by_star/between.rb
CHANGED
@@ -1,120 +1,156 @@
|
|
1
|
-
module ByStar
|
2
|
-
|
3
|
-
module Between
|
4
|
-
|
5
|
-
def between_times(
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
def
|
62
|
-
with_by_star_options(*args) do |time, options|
|
63
|
-
time = ByStar::Normalization.
|
64
|
-
between_times(time.
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
def
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
end
|
103
|
-
|
104
|
-
def
|
105
|
-
|
106
|
-
end
|
107
|
-
|
108
|
-
def
|
109
|
-
|
110
|
-
end
|
111
|
-
|
112
|
-
def
|
113
|
-
|
114
|
-
end
|
115
|
-
|
116
|
-
def
|
117
|
-
between_times(Time.zone.now, Time.zone.now
|
118
|
-
end
|
119
|
-
|
120
|
-
|
1
|
+
module ByStar
|
2
|
+
|
3
|
+
module Between
|
4
|
+
|
5
|
+
def between_times(*args)
|
6
|
+
options = args.extract_options!.symbolize_keys!
|
7
|
+
|
8
|
+
start_time, end_time = case args[0]
|
9
|
+
when Array, Range then [args[0].first, args[0].last]
|
10
|
+
else args[0..1]
|
11
|
+
end
|
12
|
+
|
13
|
+
offset = (options[:offset] || 0).seconds
|
14
|
+
start_time += offset if start_time
|
15
|
+
end_time += offset if end_time
|
16
|
+
|
17
|
+
start_field = by_star_start_field(options)
|
18
|
+
end_field = by_star_end_field(options)
|
19
|
+
scope = by_star_scope(options)
|
20
|
+
|
21
|
+
scope = if !start_time && !end_time
|
22
|
+
scope # do nothing
|
23
|
+
elsif !end_time
|
24
|
+
by_star_after_query(scope, start_field, start_time)
|
25
|
+
elsif !start_time
|
26
|
+
by_star_before_query(scope, start_field, end_time)
|
27
|
+
elsif start_field == end_field
|
28
|
+
by_star_point_query(scope, start_field, start_time, end_time)
|
29
|
+
elsif options[:strict]
|
30
|
+
by_star_span_strict_query(scope, start_field, end_field, start_time, end_time)
|
31
|
+
else
|
32
|
+
by_star_span_overlap_query(scope, start_field, end_field, start_time, end_time, options)
|
33
|
+
end
|
34
|
+
|
35
|
+
scope = by_star_order(scope, options[:order]) if options[:order]
|
36
|
+
|
37
|
+
scope
|
38
|
+
end
|
39
|
+
|
40
|
+
def by_day(*args)
|
41
|
+
with_by_star_options(*args) do |time, options|
|
42
|
+
time = ByStar::Normalization.time(time)
|
43
|
+
between_times(time.beginning_of_day, time.end_of_day, options)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def by_week(*args)
|
48
|
+
with_by_star_options(*args) do |time, options|
|
49
|
+
time = ByStar::Normalization.week(time, options)
|
50
|
+
start_day = Array(options[:start_day])
|
51
|
+
between_times(time.beginning_of_week(*start_day), time.end_of_week(*start_day), options)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def by_cweek(*args)
|
56
|
+
with_by_star_options(*args) do |time, options|
|
57
|
+
by_week(ByStar::Normalization.cweek(time, options), options)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def by_weekend(*args)
|
62
|
+
with_by_star_options(*args) do |time, options|
|
63
|
+
time = ByStar::Normalization.week(time, options)
|
64
|
+
between_times(time.beginning_of_weekend, time.end_of_weekend, options)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def by_fortnight(*args)
|
69
|
+
with_by_star_options(*args) do |time, options|
|
70
|
+
time = ByStar::Normalization.fortnight(time, options)
|
71
|
+
between_times(time.beginning_of_fortnight, time.end_of_fortnight, options)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def by_month(*args)
|
76
|
+
with_by_star_options(*args) do |time, options|
|
77
|
+
time = ByStar::Normalization.month(time, options)
|
78
|
+
between_times(time.beginning_of_month, time.end_of_month, options)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
def by_calendar_month(*args)
|
83
|
+
with_by_star_options(*args) do |time, options|
|
84
|
+
time = ByStar::Normalization.month(time, options)
|
85
|
+
start_day = Array(options[:start_day])
|
86
|
+
between_times(time.beginning_of_calendar_month(*start_day), time.end_of_calendar_month(*start_day), options)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
def by_quarter(*args)
|
91
|
+
with_by_star_options(*args) do |time, options|
|
92
|
+
time = ByStar::Normalization.quarter(time, options)
|
93
|
+
between_times(time.beginning_of_quarter, time.end_of_quarter, options)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
def by_year(*args)
|
98
|
+
with_by_star_options(*args) do |time, options|
|
99
|
+
time = ByStar::Normalization.year(time, options)
|
100
|
+
between_times(time.beginning_of_year, time.end_of_year, options)
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
def today(options={})
|
105
|
+
by_day(Time.zone.now, options)
|
106
|
+
end
|
107
|
+
|
108
|
+
def yesterday(options={})
|
109
|
+
by_day(Time.zone.now.yesterday, options)
|
110
|
+
end
|
111
|
+
|
112
|
+
def tomorrow(options={})
|
113
|
+
by_day(Time.zone.now.tomorrow, options)
|
114
|
+
end
|
115
|
+
|
116
|
+
def past_day(options={})
|
117
|
+
between_times(Time.zone.now - 1.day, Time.zone.now, options)
|
118
|
+
end
|
119
|
+
|
120
|
+
def past_week(options={})
|
121
|
+
between_times(Time.zone.now - 1.week, Time.zone.now, options)
|
122
|
+
end
|
123
|
+
|
124
|
+
def past_fortnight(options={})
|
125
|
+
between_times(Time.zone.now - 2.weeks, Time.zone.now, options)
|
126
|
+
end
|
127
|
+
|
128
|
+
def past_month(options={})
|
129
|
+
between_times(Time.zone.now - 1.month, Time.zone.now, options)
|
130
|
+
end
|
131
|
+
|
132
|
+
def past_year(options={})
|
133
|
+
between_times(Time.zone.now - 1.year, Time.zone.now, options)
|
134
|
+
end
|
135
|
+
|
136
|
+
def next_day(options={})
|
137
|
+
between_times(Time.zone.now, Time.zone.now + 1.day, options)
|
138
|
+
end
|
139
|
+
|
140
|
+
def next_week(options={})
|
141
|
+
between_times(Time.zone.now, Time.zone.now + 1.week, options)
|
142
|
+
end
|
143
|
+
|
144
|
+
def next_fortnight(options={})
|
145
|
+
between_times(Time.zone.now, Time.zone.now + 2.weeks, options)
|
146
|
+
end
|
147
|
+
|
148
|
+
def next_month(options={})
|
149
|
+
between_times(Time.zone.now, Time.zone.now + 1.month, options)
|
150
|
+
end
|
151
|
+
|
152
|
+
def next_year(options={})
|
153
|
+
between_times(Time.zone.now, Time.zone.now + 1.year, options)
|
154
|
+
end
|
155
|
+
end
|
156
|
+
end
|