refactor: move 'parse' back to internal root

This commit is contained in:
2025-08-01 18:18:16 -05:00
parent 26b8892ff6
commit d51f6d5946
7 changed files with 12 additions and 18 deletions

30
internal/parse.go Normal file
View File

@@ -0,0 +1,30 @@
package internal
import (
"fmt"
"log/slog"
"time"
"github.com/golang-module/carbon"
)
// Parses a HH:MM string.
func ParseTime(s string) carbon.Carbon {
t, err := time.Parse("15:04", s)
if err != nil {
parsingErr := fmt.Errorf("failed to parse time string \"%s\"; format must be HH:MM.: %w", s, err)
slog.Error(parsingErr.Error())
panic(parsingErr)
}
return carbon.Now().SetTimeMilli(t.Hour(), t.Minute(), 0, 0)
}
func ParseDuration(s string) time.Duration {
d, err := time.ParseDuration(s)
if err != nil {
parsingErr := fmt.Errorf("couldn't parse string duration: \"%s\" see https://pkg.go.dev/time#ParseDuration for valid time units: %w", s, err)
slog.Error(parsingErr.Error())
panic(parsingErr)
}
return d
}