gitlab_chronic_duration 0.12.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: fd977f94bc4ee464a30cfacd01d6253b80257a12954999177ceea000d5062e3c
4
- data.tar.gz: df6259ba488ea8602b07fde675dda671a4c935e66fba40e394ac7dc958010a1c
3
+ metadata.gz: 82e84baa4686ca72cfb73246286d3006461241b906678b3515bae1d5d63b7986
4
+ data.tar.gz: abfe232f81139417d80ad1ec4ba77227bfdca08c200436e77d3049637522163c
5
5
  SHA512:
6
- metadata.gz: 820338929f8edee97de15fcdc6a3de01f5ea02ab327628c48805f3b02fa4a5a05d168fd75f63843873f3ce078369bdbd2d731fbffa7db0052fcc99765e42b85a
7
- data.tar.gz: deac822896c3f81c5f776fa1375ed6e23aad9ee27213b1192e863502f9419d56fba805a30f7c276707353dd98a97a8d4e3bd937a8ebf683e87e2a8731a75783b
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.12.0'.freeze
2
+ VERSION = '0.13.0'.freeze
3
3
  end
@@ -146,9 +146,10 @@ module ChronicDuration
146
146
  joiner = ''
147
147
  end
148
148
 
149
- 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|
150
152
  next if t == :weeks && !opts[:weeks]
151
- num = eval(t.to_s)
152
153
  num = ("%.#{decimal_places}f" % num) if num.is_a?(Float) && t == :seconds
153
154
  keep_zero = dividers[:keep_zero]
154
155
  keep_zero ||= opts[:keep_zero] if t == :seconds
@@ -279,6 +279,50 @@ describe ChronicDuration do
279
279
  end
280
280
  end
281
281
 
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')
323
+ end
324
+ end
325
+
282
326
  it "uses user-specified joiner if provided" do
283
327
  expect(ChronicDuration.output(2 * 3600 + 20 * 60, joiner: ', ')).to eq('2 hrs, 20 mins')
284
328
  end
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.12.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-09-18 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