summaryrefslogtreecommitdiff
path: root/version.go
blob: 0b5455ea24af7c248e2845b86327c5921fd8cff6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package prep

// initializes logging and command line options

import (
	"fmt"
	"os"
	"strconv"
	"strings"
	"time"

	"go.wit.com/lib/config"
	"go.wit.com/log"
)

func (pb *Auto) Version() string {
	return pb.getVersion()
}

func doVersion(pb *Auto) {
	log.Info(pb.getVersion())
	os.Exit(0)
}

func (pb *Auto) getVersion() string {
	if myAuto.buildtime == nil {
		return "app doesn't have argv.BuildVersion()"
	}
	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)
}

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)
}