summaryrefslogtreecommitdiff
path: root/internal/timestamp/timestamp.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/timestamp/timestamp.go')
-rw-r--r--internal/timestamp/timestamp.go41
1 files changed, 41 insertions, 0 deletions
diff --git a/internal/timestamp/timestamp.go b/internal/timestamp/timestamp.go
new file mode 100644
index 0000000..8c048df
--- /dev/null
+++ b/internal/timestamp/timestamp.go
@@ -0,0 +1,41 @@
+package timestamp
+
+import (
+ "strings"
+ "time"
+)
+
+const (
+ Format = "20060102-150405"
+)
+
+func Now() string {
+ return time.Now().Format(Format)
+}
+
+func NowTime() time.Time {
+ t, err := Parse(Now())
+ if err != nil {
+ panic(err)
+ }
+ return t
+}
+
+func Parse(timeStr string) (time.Time, error) {
+ return time.Parse(Format, timeStr)
+}
+func OldestValidTime() time.Time {
+ // The time this code was written a:round, actually.
+ oldestValidTime, err := Parse("20240912-102800")
+ if err != nil {
+ // Never expected
+ panic(err)
+ }
+ return oldestValidTime
+}
+
+func UpdateInFilename(filename string, rIndex int) string {
+ parts := strings.Split(filename, ".")
+ parts[len(parts)-rIndex] = Now()
+ return strings.Join(parts, "-")
+}