|
@@ -7,12 +7,22 @@ import (
|
|
|
"time"
|
|
|
)
|
|
|
|
|
|
+var customLayout = "2006-01-02-15-04-05"
|
|
|
+
|
|
|
func GetNowTimeCustom() string {
|
|
|
currentTime := time.Now()
|
|
|
- formattedTime := currentTime.Format("2006-01-02-15-04-05")
|
|
|
+ formattedTime := currentTime.Format(customLayout)
|
|
|
return formattedTime
|
|
|
}
|
|
|
|
|
|
+func GetTimeCustom(sourceTime time.Time) string {
|
|
|
+ var defaultTime = time.Date(2006, time.January, 2, 15, 4, 5, 0, time.Local)
|
|
|
+ if sourceTime.Equal(defaultTime) {
|
|
|
+ return ""
|
|
|
+ }
|
|
|
+ return sourceTime.Format(customLayout)
|
|
|
+}
|
|
|
+
|
|
|
func BagTimeInInterval(bagTime string, begin string, end string) bool {
|
|
|
compare1 := TimeCustom1GreaterEqualThanTimeCustom2(bagTime, begin)
|
|
|
compare2 := TimeCustom1LessEqualThanTimeCustom2(bagTime, end)
|
|
@@ -32,13 +42,12 @@ func GetBagTime(bagName string) string {
|
|
|
}
|
|
|
func TimeCustomChange(originalTimeStr string, number int) string {
|
|
|
var newTimeStr string
|
|
|
- layout := "2006-01-02-15-04-05"
|
|
|
- originalTime, err := time.Parse(layout, originalTimeStr)
|
|
|
+ originalTime, err := time.Parse(customLayout, originalTimeStr)
|
|
|
if err != nil {
|
|
|
return newTimeStr
|
|
|
}
|
|
|
newTime := originalTime.Add(time.Duration(number) * time.Second)
|
|
|
- return newTime.Format(layout)
|
|
|
+ return newTime.Format(customLayout)
|
|
|
}
|
|
|
func CalculateDifferenceOfTimeCustom(timeCustom1 string, timeCustom2 string) int {
|
|
|
timeInt1, _ := strconv.Atoi(strings.Replace(timeCustom1, "-", "", -1))
|
|
@@ -63,7 +72,7 @@ func GetTimeString(sourceTime time.Time) string {
|
|
|
if sourceTime.Equal(defaultTime) {
|
|
|
return ""
|
|
|
}
|
|
|
- return sourceTime.Format("2006-01-02 15:04:05")
|
|
|
+ return sourceTime.Format(customLayout)
|
|
|
}
|
|
|
|
|
|
func AnyToTime(value any) (time.Time, error) {
|