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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2fcd39df5c13a6c209d893be43a2be980a20219c5e02c5cc1283a67ba84cf07e
4
- data.tar.gz: 16ddf29780a17802e64bef957362fe4588fe4e1c9bd67af9a95798d4c65f1379
3
+ metadata.gz: 10dc98d9c1080745a0aebb8880f9bbafd34d1d5c9103736683b35633f6cd8d2c
4
+ data.tar.gz: aa7288bf8c473376b30f0e46fadfd1b78c79c34173deae88055d3ce5f7e47ec5
5
5
  SHA512:
6
- metadata.gz: b0611c9270e1237268eb2a1d17cca321455bebca402afc5ce4730922171364948498759deba7ba471474657aa2e445b066d7ab26b33e23318f6848bb95363e6b
7
- data.tar.gz: 664a70b1c75f04341ba490823ae76073bc7d5618493497d7e64c513e3de8c198ae67b0c8ce84549fca3100608922fc79f8b63592180c529be468e45300082e1f
6
+ metadata.gz: 34876d1314f36317f6fd2392e5489327e00f56df5b62cfcce0f27432469026957dfbf328459dbb1c84a9e1511e5c989f9ca556988ecefcf5f05d60df65ad2e56
7
+ data.tar.gz: '09fe11dd318422c430a941be38194bdeff80ff550a9fbce78076cad789d70076c698a2e409d03c79ea85aa61a3c4d2f2b03c00b28192facb6ec90e78b5dac222'
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.2.2] - 2026-03-21
4
+
5
+ - `TimeOfDay#-` accepts `TimeOfDay` to return difference in seconds
6
+
3
7
  ## [0.2.1] - 2026-03-21
4
8
 
5
9
  - Add `TimeOfDay` arithmetic (`+`, `-`), `advance`, `change`, `to_seconds`, `.from_seconds`
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 # => "2026-03"
25
- ym.to_date # => #<Date: 2026-03-01>
26
- ym.days # => 31
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) # => #<DateValues::YearMonth 2026-03>
29
- YearMonth.parse('2026-03') # => #<DateValues::YearMonth 2026-03>
30
- YearMonth.parse('2026/3') # also works
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 # => #<DateValues::YearMonth 2026-04>
33
- ym - 1 # => #<DateValues::YearMonth 2026-02>
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) # => #<DateValues::YearMonth 2027-05>
37
- ym.change(year: 2025) # => #<DateValues::YearMonth 2025-03>
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 # => "--03-19"
51
- md.to_date(2026) # => #<Date: 2026-03-19>
50
+ md.to_s # => "--03-19"
51
+ md.to_date(2026) # => #<Date: 2026-03-19>
52
52
 
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)
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) # => #<DateValues::MonthDay --12-19>
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 # => "14:30"
68
+ tod.to_s # => "14:30"
69
69
 
70
- TimeOfDay.new(14, 30, 45).to_s # => "14:30:45"
70
+ TimeOfDay.new(14, 30, 45).to_s # => "14:30:45"
71
71
 
72
- TimeOfDay.from(Time.now) # => #<DateValues::TimeOfDay 14:30>
73
- TimeOfDay.parse('14:30') # => #<DateValues::TimeOfDay 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 # => #<DateValues::TimeOfDay 15:30>
76
- tod - 1800 # => #<DateValues::TimeOfDay 14:00>
77
- tod.advance(hours: 2, minutes: 15) # => #<DateValues::TimeOfDay 16:45>
78
- tod.change(minute: 0) # => #<DateValues::TimeOfDay 14:00>
79
- tod.to_seconds # => 52200
80
- TimeOfDay.from_seconds(52200) # => #<DateValues::TimeOfDay 14:30>
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 # => #<DateValues::TimeOfDay 00:30>
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 -(seconds)
37
- self + (-seconds)
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)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DateValues
4
- VERSION = '0.2.1'
4
+ VERSION = '0.2.2'
5
5
  end
data/sig/date_values.rbs CHANGED
@@ -102,6 +102,7 @@ module DateValues
102
102
  def +: (Integer seconds) -> TimeOfDay
103
103
 
104
104
  def -: (Integer seconds) -> TimeOfDay
105
+ | (TimeOfDay other) -> Integer
105
106
 
106
107
  def advance: (?hours: Integer, ?minutes: Integer, ?seconds: Integer) -> TimeOfDay
107
108
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: date_values
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Keita Urashima