periodical 1.1.0 → 1.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 2555e6758e16ddd84d99a9f56a223cd8c19cdfe1
4
- data.tar.gz: 3187ffebf9e51e9175a76d2321ea1b2c2b516b3a
2
+ SHA256:
3
+ metadata.gz: 87b19fdf8f3ac679f10b1be35c766f90222c8a78e1d01b99a7e097ea6d9eb391
4
+ data.tar.gz: 22bc626fc1c7e124490c085c80012b3f5121d800c23b922e512a24875ec99299
5
5
  SHA512:
6
- metadata.gz: 7adb54adb0d5d51a4193e8519497f57412beeb043ca4c145f850894e59cb684e25e149ec29c414fc51991f40ebcd5a2c0451da5d25809492ef81a549757054c8
7
- data.tar.gz: 92a27112f8b1c656b5e7f368dfd6f776c3ee017243656c75785a94640c64df4febe673cd8e8c8c634ca449b6d204daafae9cf4ac4209b8a22752c4274dde02cc
6
+ metadata.gz: 823fd79066cb4b3cea6591c27710daccca0ba31d9b32d344533b969c4bc7ec48680ebbb037b6fd349eec667aedb9cb14b500b9aa0c0e715c61697ee3acc00a56
7
+ data.tar.gz: 5caf792943a767cdb6a3e39343c2636d742372b53a73a43996735b25498c2ea47c99fe810117126794390bcbfcfe6dc515863fce47a01895d13df71b7a24d6aa
@@ -36,6 +36,8 @@ module Periodical
36
36
  end
37
37
 
38
38
  def advance(date, multiple = 1)
39
+ raise TypeError unless date.is_a?(Date)
40
+
39
41
  self.send("advance_#{unit}", date, multiple * self.count)
40
42
  end
41
43
 
@@ -46,7 +48,7 @@ module Periodical
46
48
  end
47
49
 
48
50
  def advance_weeks(date, count)
49
- date + (7 * count)
51
+ advance_days(date, count*7)
50
52
  end
51
53
 
52
54
  def advance_months(date, count)
@@ -54,7 +56,7 @@ module Periodical
54
56
  end
55
57
 
56
58
  def advance_years(date, count)
57
- date >> (12 * count)
59
+ advance_months(date, count*12)
58
60
  end
59
61
 
60
62
  class << self
@@ -19,5 +19,5 @@
19
19
  # THE SOFTWARE.
20
20
 
21
21
  module Periodical
22
- VERSION = "1.1.0"
22
+ VERSION = "1.2.0"
23
23
  end
metadata CHANGED
@@ -1,45 +1,31 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: periodical
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-06-20 00:00:00.000000000 Z
11
+ date: 2020-06-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: bundler
14
+ name: bake-bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
18
- - !ruby/object:Gem::Version
19
- version: '1.3'
20
- type: :development
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - "~>"
25
- - !ruby/object:Gem::Version
26
- version: '1.3'
27
- - !ruby/object:Gem::Dependency
28
- name: rspec
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - "~>"
17
+ - - ">="
32
18
  - !ruby/object:Gem::Version
33
- version: 3.4.0
19
+ version: '0'
34
20
  type: :development
35
21
  prerelease: false
36
22
  version_requirements: !ruby/object:Gem::Requirement
37
23
  requirements:
38
- - - "~>"
24
+ - - ">="
39
25
  - !ruby/object:Gem::Version
40
- version: 3.4.0
26
+ version: '0'
41
27
  - !ruby/object:Gem::Dependency
42
- name: rake
28
+ name: bake-modernize
43
29
  requirement: !ruby/object:Gem::Requirement
44
30
  requirements:
45
31
  - - ">="
@@ -52,33 +38,23 @@ dependencies:
52
38
  - - ">="
53
39
  - !ruby/object:Gem::Version
54
40
  version: '0'
55
- description:
41
+ description:
56
42
  email:
57
- - samuel.williams@oriontransfer.co.nz
58
43
  executables: []
59
44
  extensions: []
60
45
  extra_rdoc_files: []
61
46
  files:
62
- - ".rspec"
63
- - ".simplecov"
64
- - ".travis.yml"
65
- - Gemfile
66
- - README.md
67
- - Rakefile
68
47
  - lib/periodical.rb
69
48
  - lib/periodical/duration.rb
70
49
  - lib/periodical/filter.rb
71
50
  - lib/periodical/period.rb
72
51
  - lib/periodical/version.rb
73
- - periodical.gemspec
74
- - spec/periodical/duration_spec.rb
75
- - spec/periodical/filter_spec.rb
76
- - spec/periodical/period_spec.rb
77
- homepage:
52
+ homepage: https://github.com/ioquatix/periodical
78
53
  licenses:
79
54
  - MIT
80
- metadata: {}
81
- post_install_message:
55
+ metadata:
56
+ funding_uri: https://github.com/sponsors/ioquatix/
57
+ post_install_message:
82
58
  rdoc_options: []
83
59
  require_paths:
84
60
  - lib
@@ -93,12 +69,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
93
69
  - !ruby/object:Gem::Version
94
70
  version: '0'
95
71
  requirements: []
96
- rubyforge_project:
97
- rubygems_version: 2.5.1
98
- signing_key:
72
+ rubygems_version: 3.1.2
73
+ signing_key:
99
74
  specification_version: 4
100
75
  summary: Periodical is a simple framework for working with durations and periods.
101
- test_files:
102
- - spec/periodical/duration_spec.rb
103
- - spec/periodical/filter_spec.rb
104
- - spec/periodical/period_spec.rb
76
+ test_files: []
data/.rspec DELETED
@@ -1,4 +0,0 @@
1
- --color
2
- --format documentation
3
- --backtrace
4
- --warnings
data/.simplecov DELETED
@@ -1,9 +0,0 @@
1
-
2
- SimpleCov.start do
3
- add_filter "/spec/"
4
- end
5
-
6
- if ENV['TRAVIS']
7
- require 'coveralls'
8
- Coveralls.wear!
9
- end
@@ -1,12 +0,0 @@
1
- language: ruby
2
- sudo: false
3
- rvm:
4
- - 2.1.8
5
- - 2.2.4
6
- - 2.3.0
7
- - ruby-head
8
- - rbx-2
9
- env: COVERAGE=true
10
- matrix:
11
- allow_failures:
12
- - rvm: "rbx-2"
data/Gemfile DELETED
@@ -1,7 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- gemspec
4
-
5
- group :test do
6
- gem 'coveralls', platforms: [:mri]
7
- end
data/README.md DELETED
@@ -1,72 +0,0 @@
1
- # Periodical
2
-
3
- Periodical is a simple framework for working with durations and periods. A duration measures a range of time bounded by a `from` date and `to` date. A period is a relative unit of time such as `4 weeks`.
4
-
5
- [![Build Status](https://travis-ci.org/ioquatix/periodical.svg)](https://travis-ci.org/ioquatix/periodical)
6
- [![Code Climate](https://codeclimate.com/github/ioquatix/periodical.svg)](https://codeclimate.com/github/ioquatix/periodical)
7
- [![Coverage Status](https://coveralls.io/repos/ioquatix/periodical/badge.svg)](https://coveralls.io/r/ioquatix/periodical)
8
-
9
- ## Motivation
10
-
11
- The original idea for this library came from a [Python script which performed backup rotation](http://www.scottlu.com/Content/Snapfilter.html) from 2009. In particular, I thought it had a novel way to retain backups according to a given policy (e.g. one backup every year for 10 years, one backup every month for 12 months, one backup every week for 8 weeks, one backup every day for 30 days). This is done by constructing a special slot based hash structure with keys based on the date being stored. This functionality is used by [LSync](https://github.com/ioquatix/LSync) for performing backup rotation (i.e. deleting old backups).
12
-
13
- In addition, I had a need to implement periodical billing in [Financier](https://github.com/ioquatix/financier). Not only can this gem advance a date by a given period, it can compute the number of periods between two dates. This is useful for invoicing, say, once every 6 months for a weekly or monthly service.
14
-
15
- ## Installation
16
-
17
- Add this line to your application's Gemfile:
18
-
19
- gem 'periodical'
20
-
21
- And then execute:
22
-
23
- $ bundle
24
-
25
- Or install it yourself as:
26
-
27
- $ gem install periodical
28
-
29
- ## Usage
30
-
31
- The main use case for this framework involves periodic billing or accounting (e.g. calculating fortnightly rental payments).
32
-
33
- duration = Periodical::Duration.new(Date.parse("2010-01-01"), Date.parse("2010-02-01"))
34
- period = Periodical::Period.new(2, :weeks)
35
-
36
- # How many periods in the duration?
37
- count = duration / period
38
-
39
- # Calculate the date which is 2 * (2 weeks)
40
- next = period.advance(duration.from, 2)
41
-
42
- ## Contributing
43
-
44
- 1. Fork it
45
- 2. Create your feature branch (`git checkout -b my-new-feature`)
46
- 3. Commit your changes (`git commit -am 'Add some feature'`)
47
- 4. Push to the branch (`git push origin my-new-feature`)
48
- 5. Create new Pull Request
49
-
50
- ## License
51
-
52
- Released under the MIT license.
53
-
54
- Copyright, 2010, 2014, 2016, by [Samuel G. D. Williams](http://www.codeotaku.com/samuel-williams).
55
-
56
- Permission is hereby granted, free of charge, to any person obtaining a copy
57
- of this software and associated documentation files (the "Software"), to deal
58
- in the Software without restriction, including without limitation the rights
59
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
60
- copies of the Software, and to permit persons to whom the Software is
61
- furnished to do so, subject to the following conditions:
62
-
63
- The above copyright notice and this permission notice shall be included in
64
- all copies or substantial portions of the Software.
65
-
66
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
67
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
68
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
69
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
70
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
71
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
72
- THE SOFTWARE.
data/Rakefile DELETED
@@ -1,14 +0,0 @@
1
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
3
-
4
- RSpec::Core::RakeTask.new(:spec) do |task|
5
- if ENV['COVERAGE']
6
- begin
7
- require('simplecov/version')
8
- task.rspec_opts = %w{--require simplecov}
9
- rescue LoadError
10
- end
11
- end
12
- end
13
-
14
- task :default => :spec
@@ -1,24 +0,0 @@
1
- # -*- encoding: utf-8 -*-
2
- lib = File.expand_path('../lib', __FILE__)
3
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'periodical/version'
5
-
6
- Gem::Specification.new do |spec|
7
- spec.name = "periodical"
8
- spec.version = Periodical::VERSION
9
- spec.authors = ["Samuel Williams"]
10
- spec.email = ["samuel.williams@oriontransfer.co.nz"]
11
- spec.summary = %q{Periodical is a simple framework for working with durations and periods.}
12
- spec.license = "MIT"
13
-
14
- spec.files = `git ls-files`.split($/)
15
- spec.executables = spec.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
16
- spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
17
- spec.require_paths = ["lib"]
18
-
19
- spec.required_ruby_version = '>= 2.0'
20
-
21
- spec.add_development_dependency "bundler", "~> 1.3"
22
- spec.add_development_dependency "rspec", "~> 3.4.0"
23
- spec.add_development_dependency "rake"
24
- end
@@ -1,50 +0,0 @@
1
- # Copyright, 2012, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
- #
3
- # Permission is hereby granted, free of charge, to any person obtaining a copy
4
- # of this software and associated documentation files (the "Software"), to deal
5
- # in the Software without restriction, including without limitation the rights
6
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
- # copies of the Software, and to permit persons to whom the Software is
8
- # furnished to do so, subject to the following conditions:
9
- #
10
- # The above copyright notice and this permission notice shall be included in
11
- # all copies or substantial portions of the Software.
12
- #
13
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
- # THE SOFTWARE.
20
-
21
- require 'periodical'
22
-
23
- module Periodical::DurationSpec
24
- describe Periodical::Duration do
25
- it "should measure durations correctly" do
26
- duration = Periodical::Duration.new(Date.parse("2010-01-01"), Date.parse("2010-02-01"))
27
- expect(duration.days).to be == 31
28
- expect(duration.weeks).to be == Rational(31, 7)
29
- expect(duration.months).to be == 1
30
- expect(duration.years).to be == Rational(31, 365)
31
-
32
- expect(duration.whole_months).to be == 1
33
- expect(duration.whole_years).to be == 0
34
- end
35
-
36
- it "should compute the correct number of weeks" do
37
- duration = Periodical::Duration.new(Date.parse("2010-01-01"), Date.parse("2010-02-01"))
38
- period = Periodical::Period.new(2, :weeks)
39
-
40
- expect(duration / period).to be == Rational(31, 14)
41
- end
42
-
43
- it "should compute the correct number of months" do
44
- duration = Periodical::Duration.new(Date.parse("2010-01-01"), Date.parse("2011-03-01"))
45
- period = Periodical::Period.new(2, :months)
46
-
47
- expect(duration / period).to be == Rational(14, 2)
48
- end
49
- end
50
- end
@@ -1,61 +0,0 @@
1
- # Copyright, 2012, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
- #
3
- # Permission is hereby granted, free of charge, to any person obtaining a copy
4
- # of this software and associated documentation files (the "Software"), to deal
5
- # in the Software without restriction, including without limitation the rights
6
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
- # copies of the Software, and to permit persons to whom the Software is
8
- # furnished to do so, subject to the following conditions:
9
- #
10
- # The above copyright notice and this permission notice shall be included in
11
- # all copies or substantial portions of the Software.
12
- #
13
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
- # THE SOFTWARE.
20
-
21
- require 'periodical/filter'
22
-
23
- module Periodical::PeriodSpec
24
- describe Periodical::Filter do
25
- it "should select at most 3 days worth of data" do
26
- dates = [
27
- Date.parse("2010-01-01"),
28
- Date.parse("2010-01-02"),
29
- Date.parse("2010-01-03"),
30
- Date.parse("2010-01-04"),
31
- Date.parse("2010-01-05"),
32
- Date.parse("2010-01-06"),
33
- ]
34
-
35
- policy = Periodical::Filter::Policy.new
36
- policy << Periodical::Filter::Daily.new(3)
37
-
38
- selected, rejected = policy.filter(dates)
39
-
40
- expect(selected).to include(*dates.first(3))
41
- expect(rejected).to include(*dates.last(3))
42
- end
43
-
44
- it "should keep youngest" do
45
- dates = [
46
- Date.parse("2010-01-01"),
47
- Date.parse("2010-01-02"),
48
- ]
49
-
50
- policy = Periodical::Filter::Policy.new
51
- policy << Periodical::Filter::Monthly.new(1)
52
-
53
- selected, rejected = policy.filter(dates, :keep => :new)
54
- expect(selected.count).to be 1
55
- expect(rejected.count).to be 1
56
-
57
- # Keep oldest is the default policy
58
- expect(selected).to be_include(dates[1])
59
- end
60
- end
61
- end
@@ -1,64 +0,0 @@
1
- # Copyright, 2012, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
- #
3
- # Permission is hereby granted, free of charge, to any person obtaining a copy
4
- # of this software and associated documentation files (the "Software"), to deal
5
- # in the Software without restriction, including without limitation the rights
6
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
- # copies of the Software, and to permit persons to whom the Software is
8
- # furnished to do so, subject to the following conditions:
9
- #
10
- # The above copyright notice and this permission notice shall be included in
11
- # all copies or substantial portions of the Software.
12
- #
13
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
- # THE SOFTWARE.
20
-
21
- require 'periodical'
22
-
23
- module Periodical::PeriodSpec
24
- describe Periodical::Period do
25
- it "should advance by 1 month" do
26
- duration = Periodical::Duration.new(Date.parse("2010-01-01"), Date.parse("2011-01-01"))
27
-
28
- period = Periodical::Period.new(1, :months)
29
-
30
- expect(period.advance(duration.from, 12)).to be == duration.to
31
- end
32
-
33
- it "should parse a singular period" do
34
- period = Periodical::Period.parse("years")
35
-
36
- expect(period.count).to be == 1
37
- expect(period.unit).to be == :years
38
- end
39
-
40
- it "should parse a multiple count period" do
41
- period = Periodical::Period.parse("5 days")
42
-
43
- expect(period.count).to be == 5
44
- expect(period.unit).to be == :days
45
- end
46
-
47
- it "can load nil" do
48
- expect(Periodical::Period.load(nil)).to be == nil
49
- expect(Periodical::Period.load("")).to be == nil
50
- end
51
-
52
- it "can dump nil" do
53
- expect(Periodical::Period.dump(nil)).to be == nil
54
- end
55
-
56
- it "can load string" do
57
- expect(Periodical::Period.load("5 weeks")).to be == Periodical::Period.new(5, :weeks)
58
- end
59
-
60
- it "can dump nil" do
61
- expect(Periodical::Period.dump(Periodical::Period.new(5, :weeks))).to be == "5 weeks"
62
- end
63
- end
64
- end