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 +4 -4
- data/CHANGELOG +15 -0
- data/README.md +19 -0
- data/duration.rb.gemspec +1 -0
- data/lib/Duration/Months.rb +2 -1
- data/lib/Duration/VERSION.rb +1 -1
- data/lib/Duration/Weeks.rb +2 -1
- data/test/Duration/Days_test.rb +1 -1
- data/test/Duration/Hours_test.rb +1 -1
- data/test/Duration/Milliseconds_test.rb +1 -1
- data/test/Duration/Minutes_test.rb +1 -1
- data/test/Duration/Months_test.rb +6 -6
- data/test/Duration/Seconds_test.rb +1 -1
- data/test/Duration/Weeks_test.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: c8bbc565cb16fb074e951bca1f185eb80259d0d1319e64b494c278378ee1c43d
|
|
4
|
+
data.tar.gz: b050be4911300967ed38138c2ffb24053814b47d1ece73cc9592082cb500324d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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
data/lib/Duration/Months.rb
CHANGED
data/lib/Duration/VERSION.rb
CHANGED
data/lib/Duration/Weeks.rb
CHANGED
data/test/Duration/Days_test.rb
CHANGED
|
@@ -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.
|
|
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
|
data/test/Duration/Hours_test.rb
CHANGED
|
@@ -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.
|
|
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.
|
|
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.
|
|
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).
|
|
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).
|
|
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).
|
|
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).
|
|
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.
|
|
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.
|
|
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.
|
|
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
|
data/test/Duration/Weeks_test.rb
CHANGED
|
@@ -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.
|
|
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
|
+
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.
|
|
61
|
+
rubygems_version: 4.0.16
|
|
61
62
|
specification_version: 4
|
|
62
63
|
summary: Objects for handling durations of time.
|
|
63
64
|
test_files: []
|