date_values 0.2.1 → 0.2.2
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.md +4 -0
- data/README.md +28 -27
- data/lib/date_values/time_of_day.rb +6 -2
- data/lib/date_values/version.rb +1 -1
- data/sig/date_values.rbs +1 -0
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 10dc98d9c1080745a0aebb8880f9bbafd34d1d5c9103736683b35633f6cd8d2c
|
|
4
|
+
data.tar.gz: aa7288bf8c473376b30f0e46fadfd1b78c79c34173deae88055d3ce5f7e47ec5
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 34876d1314f36317f6fd2392e5489327e00f56df5b62cfcce0f27432469026957dfbf328459dbb1c84a9e1511e5c989f9ca556988ecefcf5f05d60df65ad2e56
|
|
7
|
+
data.tar.gz: '09fe11dd318422c430a941be38194bdeff80ff550a9fbce78076cad789d70076c698a2e409d03c79ea85aa61a3c4d2f2b03c00b28192facb6ec90e78b5dac222'
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
|
@@ -21,20 +21,20 @@ include DateValues
|
|
|
21
21
|
|
|
22
22
|
```ruby
|
|
23
23
|
ym = YearMonth.new(2026, 3)
|
|
24
|
-
ym.to_s
|
|
25
|
-
ym.to_date
|
|
26
|
-
ym.days
|
|
24
|
+
ym.to_s # => "2026-03"
|
|
25
|
+
ym.to_date # => #<Date: 2026-03-01>
|
|
26
|
+
ym.days # => 31
|
|
27
27
|
|
|
28
|
-
YearMonth.from(Date.today)
|
|
29
|
-
YearMonth.parse('2026-03')
|
|
30
|
-
YearMonth.parse('2026/3')
|
|
28
|
+
YearMonth.from(Date.today) # => #<DateValues::YearMonth 2026-03>
|
|
29
|
+
YearMonth.parse('2026-03') # => #<DateValues::YearMonth 2026-03>
|
|
30
|
+
YearMonth.parse('2026/3') # also works
|
|
31
31
|
|
|
32
|
-
ym + 1
|
|
33
|
-
ym - 1
|
|
32
|
+
ym + 1 # => #<DateValues::YearMonth 2026-04>
|
|
33
|
+
ym - 1 # => #<DateValues::YearMonth 2026-02>
|
|
34
34
|
YearMonth.new(2026, 3) - YearMonth.new(2025, 1) # => 14
|
|
35
35
|
|
|
36
|
-
ym.advance(years: 1, months: 2)
|
|
37
|
-
ym.change(year: 2025)
|
|
36
|
+
ym.advance(years: 1, months: 2) # => #<DateValues::YearMonth 2027-05>
|
|
37
|
+
ym.change(year: 2025) # => #<DateValues::YearMonth 2025-03>
|
|
38
38
|
|
|
39
39
|
# Range support
|
|
40
40
|
(YearMonth.new(2026, 1)..YearMonth.new(2026, 3)).to_a
|
|
@@ -47,14 +47,14 @@ String representation uses ISO 8601 `--MM-DD` format (year omitted):
|
|
|
47
47
|
|
|
48
48
|
```ruby
|
|
49
49
|
md = MonthDay.new(3, 19)
|
|
50
|
-
md.to_s
|
|
51
|
-
md.to_date(2026)
|
|
50
|
+
md.to_s # => "--03-19"
|
|
51
|
+
md.to_date(2026) # => #<Date: 2026-03-19>
|
|
52
52
|
|
|
53
|
-
MonthDay.from(Date.today)
|
|
54
|
-
MonthDay.parse('--03-19')
|
|
55
|
-
MonthDay.parse('3/19')
|
|
53
|
+
MonthDay.from(Date.today) # => #<DateValues::MonthDay --03-20>
|
|
54
|
+
MonthDay.parse('--03-19') # => #<DateValues::MonthDay --03-19>
|
|
55
|
+
MonthDay.parse('3/19') # also works (month/day order by default)
|
|
56
56
|
|
|
57
|
-
md.change(month: 12)
|
|
57
|
+
md.change(month: 12) # => #<DateValues::MonthDay --12-19>
|
|
58
58
|
|
|
59
59
|
# Range membership
|
|
60
60
|
summer = MonthDay.new(6, 1)..MonthDay.new(8, 31)
|
|
@@ -65,22 +65,23 @@ summer.cover?(MonthDay.new(7, 15)) # => true
|
|
|
65
65
|
|
|
66
66
|
```ruby
|
|
67
67
|
tod = TimeOfDay.new(14, 30)
|
|
68
|
-
tod.to_s
|
|
68
|
+
tod.to_s # => "14:30"
|
|
69
69
|
|
|
70
|
-
TimeOfDay.new(14, 30, 45).to_s
|
|
70
|
+
TimeOfDay.new(14, 30, 45).to_s # => "14:30:45"
|
|
71
71
|
|
|
72
|
-
TimeOfDay.from(Time.now)
|
|
73
|
-
TimeOfDay.parse('14:30')
|
|
72
|
+
TimeOfDay.from(Time.now) # => #<DateValues::TimeOfDay 14:30>
|
|
73
|
+
TimeOfDay.parse('14:30') # => #<DateValues::TimeOfDay 14:30>
|
|
74
74
|
|
|
75
|
-
tod + 3600
|
|
76
|
-
tod - 1800
|
|
77
|
-
|
|
78
|
-
tod.
|
|
79
|
-
tod.
|
|
80
|
-
|
|
75
|
+
tod + 3600 # => #<DateValues::TimeOfDay 15:30>
|
|
76
|
+
tod - 1800 # => #<DateValues::TimeOfDay 14:00>
|
|
77
|
+
TimeOfDay.new(17, 0) - TimeOfDay.new(9, 0) # => 28800 (seconds)
|
|
78
|
+
tod.advance(hours: 2, minutes: 15) # => #<DateValues::TimeOfDay 16:45>
|
|
79
|
+
tod.change(minute: 0) # => #<DateValues::TimeOfDay 14:00>
|
|
80
|
+
tod.to_seconds # => 52200
|
|
81
|
+
TimeOfDay.from_seconds(52200) # => #<DateValues::TimeOfDay 14:30>
|
|
81
82
|
|
|
82
83
|
# Wraps at 24h boundaries
|
|
83
|
-
TimeOfDay.new(23, 30) + 3600
|
|
84
|
+
TimeOfDay.new(23, 30) + 3600 # => #<DateValues::TimeOfDay 00:30>
|
|
84
85
|
|
|
85
86
|
# Range membership
|
|
86
87
|
business_hours = TimeOfDay.new(9, 0)..TimeOfDay.new(17, 0)
|
|
@@ -33,8 +33,12 @@ module DateValues
|
|
|
33
33
|
self.class.from_seconds((to_seconds + seconds) % 86_400)
|
|
34
34
|
end
|
|
35
35
|
|
|
36
|
-
def -(
|
|
37
|
-
|
|
36
|
+
def -(other)
|
|
37
|
+
case other
|
|
38
|
+
when Integer then self + (-other)
|
|
39
|
+
when TimeOfDay then to_seconds - other.to_seconds
|
|
40
|
+
else raise TypeError, "#{other.class} can't be coerced into Integer or TimeOfDay"
|
|
41
|
+
end
|
|
38
42
|
end
|
|
39
43
|
|
|
40
44
|
def advance(hours: 0, minutes: 0, seconds: 0)
|
data/lib/date_values/version.rb
CHANGED
data/sig/date_values.rbs
CHANGED