1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- package util
- import (
- "strconv"
- "strings"
- "time"
- )
- func GetNowTimeCustom() string {
- currentTime := time.Now()
- formattedTime := currentTime.Format("2006-01-02-15-04-05")
- return formattedTime
- }
- func BagTimeInInterval(bagTime string, begin string, end string) bool {
- compare1 := TimeCustom1GreaterEqualThanTimeCustom2(bagTime, begin)
- compare2 := TimeCustom1LessEqualThanTimeCustom2(bagTime, end)
- return compare1 && compare2
- }
- func TimeCustom1GreaterEqualThanTimeCustom2(timeCustom1 string, timeCustom2 string) bool {
- timeInt1, _ := strconv.Atoi(strings.Replace(timeCustom1, "-", "", -1))
- timeInt2, _ := strconv.Atoi(strings.Replace(timeCustom2, "-", "", -1))
- return timeInt1 >= timeInt2
- }
- func GetBagTime(bagName string) string {
- s1 := strings.Split(bagName, "_")[0]
- s1Split := strings.Split(s1, "/")
- s2 := s1Split[len(s1Split)-1]
- return s2
- }
- func TimeCustomChange(originalTimeStr string, number int) string {
- var newTimeStr string
- layout := "2006-01-02-15-04-05"
- originalTime, err := time.Parse(layout, originalTimeStr)
- if err != nil {
- return newTimeStr
- }
- newTime := originalTime.Add(time.Duration(number) * time.Second)
- return newTime.Format(layout)
- }
- func CalculateDifferenceOfTimeCustom(timeCustom1 string, timeCustom2 string) int {
- timeInt1, _ := strconv.Atoi(strings.Replace(timeCustom1, "-", "", -1))
- timeInt2, _ := strconv.Atoi(strings.Replace(timeCustom2, "-", "", -1))
- return timeInt2 - timeInt1 + 1
- }
- func TimeCustom1GreaterTimeCustom2(timeCustom1 string, timeCustom2 string) bool {
- timeInt1, _ := strconv.Atoi(strings.Replace(timeCustom1, "-", "", -1))
- timeInt2, _ := strconv.Atoi(strings.Replace(timeCustom2, "-", "", -1))
- return timeInt1 > timeInt2
- }
- func TimeCustom1LessEqualThanTimeCustom2(timeCustom1 string, timeCustom2 string) bool {
- timeInt1, _ := strconv.Atoi(strings.Replace(timeCustom1, "-", "", -1))
- timeInt2, _ := strconv.Atoi(strings.Replace(timeCustom2, "-", "", -1))
- return timeInt1 <= timeInt2
- }
- func GetTimeString(sourceTime time.Time) string {
- return sourceTime.Format("2006-01-02 15:04:05")
- }
|