gitlab_chronic_duration 0.11.0 → 0.13.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 90ed911722678aa8c57973bd8cf733877d32bd06b0e313764502100bd0e36bf7
4
- data.tar.gz: 5a5afd28caceefa29332d8774a161b811a1340344fdff23a33cd33f7d91aaaea
3
+ metadata.gz: 82e84baa4686ca72cfb73246286d3006461241b906678b3515bae1d5d63b7986
4
+ data.tar.gz: abfe232f81139417d80ad1ec4ba77227bfdca08c200436e77d3049637522163c
5
5
  SHA512:
6
- metadata.gz: '085d3ef7649df9ff93e215b41cea7d77739c415c9295f201a5e005da90c52309d395459bf0543512e729c0feb73a4520d4123d7250191888212f6c12f7f2c0d8'
7
- data.tar.gz: 374eaf5cfee394c835a28bad82214de21a921a4cbc11a99f58844e43b7f240c804f757b941294924927a7b88a33e3925a44c86e6f8defc893c0533e00bc969e2
6
+ metadata.gz: d5ead0c874d9e1f9bfc7c88fb04d0080a54cf7bc2f2fa427486c2c7c7ff51158b7f02551dc5ae75f262def80b135f34073afcce04581d984975752e69e597b25
7
+ data.tar.gz: f34255f688f723f3c4d68602b1470aa1fa9df75b26d663f98fad79efd004a17e9dda8fe4cd389da9f63a058239eaccce03ecbff43daacc1d16f57aa168dc1f20
data/.gitlab-ci.yml CHANGED
@@ -1,3 +1,8 @@
1
+ include:
2
+ - component: gitlab.com/gitlab-org/components/gem-release/gem-release@~latest
3
+ inputs:
4
+ gem_name: gitlab_chronic_duration
5
+
1
6
  .default:
2
7
  image: "ruby:${RUBY_VERSION}"
3
8
  before_script:
@@ -14,4 +19,4 @@ rspec:
14
19
  - bundle exec rspec
15
20
  parallel:
16
21
  matrix:
17
- - RUBY_VERSION: ['2.7', '3.0', '3.1', '3.2']
22
+ - RUBY_VERSION: ['3.0', '3.1', '3.2', '3.3', '3.4']
data/AGENTS.md ADDED
@@ -0,0 +1,79 @@
1
+ # gitlab_chronic_duration: AI agent guidelines
2
+
3
+ gitlab_chronic_duration is a Ruby gem that parses natural language durations
4
+ ("4 hours and 30 minutes") into seconds, and formats seconds back into text.
5
+ It is a GitLab-maintained fork of chronic_duration. See `README.md` for usage.
6
+
7
+ ## Project layout
8
+
9
+ - `lib/gitlab_chronic_duration.rb`: the parser and formatter
10
+ - `lib/chronic_duration/version.rb`: the gem version. Bumping this on `master`
11
+ triggers a release (see below).
12
+ - `spec/`: RSpec tests
13
+
14
+ ## Development commands
15
+
16
+ ```sh
17
+ bundle install
18
+ bundle exec rspec # tests
19
+ ```
20
+
21
+ CI runs the specs against every Ruby version listed in `.gitlab-ci.yml`.
22
+
23
+ ## Commit messages
24
+
25
+ Follow the [GitLab commit message guidelines](https://docs.gitlab.com/development/contributing/merge_request_workflow/#commit-messages-guidelines).
26
+
27
+ - Subject: imperative mood, capitalized, no trailing period, at most 72 chars
28
+ ("Fix parsing of fractional weeks", not "Fixed parsing of fractional weeks").
29
+ - Body: explain *why*, wrap at 72 chars. Reference issues and MRs with full
30
+ URLs, not short references (`#123`).
31
+
32
+ ## Changelog trailer (required for user-facing changes)
33
+
34
+ Releases are cut by the `gem-release` CI component, which builds the release
35
+ notes from GitLab's changelog generator. That generator **only includes commits
36
+ that carry a `Changelog:` git trailer**. Commits without one are dropped, so a
37
+ release can end up saying "No changes." and give downstream projects, such as
38
+ gitlab-org/gitlab, an empty changelog.
39
+
40
+ Add the trailer as a **separate block at the end of the commit message**,
41
+ preceded by a blank line. Git needs the blank line to parse it as a trailer;
42
+ without it the changelog generator silently drops the commit.
43
+
44
+ ```
45
+ Changelog: <type>
46
+ ```
47
+
48
+ Valid types: `added`, `fixed`, `changed`, `deprecated`, `removed`, `security`,
49
+ `performance`, `other`.
50
+
51
+ **Include a trailer for:** new or changed parsing or output behavior, bug
52
+ fixes, performance improvements, dependency bumps that affect users, security
53
+ fixes.
54
+
55
+ **Skip the trailer for:** test-only changes, documentation-only changes, CI or
56
+ tooling-only changes, and pure internal refactors with no user-visible effect.
57
+
58
+ Example:
59
+
60
+ ```
61
+ Avoid eval per time unit in ChronicDuration.output
62
+
63
+ output looked up each unit value with eval, seven evals per call.
64
+ Build a hash of the unit values once and iterate over it instead.
65
+ Output is unchanged.
66
+
67
+ Changelog: performance
68
+ ```
69
+
70
+ `CHANGELOG.md` is no longer maintained. Release notes live in GitLab Releases,
71
+ built from the trailers above. Do not add entries to `CHANGELOG.md`.
72
+
73
+ ## Releasing
74
+
75
+ A release happens when `lib/chronic_duration/version.rb` changes on `master`.
76
+ The CI pipeline then generates the changelog from the `Changelog:` trailers
77
+ since the previous tag, creates the GitLab Release and tag, and publishes the
78
+ gem to RubyGems. Keeping trailers accurate on every merged commit is what makes
79
+ those release notes meaningful.
data/CLAUDE.md ADDED
@@ -0,0 +1 @@
1
+ @AGENTS.md
@@ -1,3 +1,3 @@
1
1
  module ChronicDuration
2
- VERSION = '0.11.0'.freeze
2
+ VERSION = '0.13.0'.freeze
3
3
  end
@@ -46,8 +46,7 @@ module ChronicDuration
46
46
  # return an integer (or float, if fractions of a
47
47
  # second are input)
48
48
  def parse(string, opts = {})
49
- use_complete_matcher = opts.fetch(:use_complete_matcher, false)
50
- result = calculate_from_words(cleanup(string, use_complete_matcher), opts)
49
+ result = calculate_from_words(cleanup(string), opts)
51
50
  (!opts[:keep_zero] and result == 0) ? nil : result
52
51
  end
53
52
 
@@ -147,9 +146,10 @@ module ChronicDuration
147
146
  joiner = ''
148
147
  end
149
148
 
150
- result = [:years, :months, :weeks, :days, :hours, :minutes, :seconds].map do |t|
149
+ values = { :years => years, :months => months, :weeks => weeks, :days => days, :hours => hours, :minutes => minutes, :seconds => seconds }
150
+
151
+ result = values.map do |t, num|
151
152
  next if t == :weeks && !opts[:weeks]
152
- num = eval(t.to_s)
153
153
  num = ("%.#{decimal_places}f" % num) if num.is_a?(Float) && t == :seconds
154
154
  keep_zero = dividers[:keep_zero]
155
155
  keep_zero ||= opts[:keep_zero] if t == :seconds
@@ -189,9 +189,9 @@ private
189
189
  val
190
190
  end
191
191
 
192
- def cleanup(string, use_complete_matcher = false)
192
+ def cleanup(string)
193
193
  res = string.downcase
194
- res = filter_by_type(Numerizer.numerize(res), use_complete_matcher)
194
+ res = filter_by_type(Numerizer.numerize(res))
195
195
  res = res.gsub(float_matcher) {|n| " #{n} "}.squeeze(' ').strip
196
196
  res = filter_through_white_list(res)
197
197
  end
@@ -223,11 +223,10 @@ private
223
223
  end
224
224
 
225
225
  # Parse 3:41:59 and return 3 hours 41 minutes 59 seconds
226
- def filter_by_type(string, use_complete_matcher = false)
226
+ def filter_by_type(string)
227
227
  chrono_units_list = duration_units_list.reject {|v| v == "weeks"}
228
- matcher = use_complete_matcher ? time_matcher : /#{float_matcher}(:#{float_matcher})+/
229
228
 
230
- if string.gsub(' ', '') =~ matcher
229
+ if string.gsub(' ', '') =~ time_matcher
231
230
  res = []
232
231
  string.gsub(' ', '').split(':').reverse.each_with_index do |v,k|
233
232
  return unless chrono_units_list[k]
@@ -271,21 +271,55 @@ describe ChronicDuration do
271
271
 
272
272
  @exemplars.each do |seconds, format_spec|
273
273
  format_spec.each do |format, _|
274
- context 'when using the legacy time matcher' do
275
- it "outputs a duration for #{seconds} that parses back to the same thing when using the #{format} format" do
276
- expect(ChronicDuration.parse(
277
- ChronicDuration.output(seconds, format: format, use_complete_matcher: false)
278
- )).to eq(seconds)
279
- end
274
+ it "outputs a duration for #{seconds} that parses back to the same thing when using the #{format} format" do
275
+ expect(ChronicDuration.parse(
276
+ ChronicDuration.output(seconds, format: format, use_complete_matcher: true)
277
+ )).to eq(seconds)
280
278
  end
279
+ end
280
+ end
281
281
 
282
- context 'when using the new time matcher' do
283
- it "outputs a duration for #{seconds} that parses back to the same thing when using the #{format} format" do
284
- expect(ChronicDuration.parse(
285
- ChronicDuration.output(seconds, format: format, use_complete_matcher: true)
286
- )).to eq(seconds)
287
- end
288
- end
282
+ context "with :weeks" do
283
+ seconds = 45 * 24 * 3600 + 3 * 3600 + 61
284
+
285
+ it "outputs every unit in each format" do
286
+ expect(ChronicDuration.output(seconds, weeks: true)).to eq('1 mo 2 wks 3 days 3 hrs 1 min 1 sec')
287
+ expect(ChronicDuration.output(seconds, weeks: true, format: :short)).to eq('1mo 2w 3d 3h 1m 1s')
288
+ expect(ChronicDuration.output(seconds, weeks: true, format: :long)).to eq('1 month 2 weeks 3 days 3 hours 1 minute 1 second')
289
+ end
290
+
291
+ it "counts weeks towards :units" do
292
+ expect(ChronicDuration.output(seconds, weeks: true, units: 2)).to eq('1 mo 2 wks')
293
+ end
294
+ end
295
+
296
+ it "keeps zero seconds after larger units when :keep_zero is set" do
297
+ expect(ChronicDuration.output(3600, keep_zero: true)).to eq('1 hr 0 secs')
298
+ expect(ChronicDuration.output(3600, keep_zero: true, format: :short)).to eq('1h 0s')
299
+ end
300
+
301
+ it "outputs float seconds after larger units" do
302
+ expect(ChronicDuration.output(3725.5)).to eq('1 hr 2 mins 5.5 secs')
303
+ expect(ChronicDuration.output(3725.5, format: :chrono)).to eq('1:02:05.5')
304
+ end
305
+
306
+ it "treats whole float seconds as integers" do
307
+ expect(ChronicDuration.output(2.0)).to eq('2 secs')
308
+ expect(ChronicDuration.output(0.0)).to be_nil
309
+ expect(ChronicDuration.output(0.0, keep_zero: true)).to eq('0 secs')
310
+ end
311
+
312
+ context "with the options GitLab time tracking uses" do
313
+ let(:opts) { { format: :short, hours_per_day: 8, days_per_month: 20, weeks: true } }
314
+
315
+ it "outputs short durations" do
316
+ expect(ChronicDuration.output(0, opts)).to be_nil
317
+ expect(ChronicDuration.output(5400, opts)).to eq('1h 30m')
318
+ expect(ChronicDuration.output(7 * 8 * 3600 + 5400, opts)).to eq('1w 2d 1h 30m')
319
+ end
320
+
321
+ it "outputs hours only with :limit_to_hours" do
322
+ expect(ChronicDuration.output(395 * 24 * 3600 + 90, opts.merge(limit_to_hours: true))).to eq('9480h 1m 30s')
289
323
  end
290
324
  end
291
325
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gitlab_chronic_duration
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.0
4
+ version: 0.13.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - hpoydar
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-08-29 00:00:00.000000000 Z
11
+ date: 2026-11-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: numerizer
@@ -65,7 +65,9 @@ extra_rdoc_files: []
65
65
  files:
66
66
  - ".gitignore"
67
67
  - ".gitlab-ci.yml"
68
+ - AGENTS.md
68
69
  - CHANGELOG.md
70
+ - CLAUDE.md
69
71
  - Gemfile
70
72
  - LICENSE.txt
71
73
  - README.md
@@ -94,7 +96,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
94
96
  - !ruby/object:Gem::Version
95
97
  version: '0'
96
98
  requirements: []
97
- rubygems_version: 3.4.19
99
+ rubygems_version: 3.5.22
98
100
  signing_key:
99
101
  specification_version: 4
100
102
  summary: A simple Ruby natural language parser for elapsed time