refactor: move parsing into internal/parse module, move other functions into misc

This commit is contained in:
2025-08-01 16:39:03 -05:00
parent 378bc29e7e
commit 55a390e69c
8 changed files with 44 additions and 33 deletions

30
internal/parse/main.go Normal file
View File

@@ -0,0 +1,30 @@
package parse
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
}