date_breakup 2.0.0 → 3.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -1
- data/Gemfile +2 -2
- data/Gemfile.lock +43 -0
- data/README.md +103 -4
- data/Rakefile +3 -3
- data/bin/console +3 -3
- data/date_breakup.gemspec +20 -21
- data/lib/date_breakup.rb +37 -171
- metadata +38 -22
- data/lib/date_breakup/version.rb +0 -3
- data/lib/date_breakup_v1.rb +0 -215
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 21887235144f6659466a3e0d709417dab4bd9d9dd6f5686e036e01f8890d8e3d
|
4
|
+
data.tar.gz: 7842cf3953652600cd749bd8a1b212d4967476f0aade5899dba0100ddb642ed2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1b964d8d15cb315b57fef5109c2c013fdfbfe0f740d09eea092152ae02b29bda6dffb852cd77138d462ad99b3b9105f23b7b3e759119078ae5014d5e03045a87
|
7
|
+
data.tar.gz: 37aaf14964872d38432d51135915065913224db2f82d9e813946b5bccfafaf4b8fbbe29d720d641ebd23b0fc77b889bf9f36c9169d5d6483e21038d1d5715b55
|
data/.gitignore
CHANGED
data/Gemfile
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
source
|
1
|
+
source 'https://rubygems.org'
|
2
2
|
|
3
|
-
git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
|
3
|
+
git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
|
4
4
|
|
5
5
|
# Specify your gem's dependencies in date_breakup.gemspec
|
6
6
|
gemspec
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
date_breakup (3.0.1)
|
5
|
+
date (~> 3.1, >= 3.1.1)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
coderay (1.1.3)
|
11
|
+
date (3.1.1)
|
12
|
+
diff-lcs (1.4.4)
|
13
|
+
method_source (1.0.0)
|
14
|
+
pry (0.14.1)
|
15
|
+
coderay (~> 1.1)
|
16
|
+
method_source (~> 1.0)
|
17
|
+
rake (13.0.3)
|
18
|
+
rspec (3.10.0)
|
19
|
+
rspec-core (~> 3.10.0)
|
20
|
+
rspec-expectations (~> 3.10.0)
|
21
|
+
rspec-mocks (~> 3.10.0)
|
22
|
+
rspec-core (3.10.1)
|
23
|
+
rspec-support (~> 3.10.0)
|
24
|
+
rspec-expectations (3.10.1)
|
25
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
26
|
+
rspec-support (~> 3.10.0)
|
27
|
+
rspec-mocks (3.10.2)
|
28
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
29
|
+
rspec-support (~> 3.10.0)
|
30
|
+
rspec-support (3.10.2)
|
31
|
+
|
32
|
+
PLATFORMS
|
33
|
+
x86_64-darwin-20
|
34
|
+
|
35
|
+
DEPENDENCIES
|
36
|
+
bundler (~> 2.2, >= 2.2.20)
|
37
|
+
date_breakup!
|
38
|
+
pry (~> 0.14.1)
|
39
|
+
rake (~> 13.0, >= 13.0.3)
|
40
|
+
rspec (~> 3.10)
|
41
|
+
|
42
|
+
BUNDLED WITH
|
43
|
+
2.2.20
|
data/README.md
CHANGED
@@ -1,4 +1,10 @@
|
|
1
1
|
# DateBreakup
|
2
|
+
VERSION 3 is Live Now.
|
3
|
+
|
4
|
+
What's New?
|
5
|
+
- The code to generate data has been cleaned and made dynamic.
|
6
|
+
- Dependencies has been updated.
|
7
|
+
- The class name has changed and methods too. (Please refer the examples below)
|
2
8
|
|
3
9
|
## Installation
|
4
10
|
|
@@ -20,11 +26,103 @@ Or install it yourself as:
|
|
20
26
|
|
21
27
|
### Pass in 2 Date(String) & get a breakup of dates in years, months, weeks & days
|
22
28
|
|
29
|
+
#### FOR YEARS (BREAKUP in YEARS, MONTHS, WEEKS, DAYS)
|
23
30
|
```ruby
|
24
|
-
DateBreakup::Range.between('01/01/2019', '31/12/2019').
|
31
|
+
# Was: DateBreakup::Range.between('01/01/2019', '31/12/2019').get_years
|
32
|
+
DateBreakup.between('01/01/2019', '31/12/2019').in_years
|
25
33
|
=> {
|
26
34
|
:years=>[
|
27
35
|
{:year=>2019, :start_date=>Sat, 01 Jan 2019, :end_date=>Sat, 31 Dec 2019}
|
36
|
+
],
|
37
|
+
:months=>[],
|
38
|
+
:weeks=>[],
|
39
|
+
:days=>[]
|
40
|
+
}
|
41
|
+
```
|
42
|
+
|
43
|
+
#### FOR MONTHS (BREAKUP in MONTHS, WEEKS, DAYS)
|
44
|
+
```ruby
|
45
|
+
# Was: DateBreakup::Range.between('01/01/2019', '31/12/2019').get_months
|
46
|
+
DateBreakup.between('01/01/2019', '31/12/2019').in_months
|
47
|
+
=> {
|
48
|
+
:years=>[],
|
49
|
+
:months=>[
|
50
|
+
{:month=>1, :year=>2019, :start_date=>Tue, 01 Jan 2019, :end_date=>Thu, 31 Jan 2019},
|
51
|
+
{:month=>2, :year=>2019, :start_date=>Fri, 01 Feb 2019, :end_date=>Thu, 28 Feb 2019},
|
52
|
+
{:month=>3, :year=>2019, :start_date=>Fri, 01 Mar 2019, :end_date=>Sun, 31 Mar 2019},
|
53
|
+
{:month=>4, :year=>2019, :start_date=>Mon, 01 Apr 2019, :end_date=>Tue, 30 Apr 2019},
|
54
|
+
{:month=>5, :year=>2019, :start_date=>Wed, 01 May 2019, :end_date=>Fri, 31 May 2019},
|
55
|
+
{:month=>6, :year=>2019, :start_date=>Sat, 01 Jun 2019, :end_date=>Sun, 30 Jun 2019},
|
56
|
+
{:month=>7, :year=>2019, :start_date=>Mon, 01 Jul 2019, :end_date=>Wed, 31 Jul 2019},
|
57
|
+
{:month=>8, :year=>2019, :start_date=>Thu, 01 Aug 2019, :end_date=>Sat, 31 Aug 2019},
|
58
|
+
{:month=>9, :year=>2019, :start_date=>Sun, 01 Sep 2019, :end_date=>Mon, 30 Sep 2019},
|
59
|
+
{:month=>10, :year=>2019, :start_date=>Tue, 01 Oct 2019, :end_date=>Thu, 31 Oct 2019},
|
60
|
+
{:month=>11, :year=>2019, :start_date=>Fri, 01 Nov 2019, :end_date=>Sat, 30 Nov 2019},
|
61
|
+
{:month=>12, :year=>2019, :start_date=>Sun, 01 Dec 2019, :end_date=>Tue, 31 Dec 2019}
|
62
|
+
],
|
63
|
+
:weeks=>[],
|
64
|
+
:days=>[]
|
65
|
+
}
|
66
|
+
```
|
67
|
+
#### FOR WEEKS (BREAKUP in WEEKS, DAYS)
|
68
|
+
```ruby
|
69
|
+
# Was: DateBreakup::Range.between('01/01/2019', '31/12/2019').get_weeks
|
70
|
+
DateBreakup.between('01/01/2019', '31/12/2019').in_weeks
|
71
|
+
=> {
|
72
|
+
:years=>[],
|
73
|
+
:months=>[],
|
74
|
+
:weeks=>[
|
75
|
+
{:week=>2, :month=>1, :year=>2019, :start_date=>Mon, 07 Jan 2019, :end_date=>Sun, 13 Jan 2019},
|
76
|
+
{:week=>3, :month=>1, :year=>2019, :start_date=>Mon, 14 Jan 2019, :end_date=>Sun, 20 Jan 2019},
|
77
|
+
{:week=>4, :month=>1, :year=>2019, :start_date=>Mon, 21 Jan 2019, :end_date=>Sun, 27 Jan 2019},
|
78
|
+
{:week=>5, :month=>1, :year=>2019, :start_date=>Mon, 28 Jan 2019, :end_date=>Sun, 03 Feb 2019},
|
79
|
+
{:week=>6, :month=>2, :year=>2019, :start_date=>Mon, 04 Feb 2019, :end_date=>Sun, 10 Feb 2019},
|
80
|
+
{:week=>7, :month=>2, :year=>2019, :start_date=>Mon, 11 Feb 2019, :end_date=>Sun, 17 Feb 2019},
|
81
|
+
{:week=>8, :month=>2, :year=>2019, :start_date=>Mon, 18 Feb 2019, :end_date=>Sun, 24 Feb 2019},
|
82
|
+
{:week=>9, :month=>2, :year=>2019, :start_date=>Mon, 25 Feb 2019, :end_date=>Sun, 03 Mar 2019},
|
83
|
+
{:week=>10, :month=>3, :year=>2019, :start_date=>Mon, 04 Mar 2019, :end_date=>Sun, 10 Mar 2019},
|
84
|
+
...
|
85
|
+
{:week=>43, :month=>10, :year=>2019, :start_date=>Mon, 21 Oct 2019, :end_date=>Sun, 27 Oct 2019},
|
86
|
+
{:week=>44, :month=>10, :year=>2019, :start_date=>Mon, 28 Oct 2019, :end_date=>Sun, 03 Nov 2019},
|
87
|
+
{:week=>45, :month=>11, :year=>2019, :start_date=>Mon, 04 Nov 2019, :end_date=>Sun, 10 Nov 2019},
|
88
|
+
{:week=>46, :month=>11, :year=>2019, :start_date=>Mon, 11 Nov 2019, :end_date=>Sun, 17 Nov 2019},
|
89
|
+
{:week=>47, :month=>11, :year=>2019, :start_date=>Mon, 18 Nov 2019, :end_date=>Sun, 24 Nov 2019},
|
90
|
+
{:week=>48, :month=>11, :year=>2019, :start_date=>Mon, 25 Nov 2019, :end_date=>Sun, 01 Dec 2019},
|
91
|
+
{:week=>49, :month=>12, :year=>2019, :start_date=>Mon, 02 Dec 2019, :end_date=>Sun, 08 Dec 2019},
|
92
|
+
{:week=>50, :month=>12, :year=>2019, :start_date=>Mon, 09 Dec 2019, :end_date=>Sun, 15 Dec 2019},
|
93
|
+
{:week=>51, :month=>12, :year=>2019, :start_date=>Mon, 16 Dec 2019, :end_date=>Sun, 22 Dec 2019},
|
94
|
+
{:week=>52, :month=>12, :year=>2019, :start_date=>Mon, 23 Dec 2019, :end_date=>Sun, 29 Dec 2019}
|
95
|
+
],
|
96
|
+
:days=>[
|
97
|
+
{:day=>1, :month_day=>1, :month=>1, :year=>2019, :start_date=>Tue, 01 Jan 2019, :end_date=>Tue, 01 Jan 2019},
|
98
|
+
{:day=>2, :month_day=>2, :month=>1, :year=>2019, :start_date=>Wed, 02 Jan 2019, :end_date=>Wed, 02 Jan 2019},
|
99
|
+
{:day=>3, :month_day=>3, :month=>1, :year=>2019, :start_date=>Thu, 03 Jan 2019, :end_date=>Thu, 03 Jan 2019},
|
100
|
+
{:day=>4, :month_day=>4, :month=>1, :year=>2019, :start_date=>Fri, 04 Jan 2019, :end_date=>Fri, 04 Jan 2019},
|
101
|
+
{:day=>5, :month_day=>5, :month=>1, :year=>2019, :start_date=>Sat, 05 Jan 2019, :end_date=>Sat, 05 Jan 2019},
|
102
|
+
{:day=>6, :month_day=>6, :month=>1, :year=>2019, :start_date=>Sun, 06 Jan 2019, :end_date=>Sun, 06 Jan 2019},
|
103
|
+
{:day=>364, :month_day=>30, :month=>12, :year=>2019, :start_date=>Mon, 30 Dec 2019, :end_date=>Mon, 30 Dec 2019},
|
104
|
+
{:day=>365, :month_day=>31, :month=>12, :year=>2019, :start_date=>Tue, 31 Dec 2019, :end_date=>Tue, 31 Dec 2019}
|
105
|
+
]
|
106
|
+
}
|
107
|
+
```
|
108
|
+
#### FOR DAYS (BREAKUP in DAYS)
|
109
|
+
```ruby
|
110
|
+
# Was: DateBreakup::Range.between('01/01/2019', '31/12/2019').get_days
|
111
|
+
DateBreakup.between('01/01/2019', '31/12/2019').in_days
|
112
|
+
=> {
|
113
|
+
:years=>[],
|
114
|
+
:months=>[],
|
115
|
+
:weeks=>[],
|
116
|
+
:days=>[
|
117
|
+
{:day=>1, :month_day=>1, :month=>1, :year=>2019, :start_date=>Tue, 01 Jan 2019, :end_date=>Tue, 01 Jan 2019},
|
118
|
+
{:day=>2, :month_day=>2, :month=>1, :year=>2019, :start_date=>Wed, 02 Jan 2019, :end_date=>Wed, 02 Jan 2019},
|
119
|
+
{:day=>3, :month_day=>3, :month=>1, :year=>2019, :start_date=>Thu, 03 Jan 2019, :end_date=>Thu, 03 Jan 2019},
|
120
|
+
{:day=>4, :month_day=>4, :month=>1, :year=>2019, :start_date=>Fri, 04 Jan 2019, :end_date=>Fri, 04 Jan 2019},
|
121
|
+
{:day=>5, :month_day=>5, :month=>1, :year=>2019, :start_date=>Sat, 05 Jan 2019, :end_date=>Sat, 05 Jan 2019},
|
122
|
+
{:day=>6, :month_day=>6, :month=>1, :year=>2019, :start_date=>Sun, 06 Jan 2019, :end_date=>Sun, 06 Jan 2019},
|
123
|
+
...
|
124
|
+
{:day=>364, :month_day=>30, :month=>12, :year=>2019, :start_date=>Mon, 30 Dec 2019, :end_date=>Mon, 30 Dec 2019},
|
125
|
+
{:day=>365, :month_day=>31, :month=>12, :year=>2019, :start_date=>Tue, 31 Dec 2019, :end_date=>Tue, 31 Dec 2019}
|
28
126
|
]
|
29
127
|
}
|
30
128
|
```
|
@@ -32,7 +130,8 @@ DateBreakup::Range.between('01/01/2019', '31/12/2019').get_accurate
|
|
32
130
|
### More Further Apart Dates
|
33
131
|
|
34
132
|
```ruby
|
35
|
-
DateBreakup::Range.between('10/10/2010', '12/12/2012').
|
133
|
+
# Was: DateBreakup::Range.between('10/10/2010', '12/12/2012').get_years
|
134
|
+
DateBreakup.between('10/10/2010', '12/12/2012').in_years
|
36
135
|
=> {
|
37
136
|
:years=>[
|
38
137
|
{:year=>2011, :start_date=>Sat, 01 Jan 2011, :end_date=>Sat, 31 Dec 2011}
|
@@ -71,11 +170,11 @@ DateBreakup::Range.between('10/10/2010', '12/12/2012').get_accurate
|
|
71
170
|
|
72
171
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
73
172
|
|
74
|
-
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
173
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org). -->
|
75
174
|
|
76
175
|
## Contributing
|
77
176
|
|
78
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
177
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/HuzaifaSaifuddin/date_breakup.
|
79
178
|
|
80
179
|
## License
|
81
180
|
|
data/Rakefile
CHANGED
data/bin/console
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'date_breakup'
|
5
5
|
|
6
6
|
# You can add fixtures and/or initialization code here to make experimenting
|
7
7
|
# with your gem easier. You can also use a different console, if you like.
|
@@ -10,5 +10,5 @@ require "date_breakup"
|
|
10
10
|
# require "pry"
|
11
11
|
# Pry.start
|
12
12
|
|
13
|
-
require
|
13
|
+
require 'irb'
|
14
14
|
IRB.start(__FILE__)
|
data/date_breakup.gemspec
CHANGED
@@ -1,41 +1,40 @@
|
|
1
|
-
|
2
|
-
lib = File.expand_path("../lib", __FILE__)
|
1
|
+
lib = File.expand_path('lib', __dir__)
|
3
2
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require
|
3
|
+
require 'date_breakup'
|
5
4
|
|
6
5
|
Gem::Specification.new do |spec|
|
7
|
-
spec.name =
|
6
|
+
spec.name = 'date_breakup'
|
8
7
|
spec.version = DateBreakup::VERSION
|
9
|
-
spec.authors = [
|
10
|
-
spec.email = [
|
8
|
+
spec.authors = ['Huzaifa Saifuddin']
|
9
|
+
spec.email = ['Huzaifa@Huzaifas-MacBook-Pro.local']
|
11
10
|
|
12
|
-
spec.summary =
|
13
|
-
spec.description =
|
14
|
-
spec.homepage =
|
15
|
-
spec.license =
|
11
|
+
spec.summary = 'Feed in 2 dates and get a breakup of dates grouped in years, months, weeks & days'
|
12
|
+
spec.description = 'Feed in 2 dates and get a breakup of dates grouped in years, months, weeks & days'
|
13
|
+
spec.homepage = 'https://github.com/HuzaifaSaifuddin/date_breakup'
|
14
|
+
spec.license = 'MIT'
|
16
15
|
|
17
16
|
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
18
17
|
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
19
18
|
if spec.respond_to?(:metadata)
|
20
|
-
spec.metadata[
|
19
|
+
spec.metadata['allowed_push_host'] = 'https://rubygems.org'
|
21
20
|
else
|
22
|
-
raise
|
23
|
-
|
21
|
+
raise 'RubyGems 2.0 or newer is required to protect against ' \
|
22
|
+
'public gem pushes.'
|
24
23
|
end
|
25
24
|
|
26
25
|
# Specify which files should be added to the gem when it is released.
|
27
26
|
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
28
|
-
spec.files
|
27
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
29
28
|
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
30
29
|
end
|
31
|
-
spec.bindir =
|
30
|
+
spec.bindir = 'exe'
|
32
31
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
33
|
-
spec.require_paths = [
|
32
|
+
spec.require_paths = ['lib']
|
34
33
|
|
35
|
-
spec.add_development_dependency
|
36
|
-
spec.add_development_dependency
|
37
|
-
spec.add_development_dependency
|
38
|
-
spec.add_development_dependency
|
34
|
+
spec.add_development_dependency 'bundler', '~> 2.2', '>= 2.2.20'
|
35
|
+
spec.add_development_dependency 'pry', '~> 0.14.1'
|
36
|
+
spec.add_development_dependency 'rake', '~> 13.0', '>= 13.0.3'
|
37
|
+
spec.add_development_dependency 'rspec', '~> 3.10'
|
39
38
|
|
40
|
-
spec.add_runtime_dependency 'date', '~>
|
39
|
+
spec.add_runtime_dependency 'date', '~> 3.1', '>= 3.1.1'
|
41
40
|
end
|
data/lib/date_breakup.rb
CHANGED
@@ -1,183 +1,49 @@
|
|
1
|
-
|
2
|
-
require "time_difference"
|
1
|
+
# frozen_string_literal: true
|
3
2
|
|
4
|
-
|
5
|
-
|
6
|
-
private_class_method :new
|
3
|
+
require 'rubygems'
|
4
|
+
require 'time_difference'
|
7
5
|
|
8
|
-
|
9
|
-
|
10
|
-
end
|
11
|
-
|
12
|
-
def get_years
|
13
|
-
get_year_array(@date1, @date2)
|
14
|
-
|
15
|
-
output = { years: @year_array, months: @month_array, weeks: @week_array, days: @day_array }
|
16
|
-
end
|
17
|
-
|
18
|
-
def get_months
|
19
|
-
get_month_array(@date1, @date2)
|
20
|
-
|
21
|
-
output = { years: @year_array, months: @month_array, weeks: @week_array, days: @day_array }
|
22
|
-
end
|
23
|
-
|
24
|
-
def get_weeks
|
25
|
-
get_week_array(@date1, @date2)
|
26
|
-
|
27
|
-
output = { years: @year_array, months: @month_array, weeks: @week_array, days: @day_array }
|
28
|
-
end
|
29
|
-
|
30
|
-
def get_days
|
31
|
-
get_day_array(@date1, @date2)
|
32
|
-
|
33
|
-
output = { years: @year_array, months: @month_array, weeks: @week_array, days: @day_array }
|
34
|
-
end
|
35
|
-
|
36
|
-
private
|
37
|
-
|
38
|
-
def initialize(date1, date2)
|
39
|
-
@date1 = date1
|
40
|
-
@date2 = date2
|
41
|
-
@year_array = Array.new
|
42
|
-
@month_array = Array.new
|
43
|
-
@week_array = Array.new
|
44
|
-
@day_array = Array.new
|
45
|
-
end
|
46
|
-
|
47
|
-
def get_year_array(date, end_date)
|
48
|
-
move_to_date = true
|
49
|
-
# YEAR
|
50
|
-
if move_to_date
|
51
|
-
if date.beginning_of_year == date
|
52
|
-
if date.end_of_year <= @date2
|
53
|
-
date, move_to_date = get_year_data(date)
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
# MONTH
|
59
|
-
if move_to_date
|
60
|
-
if date.beginning_of_month == date
|
61
|
-
if date.end_of_month <= @date2
|
62
|
-
date, move_to_date = get_month_data(date)
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
# Week
|
68
|
-
if move_to_date
|
69
|
-
if date.beginning_of_week == date && date.end_of_week <= @date2
|
70
|
-
if date.beginning_of_week.month == date.end_of_week.month || date.end_of_week.end_of_month >= @date2
|
71
|
-
date, move_to_date = get_week_data(date)
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
# DAY
|
77
|
-
if move_to_date
|
78
|
-
date, move_to_date = get_date_data(date)
|
79
|
-
end
|
80
|
-
|
81
|
-
if date <= end_date
|
82
|
-
get_year_array(date, end_date)
|
83
|
-
end
|
84
|
-
end
|
6
|
+
class DateBreakup
|
7
|
+
VERSION = '3.0.1'
|
85
8
|
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
if move_to_date
|
90
|
-
if date.beginning_of_month == date
|
91
|
-
if date.end_of_month <= @date2
|
92
|
-
date, move_to_date = get_month_data(date)
|
93
|
-
end
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
|
-
# Week
|
98
|
-
if move_to_date
|
99
|
-
if date.beginning_of_week == date && date.end_of_week <= @date2
|
100
|
-
if date.beginning_of_week.month == date.end_of_week.month || date.end_of_week.end_of_month >= @date2
|
101
|
-
date, move_to_date = get_week_data(date)
|
102
|
-
end
|
103
|
-
end
|
104
|
-
end
|
9
|
+
def self.between(start_date, end_date)
|
10
|
+
new(Date.parse(start_date), Date.parse(end_date))
|
11
|
+
end
|
105
12
|
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
end
|
13
|
+
def initialize(start_date, end_date)
|
14
|
+
@start_date = start_date
|
15
|
+
@end_date = end_date
|
110
16
|
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
17
|
+
@years = []
|
18
|
+
@months = []
|
19
|
+
@weeks = []
|
20
|
+
@days = []
|
21
|
+
end
|
115
22
|
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
23
|
+
# Methods
|
24
|
+
# in_years, in_months, in_weeks, in_days
|
25
|
+
%w[years months weeks days].each do |method|
|
26
|
+
define_method "in_#{method}" do
|
27
|
+
date = @start_date
|
28
|
+
while date <= @end_date
|
29
|
+
if ['years'].include?(method) && date.beginning_of_year == date && @end_date >= date.end_of_year
|
30
|
+
@years << { year: date.year, start_date: date, end_date: date.end_of_year }
|
31
|
+
date = date.end_of_year + 1.day
|
32
|
+
elsif ['years', 'months'].include?(method) && date.beginning_of_month == date && @end_date >= date.end_of_month
|
33
|
+
@months << { month: date.month, year: date.year, start_date: date, end_date: date.end_of_month }
|
34
|
+
date = date.end_of_month + 1.day
|
35
|
+
elsif ['years', 'months', 'weeks'].include?(method) && date.beginning_of_week == date && @end_date >= date.end_of_week
|
36
|
+
@weeks << { week: date.cweek, month: date.month, year: date.year, start_date: date,
|
37
|
+
end_date: date.end_of_week }
|
38
|
+
date = date.end_of_week + 1.day
|
39
|
+
else
|
40
|
+
@days << { day: date.yday, month_day: date.mday, month: date.month, year: date.year, start_date: date,
|
41
|
+
end_date: date }
|
42
|
+
date += 1.day
|
122
43
|
end
|
123
44
|
end
|
124
45
|
|
125
|
-
|
126
|
-
if move_to_date
|
127
|
-
date, move_to_date = get_date_data(date)
|
128
|
-
end
|
129
|
-
|
130
|
-
if date <= end_date
|
131
|
-
get_week_array(date, end_date)
|
132
|
-
end
|
133
|
-
end
|
134
|
-
|
135
|
-
def get_day_array(date, end_date)
|
136
|
-
move_to_date = true
|
137
|
-
# DAY
|
138
|
-
if move_to_date
|
139
|
-
date, move_to_date = get_date_data(date)
|
140
|
-
end
|
141
|
-
|
142
|
-
if date <= end_date
|
143
|
-
get_day_array(date, end_date)
|
144
|
-
end
|
145
|
-
end
|
146
|
-
|
147
|
-
def get_year_data(date)
|
148
|
-
year_hash = { year: date.year, start_date: date, end_date: date.end_of_year }
|
149
|
-
@year_array << year_hash
|
150
|
-
new_date = date.end_of_year + 1.day
|
151
|
-
move_to_date = false
|
152
|
-
|
153
|
-
return new_date, move_to_date
|
154
|
-
end
|
155
|
-
|
156
|
-
def get_month_data(date)
|
157
|
-
month_hash = { month: date.month, year: date.year, start_date: date, end_date: date.end_of_month }
|
158
|
-
@month_array << month_hash
|
159
|
-
new_date = date.end_of_month + 1.day
|
160
|
-
move_to_date = false
|
161
|
-
|
162
|
-
return new_date, move_to_date
|
163
|
-
end
|
164
|
-
|
165
|
-
def get_week_data(date)
|
166
|
-
week_hash = { week: date.cweek, month: date.month, year: date.year, start_date: date, end_date: date.end_of_week }
|
167
|
-
@week_array << week_hash
|
168
|
-
new_date = date.end_of_week + 1.day
|
169
|
-
move_to_date = false
|
170
|
-
|
171
|
-
return new_date, move_to_date
|
172
|
-
end
|
173
|
-
|
174
|
-
def get_date_data(date)
|
175
|
-
day_hash = { day: date.yday, month_day: date.mday, month: date.month, year: date.year, start_date: date, end_date: date }
|
176
|
-
@day_array << day_hash
|
177
|
-
new_date = date + 1.day
|
178
|
-
move_to_date = false
|
179
|
-
|
180
|
-
return new_date, move_to_date
|
46
|
+
{ years: @years, months: @months, weeks: @weeks, days: @days }
|
181
47
|
end
|
182
48
|
end
|
183
49
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: date_breakup
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 3.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Huzaifa Saifuddin
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-06-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -16,70 +16,88 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '2.2'
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 2.2.20
|
20
23
|
type: :development
|
21
24
|
prerelease: false
|
22
25
|
version_requirements: !ruby/object:Gem::Requirement
|
23
26
|
requirements:
|
24
27
|
- - "~>"
|
25
28
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
29
|
+
version: '2.2'
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 2.2.20
|
27
33
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
34
|
+
name: pry
|
29
35
|
requirement: !ruby/object:Gem::Requirement
|
30
36
|
requirements:
|
31
37
|
- - "~>"
|
32
38
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
39
|
+
version: 0.14.1
|
34
40
|
type: :development
|
35
41
|
prerelease: false
|
36
42
|
version_requirements: !ruby/object:Gem::Requirement
|
37
43
|
requirements:
|
38
44
|
- - "~>"
|
39
45
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
46
|
+
version: 0.14.1
|
41
47
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
48
|
+
name: rake
|
43
49
|
requirement: !ruby/object:Gem::Requirement
|
44
50
|
requirements:
|
45
51
|
- - "~>"
|
46
52
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
53
|
+
version: '13.0'
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: 13.0.3
|
48
57
|
type: :development
|
49
58
|
prerelease: false
|
50
59
|
version_requirements: !ruby/object:Gem::Requirement
|
51
60
|
requirements:
|
52
61
|
- - "~>"
|
53
62
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
63
|
+
version: '13.0'
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: 13.0.3
|
55
67
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
68
|
+
name: rspec
|
57
69
|
requirement: !ruby/object:Gem::Requirement
|
58
70
|
requirements:
|
59
71
|
- - "~>"
|
60
72
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
73
|
+
version: '3.10'
|
62
74
|
type: :development
|
63
75
|
prerelease: false
|
64
76
|
version_requirements: !ruby/object:Gem::Requirement
|
65
77
|
requirements:
|
66
78
|
- - "~>"
|
67
79
|
- !ruby/object:Gem::Version
|
68
|
-
version: '
|
80
|
+
version: '3.10'
|
69
81
|
- !ruby/object:Gem::Dependency
|
70
82
|
name: date
|
71
83
|
requirement: !ruby/object:Gem::Requirement
|
72
84
|
requirements:
|
73
85
|
- - "~>"
|
74
86
|
- !ruby/object:Gem::Version
|
75
|
-
version: '
|
87
|
+
version: '3.1'
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: 3.1.1
|
76
91
|
type: :runtime
|
77
92
|
prerelease: false
|
78
93
|
version_requirements: !ruby/object:Gem::Requirement
|
79
94
|
requirements:
|
80
95
|
- - "~>"
|
81
96
|
- !ruby/object:Gem::Version
|
82
|
-
version: '
|
97
|
+
version: '3.1'
|
98
|
+
- - ">="
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: 3.1.1
|
83
101
|
description: Feed in 2 dates and get a breakup of dates grouped in years, months,
|
84
102
|
weeks & days
|
85
103
|
email:
|
@@ -92,6 +110,7 @@ files:
|
|
92
110
|
- ".rspec"
|
93
111
|
- ".travis.yml"
|
94
112
|
- Gemfile
|
113
|
+
- Gemfile.lock
|
95
114
|
- LICENSE.txt
|
96
115
|
- README.md
|
97
116
|
- Rakefile
|
@@ -99,14 +118,12 @@ files:
|
|
99
118
|
- bin/setup
|
100
119
|
- date_breakup.gemspec
|
101
120
|
- lib/date_breakup.rb
|
102
|
-
- lib/date_breakup/version.rb
|
103
|
-
- lib/date_breakup_v1.rb
|
104
121
|
homepage: https://github.com/HuzaifaSaifuddin/date_breakup
|
105
122
|
licenses:
|
106
123
|
- MIT
|
107
124
|
metadata:
|
108
125
|
allowed_push_host: https://rubygems.org
|
109
|
-
post_install_message:
|
126
|
+
post_install_message:
|
110
127
|
rdoc_options: []
|
111
128
|
require_paths:
|
112
129
|
- lib
|
@@ -121,9 +138,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
121
138
|
- !ruby/object:Gem::Version
|
122
139
|
version: '0'
|
123
140
|
requirements: []
|
124
|
-
|
125
|
-
|
126
|
-
signing_key:
|
141
|
+
rubygems_version: 3.1.6
|
142
|
+
signing_key:
|
127
143
|
specification_version: 4
|
128
144
|
summary: Feed in 2 dates and get a breakup of dates grouped in years, months, weeks
|
129
145
|
& days
|
data/lib/date_breakup/version.rb
DELETED
data/lib/date_breakup_v1.rb
DELETED
@@ -1,215 +0,0 @@
|
|
1
|
-
require "date_breakup/version"
|
2
|
-
require "time_difference"
|
3
|
-
|
4
|
-
module DateBreakup
|
5
|
-
class Range
|
6
|
-
private_class_method :new
|
7
|
-
|
8
|
-
def self.between(date1, date2)
|
9
|
-
new(Date.parse(date1), Date.parse(date2))
|
10
|
-
end
|
11
|
-
|
12
|
-
def get_accurate
|
13
|
-
years, remaining_dates_year = get_years(@date1, @date2)
|
14
|
-
|
15
|
-
months, remaining_dates_month = get_months(remaining_dates_year)
|
16
|
-
|
17
|
-
weeks, remaining_dates_week = get_weeks(remaining_dates_month)
|
18
|
-
|
19
|
-
days, remaining_dates_days = get_days(remaining_dates_week)
|
20
|
-
|
21
|
-
output = { years: years, months: months, weeks: weeks, days: days }
|
22
|
-
end
|
23
|
-
|
24
|
-
private
|
25
|
-
|
26
|
-
def initialize(date1, date2)
|
27
|
-
@date1 = date1
|
28
|
-
@date2 = date2
|
29
|
-
end
|
30
|
-
|
31
|
-
def get_years(date1, date2)
|
32
|
-
year_array = []
|
33
|
-
remaining_dates = []
|
34
|
-
|
35
|
-
if date1.beginning_of_year == date1 && date1.end_of_year <= date2
|
36
|
-
year_hash = { year: date1.year, start_date: date1.beginning_of_year, end_date: date1.end_of_year }
|
37
|
-
year_array << year_hash
|
38
|
-
end
|
39
|
-
|
40
|
-
get_year_range(date1, date2, year_array, year_hash)
|
41
|
-
|
42
|
-
if year_array.count > 0
|
43
|
-
if(date1 != year_array[0][:start_date])
|
44
|
-
remaining_dates_hash = { date1: date1, date2: year_array[0][:start_date] - 1 }
|
45
|
-
remaining_dates << remaining_dates_hash
|
46
|
-
end
|
47
|
-
|
48
|
-
if(date2 != year_array[-1][:end_date])
|
49
|
-
remaining_dates_hash = { date1: year_array[-1][:end_date] + 1, date2: date2 }
|
50
|
-
remaining_dates << remaining_dates_hash
|
51
|
-
end
|
52
|
-
else
|
53
|
-
remaining_dates << { date1: date1, date2: date2 }
|
54
|
-
end
|
55
|
-
|
56
|
-
return year_array, remaining_dates
|
57
|
-
end
|
58
|
-
|
59
|
-
def get_months(remaining_dates_year)
|
60
|
-
month_array = []
|
61
|
-
remaining_dates = []
|
62
|
-
|
63
|
-
remaining_dates_year.each do |rd|
|
64
|
-
date1, date2 = rd[:date1], rd[:date2]
|
65
|
-
if date1.beginning_of_month == date1 && date1.end_of_month <= date2
|
66
|
-
month_hash = { month: date1.month, year: date1.year, start_date: date1.beginning_of_month, end_date: date1.end_of_month }
|
67
|
-
month_array << month_hash
|
68
|
-
end
|
69
|
-
|
70
|
-
get_month_range(date1, date2, month_array, month_hash)
|
71
|
-
end
|
72
|
-
|
73
|
-
|
74
|
-
if month_array.count > 0
|
75
|
-
month_arrx1 = month_array.sort_by{ |ma| ma[:start_date] }.select{ |wa| wa[:year] == remaining_dates_year[0][:date1].year }.first
|
76
|
-
|
77
|
-
if month_arrx1
|
78
|
-
if(remaining_dates_year[0][:date1] != month_arrx1[:start_date])
|
79
|
-
remaining_dates_hash = { date1: remaining_dates_year[0][:date1], date2: month_arrx1[:start_date] - 1 }
|
80
|
-
remaining_dates << remaining_dates_hash
|
81
|
-
end
|
82
|
-
else
|
83
|
-
remaining_dates_hash = { date1: remaining_dates_year[0][:date1], date2: remaining_dates_year[0][:date2] }
|
84
|
-
remaining_dates << remaining_dates_hash
|
85
|
-
end
|
86
|
-
|
87
|
-
month_arrx2 = month_array.sort_by{ |ma| ma[:start_date] }.select{ |wa| wa[:year] == remaining_dates_year[-1][:date2].year }.last
|
88
|
-
if month_arrx2
|
89
|
-
if(remaining_dates_year[-1][:date2] != month_arrx2[:end_date])
|
90
|
-
remaining_dates_hash = { date1: month_arrx2[:end_date] + 1, date2: remaining_dates_year[-1][:date2] }
|
91
|
-
remaining_dates << remaining_dates_hash
|
92
|
-
end
|
93
|
-
else
|
94
|
-
remaining_dates_hash = { date1: remaining_dates_year[-1][:date1], date2: remaining_dates_year[-1][:date2] }
|
95
|
-
remaining_dates << remaining_dates_hash
|
96
|
-
end
|
97
|
-
else
|
98
|
-
remaining_dates = remaining_dates_year
|
99
|
-
end
|
100
|
-
|
101
|
-
return month_array, remaining_dates
|
102
|
-
end
|
103
|
-
|
104
|
-
def get_weeks(remaining_dates_month)
|
105
|
-
week_array = []
|
106
|
-
remaining_dates = []
|
107
|
-
|
108
|
-
remaining_dates_month.each do |rd|
|
109
|
-
date1, date2 = rd[:date1], rd[:date2]
|
110
|
-
if date1.beginning_of_week == date1 && date1.end_of_week <= date2
|
111
|
-
week_hash = { week: date1.cweek, month: date1.month, year: date1.year, start_date: date1.beginning_of_week, end_date: date1.end_of_week }
|
112
|
-
week_array << week_hash
|
113
|
-
end
|
114
|
-
|
115
|
-
get_week_range(date1, date2, week_array, week_hash)
|
116
|
-
end
|
117
|
-
|
118
|
-
if week_array.count > 0
|
119
|
-
week_arrx1 = week_array.sort_by{ |ma| ma[:start_date] }.select{ |wa| wa[:month] == remaining_dates_month[0][:date1].month }.first
|
120
|
-
if week_arrx1
|
121
|
-
if(remaining_dates_month[0][:date1] != week_arrx1[:start_date])
|
122
|
-
remaining_dates_hash = { date1: remaining_dates_month[0][:date1], date2: week_arrx1[:start_date] - 1 }
|
123
|
-
remaining_dates << remaining_dates_hash
|
124
|
-
end
|
125
|
-
end
|
126
|
-
|
127
|
-
week_arrx2 = week_array.sort_by{ |ma| ma[:start_date] }.select{ |wa| wa[:month] == remaining_dates_month[0][:date2].month }.last
|
128
|
-
if week_arrx2
|
129
|
-
if(remaining_dates_month[0][:date2] != week_arrx2[:end_date])
|
130
|
-
remaining_dates_hash = { date1: week_arrx2[:end_date] + 1, date2: remaining_dates_month[0][:date2] }
|
131
|
-
remaining_dates << remaining_dates_hash
|
132
|
-
end
|
133
|
-
end
|
134
|
-
|
135
|
-
week_arrx3 = week_array.sort_by{ |ma| ma[:start_date] }.select{ |wa| wa[:month] == remaining_dates_month[-1][:date1].month }.first
|
136
|
-
if week_arrx3
|
137
|
-
if(remaining_dates_month[0][:date1] != week_arrx3[:end_date])
|
138
|
-
remaining_dates_hash = { date1: remaining_dates_month[-1][:date1], date2: week_arrx3[:start_date] - 1 }
|
139
|
-
remaining_dates << remaining_dates_hash
|
140
|
-
end
|
141
|
-
end
|
142
|
-
|
143
|
-
week_arrx4 = week_array.sort_by{ |ma| ma[:start_date] }.select{ |wa| wa[:month] == remaining_dates_month[-1][:date1].month }.last
|
144
|
-
if week_arrx4
|
145
|
-
if(remaining_dates_month[-1][:date2] != week_arrx4[:end_date])
|
146
|
-
remaining_dates_hash = { date1: week_arrx4[:end_date] + 1, date2: remaining_dates_month[-1][:date2] }
|
147
|
-
remaining_dates << remaining_dates_hash
|
148
|
-
end
|
149
|
-
end
|
150
|
-
else
|
151
|
-
remaining_dates = remaining_dates_month
|
152
|
-
end
|
153
|
-
|
154
|
-
return week_array, remaining_dates
|
155
|
-
end
|
156
|
-
|
157
|
-
def get_days(remaining_dates_week)
|
158
|
-
day_array = []
|
159
|
-
remaining_dates = []
|
160
|
-
|
161
|
-
remaining_dates_week.each do |rd|
|
162
|
-
date1, date2 = rd[:date1], rd[:date2]
|
163
|
-
dates = (date1).upto(date2).to_a
|
164
|
-
|
165
|
-
dates.each do |date|
|
166
|
-
unless day_array.find{ |da| da[:start_date] == date }.present?
|
167
|
-
day_hash = { day: date.yday, month_day: date.mday, month: date.month, year: date.year, start_date: date, end_date: date }
|
168
|
-
day_array << day_hash
|
169
|
-
end
|
170
|
-
end
|
171
|
-
end
|
172
|
-
|
173
|
-
return day_array, remaining_dates
|
174
|
-
end
|
175
|
-
|
176
|
-
def get_year_range(date1, date2, year_array, year_hash)
|
177
|
-
next_year = (date1.end_of_year + 1.day)
|
178
|
-
end_next_year = next_year.end_of_year
|
179
|
-
if end_next_year <= date2
|
180
|
-
year = end_next_year.year
|
181
|
-
start_date = next_year.beginning_of_year
|
182
|
-
end_date = end_next_year
|
183
|
-
year_hash = { year: year, start_date: start_date, end_date: end_date }
|
184
|
-
year_array << year_hash
|
185
|
-
get_year_range(next_year, date2, year_array, year_hash)
|
186
|
-
end
|
187
|
-
end
|
188
|
-
|
189
|
-
def get_month_range(date1, date2, month_array, month_hash)
|
190
|
-
next_month = (date1.end_of_month + 1.day)
|
191
|
-
end_next_month = next_month.end_of_month
|
192
|
-
if end_next_month <= date2
|
193
|
-
month = end_next_month.month
|
194
|
-
start_date = next_month.beginning_of_month
|
195
|
-
end_date = end_next_month
|
196
|
-
month_hash = { month: month, year: end_next_month.year, start_date: start_date, end_date: end_date }
|
197
|
-
month_array << month_hash
|
198
|
-
get_month_range(next_month, date2, month_array, month_hash)
|
199
|
-
end
|
200
|
-
end
|
201
|
-
|
202
|
-
def get_week_range(date1, date2, week_array, week_hash)
|
203
|
-
next_week = (date1.end_of_week + 1.day)
|
204
|
-
end_next_week = next_week.end_of_week
|
205
|
-
if end_next_week <= date2
|
206
|
-
week = end_next_week.cweek
|
207
|
-
start_date = next_week.beginning_of_week
|
208
|
-
end_date = end_next_week
|
209
|
-
week_hash = { week: week, month: end_next_week.month, year: end_next_week.year, start_date: start_date, end_date: end_date }
|
210
|
-
week_array << week_hash
|
211
|
-
get_week_range(next_week, date2, week_array, week_hash)
|
212
|
-
end
|
213
|
-
end
|
214
|
-
end
|
215
|
-
end
|