date_values 0.1.0 → 0.1.1
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 +24 -0
- data/lib/date_values/month_day.rb +4 -0
- data/lib/date_values/time_of_day.rb +4 -0
- data/lib/date_values/version.rb +1 -1
- data/lib/date_values/year_month.rb +4 -0
- data/sig/date_values.rbs +6 -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: 8ddef0176920084031675a2e93da2007646c642f23d0238ff4c54848f4ae0691
|
|
4
|
+
data.tar.gz: ecfbf84c37563d8b7ec9c592a625313aa95e7c0de0bb13d69b05ca8c96349389
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e1f49621fe9037b5a5dddaea83c267bdcf7493dbf15b87a6ddb6e93b131843799836aa0608cb9f83b8759453265cd1ec747cbf01e3c6f518b7cf9517c3e832bd
|
|
7
|
+
data.tar.gz: 25ce52fd8bfd18544c62704562704eeba340cf44cfbb57d408c38d3d19b3771034026803a80f1d2660894541cca4d8c213a6bd462bbf62db2184ed4bde6106be
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
## [Unreleased]
|
|
2
2
|
|
|
3
|
+
## [0.1.1] - 2026-03-19
|
|
4
|
+
|
|
5
|
+
- Add `.from` class methods for converting from `Date` / `Time` (`YearMonth.from(date)`, `MonthDay.from(date)`, `TimeOfDay.from(time)`)
|
|
6
|
+
|
|
3
7
|
## [0.1.0] - 2026-03-19
|
|
4
8
|
|
|
5
9
|
- `DateValues::YearMonth` — year-month value object with arithmetic (`+`, `-`), `Range` support, and `Date` conversion
|
data/README.md
CHANGED
|
@@ -24,6 +24,7 @@ ym = YearMonth.new(2026, 3)
|
|
|
24
24
|
ym.to_s # => "2026-03"
|
|
25
25
|
ym.to_date # => #<Date: 2026-03-01>
|
|
26
26
|
|
|
27
|
+
YearMonth.from(Date.today) # => YearMonth[2026-03]
|
|
27
28
|
YearMonth.parse('2026-03') # => YearMonth[2026-03]
|
|
28
29
|
|
|
29
30
|
ym + 1 # => YearMonth[2026-04]
|
|
@@ -42,6 +43,7 @@ md = MonthDay.new(3, 19)
|
|
|
42
43
|
md.to_s # => "--03-19"
|
|
43
44
|
md.to_date(2026) # => #<Date: 2026-03-19>
|
|
44
45
|
|
|
46
|
+
MonthDay.from(Date.today) # => MonthDay[--03-19]
|
|
45
47
|
MonthDay.parse('--03-19') # => MonthDay[--03-19]
|
|
46
48
|
```
|
|
47
49
|
|
|
@@ -53,9 +55,31 @@ tod.to_s # => "14:30"
|
|
|
53
55
|
|
|
54
56
|
TimeOfDay.new(14, 30, 45).to_s # => "14:30:45"
|
|
55
57
|
|
|
58
|
+
TimeOfDay.from(Time.now) # => TimeOfDay[14:30]
|
|
56
59
|
TimeOfDay.parse('14:30') # => TimeOfDay[14:30]
|
|
57
60
|
```
|
|
58
61
|
|
|
62
|
+
### Pattern Matching
|
|
63
|
+
|
|
64
|
+
Built on `Data.define`, so pattern matching works out of the box:
|
|
65
|
+
|
|
66
|
+
```ruby
|
|
67
|
+
case YearMonth.new(2026, 3)
|
|
68
|
+
in { year: 2026, month: (1..3) }
|
|
69
|
+
puts 'Q1 2026'
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
case MonthDay.new(12, 25)
|
|
73
|
+
in { month: 12, day: 25 }
|
|
74
|
+
puts 'Christmas'
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
case TimeOfDay.new(14, 30)
|
|
78
|
+
in { hour: (9..17) }
|
|
79
|
+
puts 'Business hours'
|
|
80
|
+
end
|
|
81
|
+
```
|
|
82
|
+
|
|
59
83
|
## Rails Integration
|
|
60
84
|
|
|
61
85
|
Opt-in ActiveModel type casting for ActiveRecord attributes:
|
data/lib/date_values/version.rb
CHANGED
data/sig/date_values.rbs
CHANGED
|
@@ -9,6 +9,8 @@ module DateValues
|
|
|
9
9
|
|
|
10
10
|
def initialize: (Integer year, Integer month) -> void
|
|
11
11
|
|
|
12
|
+
def self.from: (Date date) -> YearMonth
|
|
13
|
+
|
|
12
14
|
def self.parse: (String str) -> YearMonth
|
|
13
15
|
|
|
14
16
|
def <=>: (YearMonth other) -> Integer
|
|
@@ -36,6 +38,8 @@ module DateValues
|
|
|
36
38
|
|
|
37
39
|
def initialize: (Integer month, Integer day) -> void
|
|
38
40
|
|
|
41
|
+
def self.from: (Date date) -> MonthDay
|
|
42
|
+
|
|
39
43
|
def self.parse: (String str) -> MonthDay
|
|
40
44
|
|
|
41
45
|
def <=>: (MonthDay other) -> Integer
|
|
@@ -61,6 +65,8 @@ module DateValues
|
|
|
61
65
|
|
|
62
66
|
def initialize: (Integer hour, Integer minute, ?Integer second) -> void
|
|
63
67
|
|
|
68
|
+
def self.from: (Time time) -> TimeOfDay
|
|
69
|
+
|
|
64
70
|
def self.parse: (String str) -> TimeOfDay
|
|
65
71
|
|
|
66
72
|
def <=>: (TimeOfDay other) -> Integer
|