tins 1.59.0 → 1.60.0
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/CHANGES.md +13 -0
- data/lib/tins/duration.rb +12 -1
- data/lib/tins/version.rb +1 -1
- data/tests/duration_test.rb +12 -1
- data/tins.gemspec +2 -2
- 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: c17298f1ee629a9226613814a7590bf107ab45e978cedf938407dd3160d1174a
|
|
4
|
+
data.tar.gz: b0246606c5dee0de323b62f91623a5d8f3b37f7da486c800e0fbef87a5a538a5
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: a24706b341766327830215b3ccb48cc498087e7559c1b230757e363cf2db9797737bf32d05e91e05a9eabda331918131e758ea899985865162ea5c65ba308e13
|
|
7
|
+
data.tar.gz: d55dea1d7ad3db342c8e60097bf716f8f74937f340c63ac76fc1bd6cbeb516ffd853e5cee7ad674b16143f318b36d424f4cd4345f02b71a6689aee8756733197
|
data/CHANGES.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# Changes
|
|
2
2
|
|
|
3
|
+
## 2026-10-02 v1.60.0
|
|
4
|
+
|
|
5
|
+
* Add unpadded `%H`, `%M`, and `%u` format directives to `Duration#format` for
|
|
6
|
+
unpadded hours, minutes, and seconds, complementing the existing zero-padded
|
|
7
|
+
`%h`, `%m`, and `%s`
|
|
8
|
+
* Update the directive regex in `format` from `/%[DdhmSs%]/` to
|
|
9
|
+
`/%[DdHhMmuSs%]/` to match the new directives
|
|
10
|
+
* Extend YARD documentation with an `@example` block demonstrating unpadded
|
|
11
|
+
components in a natural-language template
|
|
12
|
+
* Add `test_format_unpadded_directives` covering all three new directives in
|
|
13
|
+
both template and standalone usage
|
|
14
|
+
* Fix `assert_equal` argument order in `test_parse_percentage`
|
|
15
|
+
|
|
3
16
|
## 2026-09-25 v1.59.0
|
|
4
17
|
|
|
5
18
|
* Add `*sels` and `&block` parameters to `squeeze` and `squeeze!`, allowing
|
data/lib/tins/duration.rb
CHANGED
|
@@ -161,8 +161,11 @@ module Tins
|
|
|
161
161
|
# The template string supports the following directives:
|
|
162
162
|
# - `%S` - Sign indicator (negative sign if duration is negative)
|
|
163
163
|
# - `%d` - Days component
|
|
164
|
+
# - `%H` - Hours component (unpadded)
|
|
164
165
|
# - `%h` - Hours component (zero-padded to 2 digits)
|
|
166
|
+
# - `%M` - Minutes component (unpadded)
|
|
165
167
|
# - `%m` - Minutes component (zero-padded to 2 digits)
|
|
168
|
+
# - `%u` - Seconds component (unpadded)
|
|
166
169
|
# - `%s` - Seconds component (zero-padded to 2 digits)
|
|
167
170
|
# - `%f` - Fractional seconds component (without the leading decimal point)
|
|
168
171
|
# - `%D` - Smart format (automatically includes days, fractional seconds, and sign)
|
|
@@ -186,13 +189,21 @@ module Tins
|
|
|
186
189
|
#
|
|
187
190
|
# @example Custom precision
|
|
188
191
|
# duration.format('%s.%f', precision: 2) # => "04.12"
|
|
192
|
+
#
|
|
193
|
+
# @example Unpadded components
|
|
194
|
+
# duration = Tins::Duration.new(93_784)
|
|
195
|
+
# duration.format('%d day(s), %H hours, %M minutes, and %u seconds')
|
|
196
|
+
# # => "1 day(s), 2 hours, 3 minutes, and 4 seconds"
|
|
189
197
|
def format(template = '%S%d+%h:%m:%s.%f', precision: nil)
|
|
190
|
-
result = template.gsub(/%[
|
|
198
|
+
result = template.gsub(/%[DdHhMmuSs%]/) { |directive|
|
|
191
199
|
case directive
|
|
192
200
|
when '%S' then ?- if negative?
|
|
193
201
|
when '%d' then @days
|
|
202
|
+
when '%H' then '%u' % @hours
|
|
194
203
|
when '%h' then '%02u' % @hours
|
|
204
|
+
when '%M' then '%u' % @minutes
|
|
195
205
|
when '%m' then '%02u' % @minutes
|
|
206
|
+
when '%u' then '%u' % @seconds
|
|
196
207
|
when '%s' then '%02u' % @seconds
|
|
197
208
|
when '%D' then format_smart
|
|
198
209
|
when '%%' then '%'
|
data/lib/tins/version.rb
CHANGED
data/tests/duration_test.rb
CHANGED
|
@@ -96,7 +96,18 @@ module Tins
|
|
|
96
96
|
def test_parse_percentage
|
|
97
97
|
duration_string = '1%2'
|
|
98
98
|
seconds = Tins::Duration.parse(duration_string, template: '%h%%%m')
|
|
99
|
-
assert_equal
|
|
99
|
+
assert_equal 3720, seconds
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
def test_format_unpadded_directives
|
|
103
|
+
d = Tins::Duration.new(93_784) # 1d 2h 3m 4s
|
|
104
|
+
assert_equal(
|
|
105
|
+
'1 day(s), 2 hours, 3 minutes, and 4 seconds',
|
|
106
|
+
d.format('%d day(s), %H hours, %M minutes, and %u seconds')
|
|
107
|
+
)
|
|
108
|
+
assert_equal '2', d.format('%H')
|
|
109
|
+
assert_equal '3', d.format('%M')
|
|
110
|
+
assert_equal '4', d.format('%u')
|
|
100
111
|
end
|
|
101
112
|
end
|
|
102
113
|
end
|
data/tins.gemspec
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
|
2
|
-
# stub: tins 1.
|
|
2
|
+
# stub: tins 1.60.0 ruby lib
|
|
3
3
|
|
|
4
4
|
Gem::Specification.new do |s|
|
|
5
5
|
s.name = "tins".freeze
|
|
6
|
-
s.version = "1.
|
|
6
|
+
s.version = "1.60.0".freeze
|
|
7
7
|
|
|
8
8
|
s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
|
|
9
9
|
s.require_paths = ["lib".freeze]
|