by_star 2.2.0 → 4.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.
Files changed (66) hide show
  1. checksums.yaml +5 -13
  2. data/.github/workflows/mysql.yml +92 -0
  3. data/.github/workflows/postgresql.yml +99 -0
  4. data/.gitignore +6 -5
  5. data/.travis.yml +92 -35
  6. data/CHANGELOG.md +59 -29
  7. data/Gemfile +18 -25
  8. data/MIT-LICENSE +20 -20
  9. data/README.md +616 -523
  10. data/Rakefile +18 -18
  11. data/UPGRADING +4 -12
  12. data/by_star.gemspec +34 -32
  13. data/cleaner.rb +24 -24
  14. data/lib/by_star/base.rb +69 -68
  15. data/lib/by_star/between.rb +185 -120
  16. data/lib/by_star/directional.rb +35 -21
  17. data/lib/by_star/kernel/date.rb +41 -0
  18. data/lib/by_star/kernel/in_time_zone.rb +20 -0
  19. data/lib/by_star/{kernel.rb → kernel/time.rb} +41 -41
  20. data/lib/by_star/normalization.rb +156 -118
  21. data/lib/by_star/orm/active_record/by_star.rb +75 -59
  22. data/lib/by_star/orm/mongoid/by_star.rb +90 -63
  23. data/lib/by_star/orm/mongoid/reorder.rb +23 -0
  24. data/lib/by_star/version.rb +3 -3
  25. data/lib/by_star.rb +18 -15
  26. data/spec/database.yml +15 -15
  27. data/spec/fixtures/active_record/models.rb +12 -10
  28. data/spec/fixtures/active_record/schema.rb +19 -19
  29. data/spec/fixtures/mongoid/models.rb +31 -29
  30. data/spec/fixtures/shared/seeds.rb +36 -26
  31. data/spec/gemfiles/Gemfile.rails +5 -0
  32. data/spec/gemfiles/Gemfile.rails32 +7 -0
  33. data/spec/gemfiles/Gemfile.rails40 +7 -0
  34. data/spec/gemfiles/Gemfile.rails41 +7 -0
  35. data/spec/gemfiles/Gemfile.rails42 +7 -0
  36. data/spec/gemfiles/Gemfile.rails50 +7 -0
  37. data/spec/gemfiles/Gemfile.rails51 +7 -0
  38. data/spec/gemfiles/Gemfile.rails52 +7 -0
  39. data/spec/gemfiles/Gemfile.rails60 +7 -0
  40. data/spec/gemfiles/Gemfile.rails61 +7 -0
  41. data/spec/integration/active_record/active_record_spec.rb +41 -53
  42. data/spec/integration/mongoid/mongoid_spec.rb +39 -46
  43. data/spec/integration/shared/at_time.rb +53 -0
  44. data/spec/integration/shared/between_dates.rb +99 -0
  45. data/spec/integration/shared/between_times.rb +99 -0
  46. data/spec/integration/shared/by_calendar_month.rb +55 -55
  47. data/spec/integration/shared/by_cweek.rb +54 -0
  48. data/spec/integration/shared/by_day.rb +120 -108
  49. data/spec/integration/shared/by_direction.rb +126 -114
  50. data/spec/integration/shared/by_fortnight.rb +48 -48
  51. data/spec/integration/shared/by_month.rb +50 -50
  52. data/spec/integration/shared/by_quarter.rb +49 -49
  53. data/spec/integration/shared/by_week.rb +54 -54
  54. data/spec/integration/shared/by_weekend.rb +49 -49
  55. data/spec/integration/shared/by_year.rb +48 -48
  56. data/spec/integration/shared/index_scope_parameter.rb +111 -0
  57. data/spec/integration/shared/offset_parameter.rb +32 -31
  58. data/spec/integration/shared/order_parameter.rb +36 -0
  59. data/spec/integration/shared/relative.rb +174 -174
  60. data/spec/spec_helper.rb +33 -29
  61. data/spec/unit/kernel_date_spec.rb +113 -0
  62. data/spec/unit/kernel_time_spec.rb +57 -57
  63. data/spec/unit/normalization_spec.rb +384 -255
  64. data/tmp/.gitignore +1 -1
  65. metadata +82 -68
  66. data/spec/integration/shared/scope_parameter.rb +0 -42
@@ -1,57 +1,57 @@
1
- require 'spec_helper'
2
-
3
- describe Time do
4
-
5
- describe 'weekend' do
6
-
7
- (0..6).each do |n|
8
- context "Monday plus #{n} days" do
9
- subject { Time.zone.parse('2014-01-06') + n.days }
10
- its(:beginning_of_weekend){ should eq Time.zone.parse('2014-01-10 15:00') }
11
- its(:end_of_weekend){ should eq Time.zone.parse('2014-01-13 02:00').end_of_hour }
12
- end
13
- end
14
- end
15
-
16
- describe 'fortnight' do
17
-
18
- context 'first day of year' do
19
- subject { Time.zone.parse '2014-01-01' }
20
- its(:beginning_of_fortnight){ should eq Time.zone.parse('2014-01-01') }
21
- its(:end_of_fortnight){ should eq Time.zone.parse('2014-01-14').end_of_day }
22
- end
23
-
24
- context 'second fortnight of year' do
25
- subject { Time.zone.parse '2014-01-16' }
26
- its(:beginning_of_fortnight){ should eq Time.zone.parse('2014-01-15') }
27
- its(:end_of_fortnight){ should eq Time.zone.parse('2014-01-28').end_of_day }
28
- end
29
-
30
- context 'middle of year' do
31
- subject { Time.zone.parse '2014-06-13' }
32
- its(:beginning_of_fortnight){ should eq Time.zone.parse('2014-06-04') }
33
- its(:end_of_fortnight){ should eq Time.zone.parse('2014-06-17').end_of_day }
34
- end
35
-
36
- context 'last day of year' do
37
- subject { Time.zone.parse '2014-12-31' }
38
- its(:beginning_of_fortnight){ should eq Time.zone.parse('2014-12-31') }
39
- its(:end_of_fortnight){ should eq Time.zone.parse('2015-01-13').end_of_day }
40
- end
41
- end
42
-
43
- describe 'calendar_month' do
44
-
45
- subject { Time.zone.parse '2014-01-01' }
46
-
47
- context 'week begins Monday' do
48
- its(:beginning_of_calendar_month){ should eq Time.zone.parse('2013-12-30') }
49
- its(:end_of_calendar_month){ should eq Time.zone.parse('2014-02-02').end_of_day }
50
- end
51
-
52
- context 'week begins Sunday' do
53
- it { subject.beginning_of_calendar_month(:sunday).should eq Time.zone.parse('2013-12-29') }
54
- it { subject.end_of_calendar_month(:sunday).should eq Time.zone.parse('2014-02-01').end_of_day }
55
- end
56
- end
57
- end
1
+ require 'spec_helper'
2
+
3
+ describe Time do
4
+
5
+ describe 'weekend' do
6
+
7
+ (0..6).each do |n|
8
+ context "Monday plus #{n} days" do
9
+ subject { Time.zone.parse('2014-01-06') + n.days }
10
+ it { expect(subject.beginning_of_weekend).to eq Time.zone.parse('2014-01-11') }
11
+ it { expect(subject.end_of_weekend).to eq Time.zone.parse('2014-01-12').end_of_day }
12
+ end
13
+ end
14
+ end
15
+
16
+ describe 'fortnight' do
17
+
18
+ context 'first day of year' do
19
+ subject { Time.zone.parse '2014-01-01' }
20
+ it { expect(subject.beginning_of_fortnight).to eq Time.zone.parse('2014-01-01') }
21
+ it { expect(subject.end_of_fortnight).to eq Time.zone.parse('2014-01-14').end_of_day }
22
+ end
23
+
24
+ context 'second fortnight of year' do
25
+ subject { Time.zone.parse '2014-01-16' }
26
+ it { expect(subject.beginning_of_fortnight).to eq Time.zone.parse('2014-01-15') }
27
+ it { expect(subject.end_of_fortnight).to eq Time.zone.parse('2014-01-28').end_of_day }
28
+ end
29
+
30
+ context 'middle of year' do
31
+ subject { Time.zone.parse '2014-06-13' }
32
+ it { expect(subject.beginning_of_fortnight).to eq Time.zone.parse('2014-06-04') }
33
+ it { expect(subject.end_of_fortnight).to eq Time.zone.parse('2014-06-17').end_of_day }
34
+ end
35
+
36
+ context 'last day of year' do
37
+ subject { Time.zone.parse '2014-12-31' }
38
+ it { expect(subject.beginning_of_fortnight).to eq Time.zone.parse('2014-12-31') }
39
+ it { expect(subject.end_of_fortnight).to eq Time.zone.parse('2015-01-13').end_of_day }
40
+ end
41
+ end
42
+
43
+ describe 'calendar_month' do
44
+
45
+ subject { Time.zone.parse '2014-01-01' }
46
+
47
+ context 'week begins Monday' do
48
+ it { expect(subject.beginning_of_calendar_month).to eq Time.zone.parse('2013-12-30') }
49
+ it { expect(subject.end_of_calendar_month).to eq Time.zone.parse('2014-02-02').end_of_day }
50
+ end
51
+
52
+ context 'week begins Sunday' do
53
+ it { expect(subject.beginning_of_calendar_month(:sunday)).to eq Time.zone.parse('2013-12-29') }
54
+ it { expect(subject.end_of_calendar_month(:sunday)).to eq Time.zone.parse('2014-02-01').end_of_day }
55
+ end
56
+ end
57
+ end