Skip to content

Commit

Permalink
'from' should be relative to 'to'
Browse files Browse the repository at this point in the history
  • Loading branch information
mgjules committed Jun 16, 2021
1 parent 4b142ad commit c59357d
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions cmd/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,20 +127,6 @@ var Backup = &cli.Command{

currentTime := time.Now()

from, err := now.Parse(c.String("from"))
if err != nil {
sugar.Debugw("parse 'from' as time.Time. parsing as duration...", "error", err, "from", c.String("from"))
// try parsing as duration
fromDur, err := str2duration.ParseDuration(c.String("from"))
if err != nil {
sugar.Debugw("parse 'from' as time.Duration. using default...", "error", err, "from", c.String("from"))
// default to 1 hour ago
from = currentTime.Add(-1 * time.Hour)
} else {
from = currentTime.Add(-fromDur)
}
}

to, err := now.Parse(c.String("to"))
if err != nil {
sugar.Debugw("parse 'to' as time.Time. parsing as duration...", "error", err, "to", c.String("to"))
Expand All @@ -155,6 +141,20 @@ var Backup = &cli.Command{
}
}

from, err := now.Parse(c.String("from"))
if err != nil {
sugar.Debugw("parse 'from' as time.Time. parsing as duration...", "error", err, "from", c.String("from"))
// try parsing as duration
fromDur, err := str2duration.ParseDuration(c.String("from"))
if err != nil {
sugar.Debugw("parse 'from' as time.Duration. using default...", "error", err, "from", c.String("from"))
// default to 1 hour ago relative to 'to'
from = to.Add(-1 * time.Hour)
} else {
from = to.Add(-fromDur)
}
}

sugar.Infow("time interval", "from", from.Format(queryTimeFormat), "to", to.Format(queryTimeFormat))

if from.After(to) {
Expand Down

0 comments on commit c59357d

Please sign in to comment.