duration.rb 0.3.4 → 0.3.5

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: c8bbc565cb16fb074e951bca1f185eb80259d0d1319e64b494c278378ee1c43d
4
+ data.tar.gz: b050be4911300967ed38138c2ffb24053814b47d1ece73cc9592082cb500324d
5
5
  SHA512:
6
- metadata.gz: 6ee50579a2597c396281ce00aba23b6b558f853309d7fe976dd164a0dbfb992f5f4a574d54764f114e5b89b078cd80c2c1db89f4dafd07e036eb5692cc9309df
7
- data.tar.gz: cd7cc3d6a4d011d2dd50d46f1841fd04e6c004d58e8fff8206d172bdb19b5141da54f66f681e9038a69f99a25e71bb4de99e4a6deb41a2749e7e6d68dd114be2
6
+ metadata.gz: 488c5e1b613abde3bd4a1fe8a50696dc0aee0dbb7f597e0c03e4b46a67a5d515e0720fe583cf66501c822818ea7b5ed7553bd9288cd3b2c74b0531ec1e67265c
7
+ data.tar.gz: ca417f99691e7dece350937b0b407c44d24fe22aabcefe4327a58394dd1b3ec9dc1af3156b62a914f8334e272303fe491fc6d9c4755d9b685c20217105b08ba8
data/CHANGELOG ADDED
@@ -0,0 +1,15 @@
1
+ # CHANGELOG
2
+
3
+ ## 20260717
4
+
5
+ 0.3.5: Months conversion constant bug fix.
6
+
7
+ 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.
8
+ 2. ~ Duration::Months#to_weeks: The same constant, in the other direction.
9
+ 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.
10
+ 4. ~ test/Duration/Months_test.rb: The conversion expectations, each of which encoded the old constant.
11
+ 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.
12
+ 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.
13
+ 7. + CHANGELOG
14
+ 8. ~ duration.rb.gemspec: spec.files to include CHANGELOG.
15
+ 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/duration.rb.gemspec CHANGED
@@ -17,6 +17,7 @@ Gem::Specification.new do |spec|
17
17
  spec.required_ruby_version = '>= 2.5'
18
18
 
19
19
  spec.files = [
20
+ 'CHANGELOG',
20
21
  'duration.rb.gemspec',
21
22
  'Gemfile',
22
23
  Dir['lib/**/*.rb'],
@@ -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.5'
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,7 +1,7 @@
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.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - thoran
@@ -15,6 +15,7 @@ executables: []
15
15
  extensions: []
16
16
  extra_rdoc_files: []
17
17
  files:
18
+ - CHANGELOG
18
19
  - Gemfile
19
20
  - README.md
20
21
  - duration.rb.gemspec
@@ -57,7 +58,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
57
58
  - !ruby/object:Gem::Version
58
59
  version: '0'
59
60
  requirements: []
60
- rubygems_version: 4.0.0
61
+ rubygems_version: 4.0.16
61
62
  specification_version: 4
62
63
  summary: Objects for handling durations of time.
63
64
  test_files: []