duration.rb 0.3.4 → 0.3.6

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
2
  SHA256:
3
- metadata.gz: 38154d0b4ffc022c025fb1ab7e8cc138bd3de4c9fdf9647470833c67b6ed654e
4
- data.tar.gz: b6757bd78e018cb8d28df7c1e06c90916ac848e5b0720ef8d2d62c04f9224a44
3
+ metadata.gz: d4947aa87a27f048e0c81a3a6b7a9ce86e6d60b82d0f76db4667694865bf1887
4
+ data.tar.gz: 104cc227d961d1e48925b1e8118588f02ba9b88289fdf9e8e3dd06753ac4ced7
5
5
  SHA512:
6
- metadata.gz: 6ee50579a2597c396281ce00aba23b6b558f853309d7fe976dd164a0dbfb992f5f4a574d54764f114e5b89b078cd80c2c1db89f4dafd07e036eb5692cc9309df
7
- data.tar.gz: cd7cc3d6a4d011d2dd50d46f1841fd04e6c004d58e8fff8206d172bdb19b5141da54f66f681e9038a69f99a25e71bb4de99e4a6deb41a2749e7e6d68dd114be2
6
+ metadata.gz: 0feb8f48532ed5bc8484f9ff897b294c34b88cfdd5a9c44f77cf4deefba5d7bc4cab774c693fa63fdabc1f6b89cad4a9500b7858257e53131a774b28905d3706
7
+ data.tar.gz: 82d00f722d7255f803b4c8632d0cf9a788c1cdf22d38f9755ef274281604a22ec74b052c0d5e9f3ecb165eed4abed4bd8f584f213731649cfba1248c6f891848
data/CHANGELOG ADDED
@@ -0,0 +1,28 @@
1
+ # CHANGELOG
2
+
3
+
4
+ ## 20260717
5
+
6
+ 0.3.6: + Rakefile and gemspec tidy.
7
+
8
+ 1. + Rakefile
9
+ 2. ~ duration.rb.gemspec: + Rakefile
10
+ 3. ~ duration.rb.gemspec: - date. One less thing to edit. And it was wrong.
11
+ 4. ~ duration.rb.gemspec: + Gem::Specification#development_dependencies=
12
+ 5. ~ duration.rb.gemspec: + development_dependencies
13
+ 6. - test/test_all.rb
14
+ 9. ~ Duration::VERSION: /0.3.5/0.3.6/
15
+
16
+ ## 20260717
17
+
18
+ 0.3.5: Months conversion constant bug fix.
19
+
20
+ 1. ~ Duration::Weeks#to_months: The constant asserted a year of 52 weeks, which is 364 days rather than 365.2425, so every conversion through months was short by 1.2425 days a year before months were reached at all. The Gregorian mean month of 2629746 seconds is used instead, against 604800 seconds per week. 12.months.to_days now gives 365.2425 rather than 364.0, and 2.months.to_days gives 60.873749999999994 rather than 60.666666666666664.
21
+ 2. ~ Duration::Months#to_weeks: The same constant, in the other direction.
22
+ 3. ~ test/Duration/Milliseconds_test.rb, test/Duration/Seconds_test.rb, test/Duration/Minutes_test.rb, test/Duration/Hours_test.rb, test/Duration/Days_test.rb, test/Duration/Weeks_test.rb: The to_months expectations, each of which encoded the old constant.
23
+ 4. ~ test/Duration/Months_test.rb: The conversion expectations, each of which encoded the old constant.
24
+ 5. ~ test/Duration/Months_test.rb: /must_equal/must_be_close_to/ for the milliseconds and seconds conversions, since 2.months.to_milliseconds arrives at 5259491999.999999 rather than 5259492000.0. The conversion chains through Float, and the drift is inherent to holding a Float rather than anything introduced here. The mean month is an exact number of seconds, so the expectations are exact and it is only the arithmetic which cannot reach them.
25
+ 6. + README.md: A note that the Months conversions are a statistical mean, and that ago() and hence() on Months are not calendar-correct, since a corrected constant is still only an average.
26
+ 7. + CHANGELOG
27
+ 8. ~ duration.rb.gemspec: spec.files to include CHANGELOG.
28
+ 9. ~ Duration::VERSION: /0.3.4/0.3.5/
data/README.md CHANGED
@@ -87,6 +87,25 @@ $ gem install duration.rb
87
87
  7.months.hence # => #<Time:> (now + 7.months.to_seconds.to_f)
88
88
  ```
89
89
 
90
+ ### A Note on Months
91
+
92
+ `Months` is the odd one out. Every other unit is a fixed quantity with an exact
93
+ ratio to every other, but a month is a calendar operation whose length depends
94
+ on which month. The conversions use the Gregorian mean month (2629746 seconds),
95
+ so they are honest only as a statistical average:
96
+
97
+ ```ruby
98
+ 12.months.to_days # => 365.2425, the Gregorian mean year
99
+ ```
100
+
101
+ Two actual calendar months are anywhere from 59 to 62 days, while the mean gives
102
+ about 60.87 — no particular pair of months. No single constant can be right.
103
+
104
+ For the same reason `ago` and `hence` are not calendar-correct on `Months`: one
105
+ month before the 15th of March is the 15th of February to a calendar, but the
106
+ mean lands on the 12th. Where the calendar matters, reach for a date-anchored
107
+ type such as month.rb.
108
+
90
109
  ## Contributing
91
110
 
92
111
  1. Fork it (https://github.com/thoran/duration.rb/fork)
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ # Rakefile
2
+
3
+ require 'rake/testtask'
4
+
5
+ Rake::TestTask.new(:test) do |t|
6
+ t.test_files = FileList['test/**/*_test.rb']
7
+ end
8
+
9
+ task default: :test
data/duration.rb.gemspec CHANGED
@@ -1,10 +1,14 @@
1
1
  require_relative './lib/Duration/VERSION'
2
2
 
3
+ class Gem::Specification
4
+ def development_dependencies=(gems)
5
+ gems.each{|gem| add_development_dependency(*gem)}
6
+ end
7
+ end
8
+
3
9
  Gem::Specification.new do |spec|
4
10
  spec.name = 'duration.rb'
5
-
6
11
  spec.version = Duration::VERSION
7
- spec.date = '2025-10-25'
8
12
 
9
13
  spec.summary = "Objects for handling durations of time."
10
14
  spec.description = "Objects for handling durations of time."
@@ -14,14 +18,22 @@ Gem::Specification.new do |spec|
14
18
  spec.homepage = 'http://github.com/thoran/duration.rb'
15
19
  spec.license = 'Ruby'
16
20
 
21
+ spec.require_paths = ['lib']
17
22
  spec.required_ruby_version = '>= 2.5'
18
23
 
19
24
  spec.files = [
25
+ 'CHANGELOG',
20
26
  'duration.rb.gemspec',
21
27
  'Gemfile',
22
28
  Dir['lib/**/*.rb'],
29
+ 'Rakefile',
23
30
  'README.md',
24
31
  Dir['test/**/*.rb']
25
32
  ].flatten
26
- spec.require_paths = ['lib']
33
+
34
+ spec.development_dependencies = %w{
35
+ minitest
36
+ minitest-spec-context
37
+ rake
38
+ }
27
39
  end
@@ -29,7 +29,8 @@ module Duration
29
29
  end
30
30
 
31
31
  def to_weeks
32
- Duration::Weeks.new(@months / 12 * 52)
32
+ # A month is the Gregorian mean: 2629746 seconds against 604800 per week.
33
+ Duration::Weeks.new(@months * 2629746 / 604800.0)
33
34
  end
34
35
 
35
36
  def to_months
@@ -1,3 +1,3 @@
1
1
  module Duration
2
- VERSION = '0.3.4'
2
+ VERSION = '0.3.6'
3
3
  end
@@ -34,7 +34,8 @@ module Duration
34
34
  end
35
35
 
36
36
  def to_months
37
- Duration::Months.new(@weeks / 52 * 12)
37
+ # A month is the Gregorian mean: 2629746 seconds against 604800 per week.
38
+ Duration::Months.new(@weeks * 604800 / 2629746.0)
38
39
  end
39
40
 
40
41
  def to_i
@@ -49,7 +49,7 @@ describe Duration::Days do
49
49
  it "converts to months" do
50
50
  months = @days.to_months
51
51
  _(months).must_be_instance_of Duration::Months
52
- _(months.to_f).must_be_close_to 0.06593, 0.00001
52
+ _(months.to_f).must_be_close_to 0.065710, 0.00001
53
53
  end
54
54
 
55
55
  it "returns itself for to_days" do
@@ -49,7 +49,7 @@ describe Duration::Hours do
49
49
  it "converts to months" do
50
50
  months = subject.to_months
51
51
  _(months).must_be_instance_of Duration::Months
52
- _(months.to_f).must_be_close_to 0.004120, 0.000001
52
+ _(months.to_f).must_be_close_to 0.004107, 0.000001
53
53
  end
54
54
 
55
55
  it "returns itself for to_hours" do
@@ -49,7 +49,7 @@ describe Duration::Milliseconds do
49
49
  it "converts to months" do
50
50
  months = subject.to_months
51
51
  _(months).must_be_instance_of Duration::Months
52
- _(months.to_f).must_be_close_to 1.907814e-6, 0.000001
52
+ _(months.to_f).must_be_close_to 1.901337e-6, 0.000001
53
53
  end
54
54
 
55
55
  it "returns itself for to_milliseconds" do
@@ -49,7 +49,7 @@ describe Duration::Minutes do
49
49
  it "converts to months" do
50
50
  months = subject.to_months
51
51
  _(months).must_be_instance_of Duration::Months
52
- _(months.to_f).must_be_close_to 0.00206, 0.000001
52
+ _(months.to_f).must_be_close_to 0.002053, 0.000001
53
53
  end
54
54
 
55
55
  it "returns itself for to_minutes" do
@@ -19,37 +19,37 @@ describe Duration::Months do
19
19
  it "converts to milliseconds" do
20
20
  ms = subject.to_milliseconds
21
21
  _(ms).must_be_instance_of Duration::Milliseconds
22
- _(ms.to_f).must_equal 5241600000.0
22
+ _(ms.to_f).must_be_close_to 5259492000.0, 0.001
23
23
  end
24
24
 
25
25
  it "converts to seconds" do
26
26
  secs = subject.to_seconds
27
27
  _(secs).must_be_instance_of Duration::Seconds
28
- _(secs.to_f).must_equal 5241600.0
28
+ _(secs.to_f).must_be_close_to 5259492.0, 0.001
29
29
  end
30
30
 
31
31
  it "converts to minutes" do
32
32
  mins = subject.to_minutes
33
33
  _(mins).must_be_instance_of Duration::Minutes
34
- _(mins.to_f).must_equal 87360.0
34
+ _(mins.to_f).must_be_close_to 87658.2, 0.1
35
35
  end
36
36
 
37
37
  it "converts to hours" do
38
38
  hours = subject.to_hours
39
39
  _(hours).must_be_instance_of Duration::Hours
40
- _(hours.to_f).must_equal 1456.0
40
+ _(hours.to_f).must_be_close_to 1460.97, 0.01
41
41
  end
42
42
 
43
43
  it "converts to days" do
44
44
  days = subject.to_days
45
45
  _(days).must_be_instance_of Duration::Days
46
- _(days.to_f).must_be_close_to 60.66, 0.01
46
+ _(days.to_f).must_be_close_to 60.87375, 0.01
47
47
  end
48
48
 
49
49
  it "converts to weeks" do
50
50
  weeks = subject.to_weeks
51
51
  _(weeks).must_be_instance_of Duration::Weeks
52
- _(weeks.to_f).must_be_close_to 8.66, 0.01
52
+ _(weeks.to_f).must_be_close_to 8.69625, 0.01
53
53
  end
54
54
 
55
55
  it "returns itself for to_months" do
@@ -49,7 +49,7 @@ describe Duration::Seconds do
49
49
  it "converts to months" do
50
50
  months = subject.to_months
51
51
  _(months).must_be_instance_of Duration::Months
52
- _(months.to_f).must_be_close_to 3.4340659e-05, 0.00000001
52
+ _(months.to_f).must_be_close_to 3.422384e-05, 0.00000001
53
53
  end
54
54
 
55
55
  it "returns itself for to_seconds" do
@@ -49,7 +49,7 @@ describe Duration::Weeks do
49
49
  it "converts to months" do
50
50
  months = subject.to_months
51
51
  _(months).must_be_instance_of Duration::Months
52
- _(months.to_f).must_be_close_to 0.4615384, 0.0000001
52
+ _(months.to_f).must_be_close_to 0.459968, 0.000001
53
53
  end
54
54
 
55
55
  it "returns itself for to_weeks" do
metadata CHANGED
@@ -1,22 +1,66 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: duration.rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.4
4
+ version: 0.3.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - thoran
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-10-25 00:00:00.000000000 Z
11
- dependencies: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: minitest
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - ">="
17
+ - !ruby/object:Gem::Version
18
+ version: '0'
19
+ type: :development
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - ">="
24
+ - !ruby/object:Gem::Version
25
+ version: '0'
26
+ - !ruby/object:Gem::Dependency
27
+ name: minitest-spec-context
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ - !ruby/object:Gem::Dependency
41
+ name: rake
42
+ requirement: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ type: :development
48
+ prerelease: false
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
12
54
  description: Objects for handling durations of time.
13
55
  email: code@thoran.com
14
56
  executables: []
15
57
  extensions: []
16
58
  extra_rdoc_files: []
17
59
  files:
60
+ - CHANGELOG
18
61
  - Gemfile
19
62
  - README.md
63
+ - Rakefile
20
64
  - duration.rb.gemspec
21
65
  - lib/Duration.rb
22
66
  - lib/Duration/Common.rb
@@ -37,7 +81,6 @@ files:
37
81
  - test/Duration/Numeric_test.rb
38
82
  - test/Duration/Seconds_test.rb
39
83
  - test/Duration/Weeks_test.rb
40
- - test/test_all.rb
41
84
  - test/test_helper.rb
42
85
  homepage: http://github.com/thoran/duration.rb
43
86
  licenses:
@@ -57,7 +100,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
57
100
  - !ruby/object:Gem::Version
58
101
  version: '0'
59
102
  requirements: []
60
- rubygems_version: 4.0.0
103
+ rubygems_version: 4.0.16
61
104
  specification_version: 4
62
105
  summary: Objects for handling durations of time.
63
106
  test_files: []
data/test/test_all.rb DELETED
@@ -1,5 +0,0 @@
1
- # test/test_all.rb
2
-
3
- Dir[File.join(__dir__, '**/*_test.rb')].each do |test_file|
4
- require test_file
5
- end