diff options
| author | Jeff Carr <[email protected]> | 2025-10-12 03:33:53 -0500 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2025-10-12 03:33:53 -0500 |
| commit | 3db85febbf02380bc5c38abd660668f1ef53a9c8 (patch) | |
| tree | 3f4c498847f71f2ed423cec47aa11c520d95d270 /version.go | |
| parent | 36f7422d2fc62e5d84726633b2bb9ca07b75b555 (diff) | |
finally a standard place for time.Time() formatting
Diffstat (limited to 'version.go')
| -rw-r--r-- | version.go | 71 |
1 files changed, 3 insertions, 68 deletions
@@ -5,11 +5,8 @@ package prep import ( "fmt" "os" - "strconv" - "strings" - "time" - "go.wit.com/lib/config" + "go.wit.com/lib/cobol" "go.wit.com/log" ) @@ -28,71 +25,9 @@ func (pb *Auto) getVersion() string { } BUILDTIME, VERSION := myAuto.buildtime() - parts := strings.Split(BUILDTIME, ".") - if len(parts) == 1 { - // The input epoch seconds - // epochSeconds := int64(1758646486) - num, err := strconv.Atoi(BUILDTIME) - epochSeconds := int64(num) - if err == nil { - - // 1. 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) - - // 2. Convert the UTC time to the computer's local timezone. - localTime := t.Local() - - // 3. Print the result. The default format is clear and includes the timezone. - // fmt.Println("Default format:", localTime) - // For a more human-friendly format, use the Format() method. - // Go uses a special reference time for formatting: Mon Jan 2 15:04:05 2006 MST - // You lay out your desired format using these specific numbers. - // formattedString := localTime.Format("Monday, January 2, 2006 at 3:04:05 PM (MST)") - // fmt.Println(" Custom format:", formattedString) - - // now := time.Now() - // dur := time.Since(localTime) - // BUILDTIME = fmt.Sprintf("%s age(%v)", localTime.String(), , config.FormatDuration(time.Since(localTime))) - stamp := log.Sprintf("Built %s Age(%s)", localTime.Format("2006-01-02 15:04"), config.FormatDuration(time.Since(localTime))) - return fmt.Sprintf("%s %s %s", pb.Argname, VERSION, stamp) - } - } - - return fmt.Sprintf("%s %s Built on %s", pb.Argname, VERSION, BUILDTIME) + return fmt.Sprintf("%s %s Built on %s", pb.Argname, VERSION, cobol.Time(BUILDTIME)) } func StandardVersion(ARGNAME, VERSION, BUILDTIME string) string { - parts := strings.Split(BUILDTIME, ".") - if len(parts) == 1 { - // The input epoch seconds - // epochSeconds := int64(1758646486) - num, err := strconv.Atoi(BUILDTIME) - epochSeconds := int64(num) - if err == nil { - - // 1. 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) - - // 2. Convert the UTC time to the computer's local timezone. - localTime := t.Local() - - // 3. Print the result. The default format is clear and includes the timezone. - // fmt.Println("Default format:", localTime) - // For a more human-friendly format, use the Format() method. - // Go uses a special reference time for formatting: Mon Jan 2 15:04:05 2006 MST - // You lay out your desired format using these specific numbers. - // formattedString := localTime.Format("Monday, January 2, 2006 at 3:04:05 PM (MST)") - // fmt.Println(" Custom format:", formattedString) - - // now := time.Now() - // dur := time.Since(localTime) - // BUILDTIME = fmt.Sprintf("%s age(%v)", localTime.String(), , config.FormatDuration(time.Since(localTime))) - stamp := log.Sprintf("Built %s Age(%s)", localTime.Format("2006-01-02 15:04"), config.FormatDuration(time.Since(localTime))) - return fmt.Sprintf("%s %s %s", ARGNAME, VERSION, stamp) - } - } - - return fmt.Sprintf("%s %s Built on %s", ARGNAME, VERSION, BUILDTIME) + return fmt.Sprintf("%s %s Built on %s", ARGNAME, VERSION, cobol.Time(BUILDTIME)) } |
