Skip to content

Commit 14c6bb4

Browse files
committed
change ToDuration to ParseDuration to be more consistent with the time pkg
1 parent 243d0b2 commit 14c6bb4

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

pkg/systemdtime/systemdtime.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,15 @@ func UnitToDuration(unit string) (time.Duration, error) {
5858
return 0, fmt.Errorf("Unit %s did not match", unit)
5959
}
6060

61-
// ToDuration converts a systemd relative time string into time.Duration
62-
func ToDuration(raw string) (time.Duration, error) {
61+
// ParseDuration converts a systemd relative time string into time.Duration
62+
func ParseDuration(raw string) (time.Duration, error) {
6363
re, err := regexp.Compile(`^\s*-?\s*(\d+\s*[a-z]+)`)
6464
if err != nil {
6565
return 0, err
6666
}
6767

6868
if !re.MatchString(raw) {
69-
return 0, fmt.Errorf("ToDuration: incorrect format for raw input %s", raw)
69+
return 0, fmt.Errorf("ParseDuration: incorrect format for raw input %s", raw)
7070
}
7171

7272
reNegative, err := regexp.Compile(`^\s*-.*`)
@@ -119,7 +119,7 @@ func ToDuration(raw string) (time.Duration, error) {
119119

120120
// AdjustTime takes a systemd time adjustment string and uses it to modify a time.Time
121121
func AdjustTime(original time.Time, adjustment string) (time.Time, error) {
122-
duration, err := ToDuration(adjustment)
122+
duration, err := ParseDuration(adjustment)
123123
if err != nil {
124124
return time.Time{}, err
125125
}

pkg/systemdtime/systemdtime_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ func TestToDuration(t *testing.T) {
112112
}
113113

114114
for input, output := range testInputs {
115-
duration, err := ToDuration(input)
115+
duration, err := ParseDuration(input)
116116
if err != nil {
117117
t.Errorf("%v", err)
118118
}

0 commit comments

Comments
 (0)