readable_date_ranges 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/readable_date_ranges.rb +37 -0
  3. metadata +44 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 70850b77bc7c9d0c505edf62c63c187ea8103ef5
4
+ data.tar.gz: 2747aff465e6e973bd24a87e268fc33bdf20f81a
5
+ SHA512:
6
+ metadata.gz: d2c6246d613f68f08c51cfef5a324d03c838b48d8aa195d66bebf7dec13b43fd811d8e47a0b47af83ef38bce76580add95de912dae81a9bf226bf447253a8af6
7
+ data.tar.gz: 538ff86ff8d45a8b01177b2f21aee8ee5fd81124baec5351de44edd229ee5bcfb4436a1902c558c965a8e68abd9d9936fa457c24c084ca5f2a05fbc1a6d835d5
@@ -0,0 +1,37 @@
1
+ module ReadableDateRanges
2
+ def self.included(base)
3
+ this_week_start = Date.today.at_beginning_of_week.beginning_of_day
4
+ this_week_end = Date.today.at_end_of_week.end_of_day
5
+ last_week_start = 1.week.ago.at_beginning_of_week.beginning_of_day
6
+ last_week_end = 1.week.ago.at_end_of_week.end_of_day
7
+ this_month_start = Date.today.at_beginning_of_month.beginning_of_day
8
+ this_month_end = Date.today.at_end_of_month.end_of_day
9
+ last_month_start = 1.month.ago.at_beginning_of_month.beginning_of_day
10
+ last_month_end = 1.month.ago.at_end_of_month.end_of_day
11
+ this_year_start = Date.today.at_beginning_of_year.beginning_of_day
12
+ this_year_end = Date.today.at_end_of_year.end_of_day
13
+ last_year_start = 1.year.ago.at_beginning_of_year.beginning_of_day
14
+ last_year_end = 1.year.ago.at_end_of_year.end_of_day
15
+
16
+ base.scope :created_this_week, -> { base.where("created_at between ? AND ?", this_week_start, this_week_end) }
17
+ base.scope :created_last_week, -> { base.where("created_at between ? AND ?", last_week_start, last_week_end) }
18
+ base.scope :created_this_month, -> { base.where("created_at between ? AND ?", this_month_start, this_month_end) }
19
+ base.scope :created_last_month, -> { base.where("created_at between ? AND ?", last_month_start, last_month_end) }
20
+ base.scope :created_this_year, -> { base.where("created_at between ? AND ?", this_year_start, this_year_end) }
21
+ base.scope :created_last_year, -> { base.where("created_at between ? AND ?", last_year_start, last_year_end) }
22
+
23
+ base.scope :updated_this_week, -> { base.where("updated_at between ? AND ?", this_week_start, this_week_end) }
24
+ base.scope :updated_last_week, -> { base.where("updated_at between ? AND ?", last_week_start, last_week_end) }
25
+ base.scope :updated_this_month, -> { base.where("updated_at between ? AND ?", this_month_start, this_month_end) }
26
+ base.scope :updated_last_month, -> { base.where("updated_at between ? AND ?", last_month_start, last_month_end) }
27
+ base.scope :updated_this_year, -> { base.where("updated_at between ? AND ?", this_year_start, this_year_end) }
28
+ base.scope :updated_last_year, -> { base.where("updated_at between ? AND ?", last_year_start, last_year_end) }
29
+
30
+ base.scope :created_or_updated_this_week, -> { base.where("(created_at between ? AND ?) OR (updated_at between ? AND ?)", this_week_start, this_week_end, this_week_start, this_week_end) }
31
+ base.scope :created_or_updated_last_week, -> { base.where("(created_at between ? AND ?) OR (updated_at between ? AND ?)", last_week_start, last_week_end, last_week_start, last_week_end) }
32
+ base.scope :created_or_updated_this_month, -> { base.where("(created_at between ? AND ?) OR (updated_at between ? AND ?)", this_month_start, this_month_end, this_month_start, this_month_end) }
33
+ base.scope :created_or_updated_last_month, -> { base.where("(created_at between ? AND ?) OR (updated_at between ? AND ?)", last_month_start, last_month_end, last_month_start, last_month_end) }
34
+ base.scope :created_or_updated_this_year, -> { base.where("(created_at between ? AND ?) OR (updated_at between ? AND ?)", this_year_start, this_year_end, this_year_start, this_year_end) }
35
+ base.scope :created_or_updated_last_year, -> { base.where("(created_at between ? AND ?) OR (updated_at between ? AND ?)", last_year_start, last_year_end, last_year_start, last_year_end) }
36
+ end
37
+ end
metadata ADDED
@@ -0,0 +1,44 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: readable_date_ranges
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Kevin Kaske
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-11-27 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: 'Add readable range selections to Active Record Models '
14
+ email: kevinkaske@gmail.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - lib/readable_date_ranges.rb
20
+ homepage: https://github.com/kevinkaske/readable_date_ranges
21
+ licenses:
22
+ - Apache 2.0
23
+ metadata: {}
24
+ post_install_message:
25
+ rdoc_options: []
26
+ require_paths:
27
+ - lib
28
+ required_ruby_version: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ required_rubygems_version: !ruby/object:Gem::Requirement
34
+ requirements:
35
+ - - ">="
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ requirements: []
39
+ rubyforge_project:
40
+ rubygems_version: 2.2.2
41
+ signing_key:
42
+ specification_version: 4
43
+ summary: Readable Range Selections
44
+ test_files: []