WIP: feat: better parsing of duration in config #10273

Taslak
Gusted gusted/forgejo-parsing-duration 'nden gelen 3 değişiklikleri(commit'leri) forgejo ile birleştirmek istiyor AGit
Sahibi
  • Parse strict, if there's non-zero value it must be valid.
  • The new duration parser has more units.

Release notes

  • Features
    • PR: feat: better parsing of duration in config
- Parse strict, if there's non-zero value it must be valid. - The new duration parser has more units. <!--start release-notes-assistant--> ## Release notes <!--URL:https://codeberg.org/forgejo/forgejo--> - Features - [PR](https://codeberg.org/forgejo/forgejo/pulls/10273): <!--number 10273 --><!--line 0 --><!--description ZmVhdDogYmV0dGVyIHBhcnNpbmcgb2YgZHVyYXRpb24gaW4gY29uZmln-->feat: better parsing of duration in config<!--description--> <!--end release-notes-assistant-->
Üye
Where does that come from? The following is a preview of the release notes for this pull request, as they will appear in the upcoming release. They are derived from the content of the `release-notes/10273.md` file, if it exists, or the title of the pull request. They were also added at the bottom of the description of this pull request for easier reference.

This message and the release notes originate from a call to the release-notes-assistant.

@@ -1,2 +1,10 @@
 - Parse strict, if there's non-zero value it must be valid.
-- The new duration parser has more units.
\ No newline at end of file
+- The new duration parser has more units.
+
+<!--start release-notes-assistant-->
+
+## Release notes
+<!--URL:https://codeberg.org/forgejo/forgejo-->
+- Features
+  - [PR](https://codeberg.org/forgejo/forgejo/pulls/10273): <!--number 10273 --><!--line 0 --><!--description ZmVhdDogYmV0dGVyIHBhcnNpbmcgb2YgZHVyYXRpb24gaW4gY29uZmln-->feat: better parsing of duration in config<!--description-->
+<!--end release-notes-assistant-->

Release notes

  • Features
    • PR: feat: better parsing of duration in config
<details> <summary>Where does that come from?</summary> The following is a preview of the release notes for this pull request, as they will appear in the upcoming release. They are derived from the content of the `release-notes/10273.md` file, if it exists, or the title of the pull request. They were also added at the bottom of the description of this pull request for easier reference. This message and the release notes originate from a call to the [release-notes-assistant](https://code.forgejo.org/forgejo/release-notes-assistant). ```diff @@ -1,2 +1,10 @@ - Parse strict, if there's non-zero value it must be valid. -- The new duration parser has more units. \ No newline at end of file +- The new duration parser has more units. + +<!--start release-notes-assistant--> + +## Release notes +<!--URL:https://codeberg.org/forgejo/forgejo--> +- Features + - [PR](https://codeberg.org/forgejo/forgejo/pulls/10273): <!--number 10273 --><!--line 0 --><!--description ZmVhdDogYmV0dGVyIHBhcnNpbmcgb2YgZHVyYXRpb24gaW4gY29uZmln-->feat: better parsing of duration in config<!--description--> +<!--end release-notes-assistant--> ``` </details> <!--start release-notes-assistant--> ## Release notes <!--URL:https://codeberg.org/forgejo/forgejo--> - Features - [PR](https://codeberg.org/forgejo/forgejo/pulls/10273): <!--number 10273 --><!--line 0 --><!--description ZmVhdDogYmV0dGVyIHBhcnNpbmcgb2YgZHVyYXRpb24gaW4gY29uZmln-->feat: better parsing of duration in config<!--description--> <!--end release-notes-assistant-->
@ -0,0 +1,184 @@
// Copyright 2010 The Go Authors. All rights reserved.
// Copyright 2025 The Forgejo Authors. All rights reserved.
// SPDX-License-Identifier: BSD-3-Clause
Sahibi
Link to upstream so it's easier to follow https://cs.opensource.google/go/go/+/refs/tags/go1.25.4:src/time/format.go;l=1621
Gusted bu konuşmayı çözümlenmiş olarak işaretledi
@ -74,1 +74,3 @@
LFS.HTTPAuthExpiry = sec.Key("LFS_HTTP_AUTH_EXPIRY").MustDuration(24 * time.Hour)
LFS.HTTPAuthExpiry, err = sec.Key("LFS_HTTP_AUTH_EXPIRY").MustDuration(24 * time.Hour)
if err != nil {
return fmt.Errorf("could not parse duration for [server].LFS_HTTP_AUTH_EXPIRY: %w", err)
Sahibi

Is there a semantic difference between could not parse duration and Failed to parse duration? They seem like an inconsistency to me.

Is there a semantic difference between `could not parse duration` and `Failed to parse duration`? They seem like an inconsistency to me.
Yazar
Sahibi

Not really.

Not really.
0ko bu konuşmayı çözümlenmiş olarak işaretledi
@ -0,0 +73,4 @@
"h": uint64(time.Hour),
// Added, take a common definition.
"d": uint64(time.Hour * 24),
Sahibi

LOGIN_REMEMBER_DAYS could make use of this, but this can be scoped out.

...also USERNAME_COOLDOWN_PERIOD, [log] MAX_DAYS, [actions].ARTIFACT_RETENTION_DAYS, [actions].LOG_RETENTION_DAYS

`LOGIN_REMEMBER_DAYS` could make use of this, but this can be scoped out. ...also `USERNAME_COOLDOWN_PERIOD`, `[log] MAX_DAYS`, `[actions].ARTIFACT_RETENTION_DAYS`, `[actions].LOG_RETENTION_DAYS`
0ko bu konuşmayı çözümlenmiş olarak işaretledi
Sahibi

Have you considered attempting to upstream these changes, or you're expecting that Google will reply with "parsing d, w and returning error for invalid values is not in scope of this package"? Or making it an external package and importing it?

Have you considered attempting to upstream these changes, or you're expecting that Google will reply with "parsing `d`, `w` and returning error for invalid values is not in scope of this package"? Or making it an external package and importing it?
fnetX bir yorum yaptı

Thank you very much. I think this is great to allow admins to calculate longer values (mostly in days) without the need to convert it into and from hours.

What happens if a unit is not understood. Does it fail (my preferred behaviour) or silently fall back to the default value (current behaviour)?

Thank you very much. I think this is great to allow admins to calculate longer values (mostly in days) without the need to convert it into and from hours. What happens if a unit is not understood. Does it fail (my preferred behaviour) or silently fall back to the default value (current behaviour)?
@ -0,0 +75,4 @@
// Added, take a common definition.
"d": uint64(time.Hour * 24),
"w": uint64(time.Hour * 24 * 7),
"mo": uint64(time.Hour * 24 * 31),
Sahibi

Is this commonly used to configure software? I haven't encountered it yet. If it is used, is 31 the common unit?

I am used to configuring software in days or years, and if using days, mostly multiples of 30 (e.g. 30, 60, 90, 120, 180 days etc).

Is this commonly used to configure software? I haven't encountered it yet. If it is used, is 31 the common unit? I am used to configuring software in days or years, and if using days, mostly multiples of 30 (e.g. 30, 60, 90, 120, 180 days etc).
Katılımcı

I'm also not sure about the mo and y durations. If we just add the interpretations for days and weeks, users could use 4w as a rough equivalent for a month and either 365d or 52w for the year. Thinking further about it, the only useful addition (at least from my point of view) is the unit for days. Using days as the unit ensures no ambiguity when dealing with months.

For example, if someone expects to cleanup old stuff every month, 1mo could end up in a lot of confusion after February 28th. 30d on the other hand as a configuration value leaves much less room for interpretation.

I'm also not sure about the `mo` and `y` durations. If we just add the interpretations for days and weeks, users could use `4w` as a rough equivalent for a month and either `365d` or `52w` for the year. Thinking further about it, the only useful addition (at least from my point of view) is the unit for days. Using days as the unit ensures no ambiguity when dealing with months. For example, if someone expects to cleanup old stuff every month, `1mo` could end up in a lot of confusion after February 28th. `30d` on the other hand as a configuration value leaves much less room for interpretation.
Sahibi

I think years could make sense for configuring multi-year retention. E.g. clean up action logs and artifacts after 2 years, recorded activities after 3 years. Calculating multiple years in days is also very inconvenient.

I am not sure if any Forgejo admin ever configured it like this, though. The most important addition is probably days.

I think years could make sense for configuring multi-year retention. E.g. clean up action logs and artifacts after 2 years, recorded activities after 3 years. Calculating multiple years in days is also very inconvenient. I am not sure if any Forgejo admin ever configured it like this, though. The most important addition is probably days.
Yazar
Sahibi

I can drop month and week.

The PR is WIP because the documentation still has to be written that will clearly state that these are just shorthand for other durations and will not take into account any logic regarding dates.

I can drop month and week. The PR is WIP because the documentation still has to be written that will clearly state that these are just shorthand for other durations and will not take into account any logic regarding dates.
Gusted bu konuşmayı çözümlenmiş olarak işaretledi
Yazar
Sahibi

@0ko wrote in #10273 (yorum):

Have you considered attempting to upstream these changes, or you're expecting that Google will reply with "parsing d, w and returning error for invalid values is not in scope of this package"? Or making it an external package and importing it?

https://github.com/golang/go/issues/17767#issuecomment-258167205

@0ko wrote in https://codeberg.org/forgejo/forgejo/pulls/10273#issuecomment-8623950: > Have you considered attempting to upstream these changes, or you're expecting that Google will reply with "parsing `d`, `w` and returning error for invalid values is not in scope of this package"? Or making it an external package and importing it? https://github.com/golang/go/issues/17767#issuecomment-258167205
Sahibi

Well that was 9 years ago but another issue was closed just recently with same reasoning, so that clarifies it. What about an external package? Or developers who would like to reuse this could just import codeberg.org/forgejo/forgejo/duration if they want?

Well that was 9 years ago but [another issue](https://github.com/golang/go/issues/74813) was closed just recently with same reasoning, so that clarifies it. What about an external package? Or developers who would like to reuse this could just import `codeberg.org/forgejo/forgejo/duration` if they want?
Yazar
Sahibi

@0ko wrote in #10273 (yorum):

What about an external package? Or developers who would like to reuse this could just import codeberg.org/forgejo/forgejo/duration if they want?

Yes maybe, but given the small amount of code there's a proverb that applies here https://www.youtube.com/watch?v=PAAkCSZUG1c&t=9m28s. IIRC @fogti had a similar question regarding making the modules directory a importable package. I'm afraid this would be a larger discussion.

@0ko wrote in https://codeberg.org/forgejo/forgejo/pulls/10273#issuecomment-8625075: > What about an external package? Or developers who would like to reuse this could just import `codeberg.org/forgejo/forgejo/duration` if they want? Yes maybe, but given the small amount of code there's a proverb that applies here https://www.youtube.com/watch?v=PAAkCSZUG1c&t=9m28s. IIRC @fogti had a similar question regarding making the `modules` directory a importable package. I'm afraid this would be a larger discussion.
Gusted gusted/forgejo-parsing-duration e429d04d9a
Bazı kontroller başarısız oldu
issue-labels / backporting (pull_request_target) Has been skipped
issue-labels / cascade (pull_request_target) Has been skipped
testing / frontend-checks (pull_request) Successful in 1m0s
requirements / merge-conditions (pull_request) Successful in 1s
issue-labels / release-notes (pull_request_target) Successful in 31s
testing / backend-checks (pull_request) Failing after 2m32s
testing / test-unit (pull_request) Has been skipped
testing / test-e2e (pull_request) Has been skipped
testing / test-mysql (pull_request) Has been skipped
testing / test-pgsql (pull_request) Has been skipped
testing / test-sqlite (pull_request) Has been skipped
testing / test-remote-cacher (redis) (pull_request) Has been skipped
testing / test-remote-cacher (valkey) (pull_request) Has been skipped
testing / test-remote-cacher (garnet) (pull_request) Has been skipped
testing / test-remote-cacher (redict) (pull_request) Has been skipped
testing / security-check (pull_request) Has been skipped
hedefinden dd2a5820fb
Bazı kontroller başarısız oldu
requirements / merge-conditions (pull_request) Successful in 5s
issue-labels / release-notes (pull_request_target) Successful in 1m1s
testing / frontend-checks (pull_request) Successful in 2m3s
testing / backend-checks (pull_request) Failing after 4m46s
testing / test-unit (pull_request) Has been skipped
testing / test-e2e (pull_request) Has been skipped
testing / test-mysql (pull_request) Has been skipped
testing / test-pgsql (pull_request) Has been skipped
testing / test-sqlite (pull_request) Has been skipped
testing / test-remote-cacher (redis) (pull_request) Has been skipped
testing / test-remote-cacher (valkey) (pull_request) Has been skipped
testing / test-remote-cacher (garnet) (pull_request) Has been skipped
testing / test-remote-cacher (redict) (pull_request) Has been skipped
testing / security-check (pull_request) Has been skipped
hedefine zorla gönderildi 2025-12-01 16:50:23 +01:00
Karşılaştır
Gusted gusted/forgejo-parsing-duration dd2a5820fb
Bazı kontroller başarısız oldu
requirements / merge-conditions (pull_request) Successful in 5s
issue-labels / release-notes (pull_request_target) Successful in 1m1s
testing / frontend-checks (pull_request) Successful in 2m3s
testing / backend-checks (pull_request) Failing after 4m46s
testing / test-unit (pull_request) Has been skipped
testing / test-e2e (pull_request) Has been skipped
testing / test-mysql (pull_request) Has been skipped
testing / test-pgsql (pull_request) Has been skipped
testing / test-sqlite (pull_request) Has been skipped
testing / test-remote-cacher (redis) (pull_request) Has been skipped
testing / test-remote-cacher (valkey) (pull_request) Has been skipped
testing / test-remote-cacher (garnet) (pull_request) Has been skipped
testing / test-remote-cacher (redict) (pull_request) Has been skipped
testing / security-check (pull_request) Has been skipped
hedefinden ad591407bc
Bazı kontroller başarısız oldu
requirements / merge-conditions (pull_request) Successful in 2s
testing / frontend-checks (pull_request) Successful in 1m35s
testing / backend-checks (pull_request) Successful in 4m10s
issue-labels / release-notes (pull_request_target) Successful in 45s
testing / test-unit (pull_request) Successful in 7m10s
testing / test-remote-cacher (redis) (pull_request) Successful in 2m12s
testing / test-remote-cacher (valkey) (pull_request) Successful in 2m4s
testing / test-remote-cacher (garnet) (pull_request) Successful in 2m5s
testing / test-remote-cacher (redict) (pull_request) Successful in 1m49s
testing / test-e2e (pull_request) Failing after 19m34s
testing / test-mysql (pull_request) Successful in 27m30s
testing / test-sqlite (pull_request) Successful in 32m15s
testing / test-pgsql (pull_request) Successful in 37m49s
testing / security-check (pull_request) Successful in 1m11s
hedefine zorla gönderildi 2025-12-01 16:58:10 +01:00
Karşılaştır
Gusted gusted/forgejo-parsing-duration ad591407bc
Bazı kontroller başarısız oldu
requirements / merge-conditions (pull_request) Successful in 2s
testing / frontend-checks (pull_request) Successful in 1m35s
testing / backend-checks (pull_request) Successful in 4m10s
issue-labels / release-notes (pull_request_target) Successful in 45s
testing / test-unit (pull_request) Successful in 7m10s
testing / test-remote-cacher (redis) (pull_request) Successful in 2m12s
testing / test-remote-cacher (valkey) (pull_request) Successful in 2m4s
testing / test-remote-cacher (garnet) (pull_request) Successful in 2m5s
testing / test-remote-cacher (redict) (pull_request) Successful in 1m49s
testing / test-e2e (pull_request) Failing after 19m34s
testing / test-mysql (pull_request) Successful in 27m30s
testing / test-sqlite (pull_request) Successful in 32m15s
testing / test-pgsql (pull_request) Successful in 37m49s
testing / security-check (pull_request) Successful in 1m11s
hedefinden c8a22db9c6
Tüm denetlemeler başarılı oldu
requirements / merge-conditions (pull_request) Successful in 3s
issue-labels / release-notes (pull_request_target) Successful in 40s
testing / semgrep/ci (pull_request) Successful in 19s
testing / frontend-checks (pull_request) Successful in 1m59s
testing / backend-checks (pull_request) Successful in 7m20s
testing / test-unit (pull_request) Successful in 6m8s
testing / test-remote-cacher (redis) (pull_request) Successful in 2m25s
testing / test-remote-cacher (valkey) (pull_request) Successful in 2m35s
testing / test-remote-cacher (garnet) (pull_request) Successful in 2m39s
testing / test-remote-cacher (redict) (pull_request) Successful in 2m22s
testing / test-mysql (pull_request) Successful in 31m40s
testing / test-e2e (pull_request) Successful in 32m44s
testing / test-sqlite (pull_request) Successful in 37m41s
testing / test-pgsql (pull_request) Successful in 42m35s
testing / security-check (pull_request) Successful in 2m14s
hedefine zorla gönderildi 2026-04-01 03:45:07 +02:00
Karşılaştır
Üye

@Gusted can this pull request be considered ready for review and WIP: removed?

@Gusted can this pull request be considered ready for review and `WIP:` removed?
Yazar
Sahibi

@limiting-factor wrote in #10273 (yorum):

@Gusted can this pull request be considered ready for review and WIP: removed?

The PR is ready, but I hadn't got around to write the necessary documentation PR for it.

@limiting-factor wrote in https://codeberg.org/forgejo/forgejo/pulls/10273#issuecomment-15049845: > @Gusted can this pull request be considered ready for review and `WIP:` removed? The PR is ready, but I hadn't got around to write the necessary documentation PR for it.
Tüm denetlemeler başarılı oldu
requirements / merge-conditions (pull_request) Successful in 3s
issue-labels / release-notes (pull_request_target) Successful in 40s
testing / semgrep/ci (pull_request) Successful in 19s
testing / frontend-checks (pull_request) Successful in 1m59s
Gerekli
Ayrıntılar
testing / backend-checks (pull_request) Successful in 7m20s
Gerekli
Ayrıntılar
testing / test-unit (pull_request) Successful in 6m8s
Gerekli
Ayrıntılar
testing / test-remote-cacher (redis) (pull_request) Successful in 2m25s
testing / test-remote-cacher (valkey) (pull_request) Successful in 2m35s
testing / test-remote-cacher (garnet) (pull_request) Successful in 2m39s
testing / test-remote-cacher (redict) (pull_request) Successful in 2m22s
testing / test-mysql (pull_request) Successful in 31m40s
Gerekli
Ayrıntılar
testing / test-e2e (pull_request) Successful in 32m44s
testing / test-sqlite (pull_request) Successful in 37m41s
Gerekli
Ayrıntılar
testing / test-pgsql (pull_request) Successful in 42m35s
Gerekli
Ayrıntılar
testing / security-check (pull_request) Successful in 2m14s
Bu değişiklik isteğinde, hedef dalla çakışan değişiklikler var.
  • modules/setting/database.go
Komut satırı talimatlarını görüntüleyin.

Elle(manuel) birleştirme yardımcısı

Birleştirme işlemini kendiniz elle(manuel olarak) tamamlarken bu birleştirmenin değişiklik(commit) mesajını kullanın.

Çekme

Proje deponuzdan yeni bir dalı çekin ve değişiklikleri test edin.
git fetch -u origin +refs/pull/10273/head:gusted/forgejo-parsing-duration
git switch gusted/forgejo-parsing-duration
Bu konuşmaya katılmak için oturum aç.
Değerlendirici yok
Etiket Yok
arch
riscv64
backport/v1.19
backport/v1.20
backport/v1.21/forgejo
backport/v10.0/forgejo
backport/v11.0/forgejo
backport/v12.0/forgejo
backport/v13.0/forgejo
backport/v14.0/forgejo
backport/v15.0/forgejo
backport/v7.0/forgejo
backport/v8.0/forgejo
backport/v9.0/forgejo
breaking
bug
bug
confirmed
bug
duplicate
bug
needs-more-info
bug
new-report
bug
reported-upstream
code/actions
code/api
code/auth
code/auth/faidp
code/auth/farp
code/email
code/federation
code/git
code/migrations
code/packages
code/wiki
database
MySQL
database
PostgreSQL
database
SQLite
dependency-upgrade
dependency
Chi
dependency
Chroma
dependency
F3
dependency
ForgeFed
dependency
garage
dependency
Gitea
dependency
Golang
Discussion
duplicate
enhancement/feature
forgejo/accessibility
forgejo/branding
forgejo/ci
forgejo/commit-graph
forgejo/documentation
forgejo/furnace cleanup
forgejo/i18n
forgejo/interop
forgejo/moderation
forgejo/privacy
forgejo/release
forgejo/scaling
forgejo/security
forgejo/ui
Gain
High
Gain
Nice to have
Gain
Undefined
Gain
Very High
good first issue
i18n/backport-stable
impact
large
impact
medium
impact
small
impact
unknown
Incompatible license
issue
closed
issue
do-not-exist-yet
issue
open
manual test
Manually tested during feature freeze
OS
FreeBSD
OS
Linux
OS
macOS
OS
Windows
problem
QA
regression
release blocker
Release Cycle
Feature Freeze
release-blocker
v7.0
release-blocker
v7.0.1
release-blocker
v7.0.2
release-blocker
v7.0.3
release-blocker
v7.0.4
release-blocker
v8.0.0
release-blocker/v9.0.0
run-all-playwright-tests
run-end-to-end-tests
stage
2-research
stage
3-design
stage
4-implementation
test
manual
test
needed
test
needs-help
test
not-needed
test
present
untested
User research - time-tracker
valuable code
worth a release-note
User research - Accessibility
User research - Blocked
User research - Community
User research - Config (instance)
User research - Errors
User research - Filters
User research - Future backlog
User research - Git workflow
User research - Labels
User research - Moderation
User research - Needs input
User research - Notifications/Dashboard
User research - Rendering
User research - Repo creation
User research - Repo units
User research - Security
User research - Settings (in-app)
Kilometre Taşı Yok
Proje yok
Atanan Kişi Yok
6 katılımcı
Bildirimler
Bitiş Tarihi
Bitiş tarihi geçersiz veya aralık dışında. Lütfen 'yyyy-aa-gg' biçimini kullanın.

Bitiş tarihi atanmadı.

Bağımlılıklar

Bağımlılık yok.

Referans
forgejo/forgejo!10273
Herhangi bir açıklama sağlanmadı.