summaryrefslogtreecommitdiff
path: root/time.string.go
blob: b3aa166cb5932b7d53cbbfc8161ff10f0efb2e9d (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
package cobol

import (
	"errors"
	"strconv"
	"strings"
	"time"
)

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")
	}
	if len(parts) >= 2 {
		if len(parts[0]) == 10 && len(parts[1]) == 8 {
			// log.Info("GOT HERE also", BUILDTIME)
			const layout = "2006/01/02 15:04:05"
			t, err := time.ParseInLocation(layout, parts[0]+" "+parts[1], time.UTC)
			if err == nil {
				return &t, nil
			}

		}
	}
	return nil, NewFeature
}