mirror of
https://gitea.com/gitea/tea.git
synced 2026-10-26 11:01:25 +01:00
feat: accept days and weeks in --since and --until
tea issue list --since 7d was rejected; only h, m and s durations worked. Time bounds such as --since, --until and --before now also take whole days and weeks: 7d, 2w. Signed-off-by: bircni <bircni@icloud.com>
This commit is contained in:
2 files changed
+18
-2
No files matched your search
+15
-1
@@ -113,7 +113,7 @@ func (f positiveInt) Set(raw string) error {
|
||||
}
|
||||
|
||||
func parseRunTime(value string, now time.Time) (*time.Time, error) {
|
||||
if duration, err := time.ParseDuration(value); err == nil {
|
||||
if duration, err := durationAgo(value); err == nil {
|
||||
if duration < 0 {
|
||||
return nil, errors.New("relative duration cannot be negative")
|
||||
}
|
||||
@@ -128,6 +128,20 @@ func parseRunTime(value string, now time.Time) (*time.Time, error) {
|
||||
return nil, errors.New("use a date, RFC3339 timestamp, or duration such as 24h")
|
||||
}
|
||||
|
||||
// durationAgo parses a duration like time.ParseDuration, and also whole days and weeks: 7d, 2w.
|
||||
func durationAgo(value string) (time.Duration, error) {
|
||||
for unit, size := range map[string]time.Duration{"d": 24 * time.Hour, "w": 7 * 24 * time.Hour} {
|
||||
if count, ok := strings.CutSuffix(value, unit); ok {
|
||||
n, err := strconv.Atoi(count)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return time.Duration(n) * size, nil
|
||||
}
|
||||
}
|
||||
return time.ParseDuration(value)
|
||||
}
|
||||
|
||||
// timeRange is a pair of lower and upper time bound flags.
|
||||
type timeRange struct {
|
||||
flags *pflag.FlagSet
|
||||
|
||||
Reference in new issue
Block a user