date_values 0.1.2 → 0.1.3
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 +5 -0
- data/README.md +16 -1
- data/lib/date_values/rails.rb +6 -0
- data/lib/date_values/version.rb +1 -1
- 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: 18c625b8766c99ee4e063b2d2b756f68702d7468301cf0e14cb61c29647bc97e
|
|
4
|
+
data.tar.gz: cc21e80e920a5590109a62894d362b541f5f7362835f7d5113980b20bc28842f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 3ea359a67138a64040d1fc62a9288c3862665f636db9e1651697ec6527390e1e53cb002f87745df2189b8eba8944f104e127b620af032be0e92d5a5d707f77a2
|
|
7
|
+
data.tar.gz: f5a8b524c53566ee986a3eea6bf28d08e889a428d15b7ae48f04443d46108ee7b882391adc82bc597af10338ef071ec9ecb83dc6812718d67ef332c5065432eb
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
## [Unreleased]
|
|
2
2
|
|
|
3
|
+
## [0.1.3] - 2026-03-20
|
|
4
|
+
|
|
5
|
+
- Fix ActiveRecord type registration — use `ActiveSupport.on_load(:active_record)` to register types regardless of load order
|
|
6
|
+
- Values now work directly in ActiveRecord queries (`Shop.where(billing_month: YearMonth.new(2026, 3))`)
|
|
7
|
+
|
|
3
8
|
## [0.1.2] - 2026-03-19
|
|
4
9
|
|
|
5
10
|
- Add `#strftime` to `YearMonth`, `MonthDay`, and `TimeOfDay`
|
data/README.md
CHANGED
|
@@ -43,8 +43,12 @@ md = MonthDay.new(3, 19)
|
|
|
43
43
|
md.to_s # => "--03-19"
|
|
44
44
|
md.to_date(2026) # => #<Date: 2026-03-19>
|
|
45
45
|
|
|
46
|
-
MonthDay.from(Date.today) # => MonthDay[--03-
|
|
46
|
+
MonthDay.from(Date.today) # => MonthDay[--03-20]
|
|
47
47
|
MonthDay.parse('--03-19') # => MonthDay[--03-19]
|
|
48
|
+
|
|
49
|
+
# Range membership
|
|
50
|
+
summer = MonthDay.new(6, 1)..MonthDay.new(8, 31)
|
|
51
|
+
summer.cover?(MonthDay.new(7, 15)) # => true
|
|
48
52
|
```
|
|
49
53
|
|
|
50
54
|
### TimeOfDay
|
|
@@ -57,6 +61,10 @@ TimeOfDay.new(14, 30, 45).to_s # => "14:30:45"
|
|
|
57
61
|
|
|
58
62
|
TimeOfDay.from(Time.now) # => TimeOfDay[14:30]
|
|
59
63
|
TimeOfDay.parse('14:30') # => TimeOfDay[14:30]
|
|
64
|
+
|
|
65
|
+
# Range membership
|
|
66
|
+
business_hours = TimeOfDay.new(9, 0)..TimeOfDay.new(17, 0)
|
|
67
|
+
business_hours.cover?(TimeOfDay.new(12, 30)) # => true
|
|
60
68
|
```
|
|
61
69
|
|
|
62
70
|
### Pattern Matching
|
|
@@ -94,6 +102,13 @@ class Shop < ApplicationRecord
|
|
|
94
102
|
end
|
|
95
103
|
```
|
|
96
104
|
|
|
105
|
+
Values are automatically serialized in queries:
|
|
106
|
+
|
|
107
|
+
```ruby
|
|
108
|
+
Shop.where(billing_month: YearMonth.new(2026, 3))
|
|
109
|
+
# SELECT * FROM shops WHERE billing_month = '2026-03'
|
|
110
|
+
```
|
|
111
|
+
|
|
97
112
|
### I18n / `l` Helper
|
|
98
113
|
|
|
99
114
|
All classes implement `#strftime`, and the Rails integration extends `I18n.l` to support them. Define formats in your locale files:
|
data/lib/date_values/rails.rb
CHANGED
|
@@ -12,4 +12,10 @@ ActiveModel::Type.register(:year_month, DateValues::Rails::YearMonthType)
|
|
|
12
12
|
ActiveModel::Type.register(:month_day, DateValues::Rails::MonthDayType)
|
|
13
13
|
ActiveModel::Type.register(:time_of_day, DateValues::Rails::TimeOfDayType)
|
|
14
14
|
|
|
15
|
+
ActiveSupport.on_load(:active_record) do
|
|
16
|
+
ActiveRecord::Type.register(:year_month, DateValues::Rails::YearMonthType)
|
|
17
|
+
ActiveRecord::Type.register(:month_day, DateValues::Rails::MonthDayType)
|
|
18
|
+
ActiveRecord::Type.register(:time_of_day, DateValues::Rails::TimeOfDayType)
|
|
19
|
+
end
|
|
20
|
+
|
|
15
21
|
I18n::Backend::Base.prepend(DateValues::Rails::I18nBackend)
|
data/lib/date_values/version.rb
CHANGED