diff options
| author | Jeff Carr <[email protected]> | 2025-10-26 09:34:48 -0500 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2025-10-26 09:34:48 -0500 |
| commit | 6420336fb6208b7d4b3c40b7b215e38ad8b7f76c (patch) | |
| tree | 7ff6cf1f6dbccdb6dbe283d385c0a353ac1e225e | |
| parent | 8e670f4d97327b06563af3a38296e63be10e934f (diff) | |
find more stringsv0.0.31
| -rw-r--r-- | time.string.go | 50 |
1 files changed, 38 insertions, 12 deletions
diff --git a/time.string.go b/time.string.go index 0aa2714..bfa0007 100644 --- a/time.string.go +++ b/time.string.go @@ -26,17 +26,7 @@ import ( func doTimeString(BUILDTIME string) (*time.Time, error) { parts := strings.Split(BUILDTIME, " ") if len(parts) == 1 { - // The input epoch seconds - // epochSeconds := int64(1758646486) - num, err := strconv.Atoi(BUILDTIME) - if err != nil { - return nil, err - } - epochSeconds := int64(num) - // Convert the epoch seconds to a time.Time object. - // time.Unix() creates the time in the UTC timezone by default. - t := time.Unix(epochSeconds, 0) - return &t, errors.New("treated string as seconds") + return doTimeSingleString(parts[0]) } if len(parts) >= 2 { if len(parts[0]) == 10 && len(parts[1]) == 8 { @@ -50,10 +40,46 @@ func doTimeString(BUILDTIME string) (*time.Time, error) { } } // try lots of common stuff - const layout = "2025-10-19 11:47:48 -0500 CDT" + const layout = "2006-01-02 15:04:05 -0500 CDT" t, err := time.ParseInLocation(layout, parts[0]+" "+parts[1], time.UTC) if err == nil { return &t, nil } return nil, NewFeature } + +// string is a single string with no spaces +func doTimeSingleString(BUILDTIME string) (*time.Time, error) { + // The input epoch seconds + // epochSeconds := int64(1758646486) + num, err := strconv.Atoi(BUILDTIME) + if err == nil { + epochSeconds := int64(num) + // Convert the epoch seconds to a time.Time object. + // time.Unix() creates the time in the UTC timezone by default. + t := time.Unix(epochSeconds, 0) + return &t, errors.New("treated string as seconds") + } + { + const layout = "2006.01.02" + t, err := time.ParseInLocation(layout, BUILDTIME, time.UTC) + if err == nil { + return &t, nil + } + } + + { + const layout = "2006-01-02" + t, err := time.ParseInLocation(layout, BUILDTIME, time.UTC) + if err == nil { + return &t, nil + } + } + + const layout = "2006/01/02" + t, err := time.ParseInLocation(layout, BUILDTIME, time.UTC) + if err == nil { + return &t, nil + } + return nil, err +} |
