code refactor

This commit is contained in:
MaysWind
2025-07-06 15:50:53 +08:00
parent a54275d307
commit 82b98eca95
9 changed files with 239 additions and 191 deletions
+9 -4
View File
@@ -13,7 +13,7 @@ const (
longDateTimeFormat = "2006-01-02 15:04:05"
longDateTimeWithTimezoneFormat = "2006-01-02 15:04:05Z07:00"
longDateTimeWithTimezoneFormat2 = "2006-01-02 15:04:05 Z0700"
longDateTimeWithTimezoneRFC3389Format = "2006-01-02T15:04:05Z07:00"
longDateTimeWithTimezoneRFC3339Format = "2006-01-02T15:04:05Z07:00"
longDateTimeWithoutSecondFormat = "2006-01-02 15:04"
shortDateTimeFormat = "2006-1-2 15:4:5"
yearMonthDateTimeFormat = "2006-01"
@@ -77,15 +77,15 @@ func FormatUnixTimeToLongDateTimeWithTimezone(unixTime int64, timezone *time.Loc
return t.Format(longDateTimeWithTimezoneFormat)
}
// FormatUnixTimeToLongDateTimeWithTimezoneRFC3389Format returns a textual representation of the unix time formatted by long date time with timezone RFC 3389 format
func FormatUnixTimeToLongDateTimeWithTimezoneRFC3389Format(unixTime int64, timezone *time.Location) string {
// FormatUnixTimeToLongDateTimeWithTimezoneRFC3339Format returns a textual representation of the unix time formatted by long date time with timezone RFC 3339 format
func FormatUnixTimeToLongDateTimeWithTimezoneRFC3339Format(unixTime int64, timezone *time.Location) string {
t := parseFromUnixTime(unixTime)
if timezone != nil {
t = t.In(timezone)
}
return t.Format(longDateTimeWithTimezoneRFC3389Format)
return t.Format(longDateTimeWithTimezoneRFC3339Format)
}
func FormatYearMonthDayToLongDateTime(year string, month string, day string) (string, error) {
@@ -229,6 +229,11 @@ func ParseFromLongDateTimeWithTimezone2(t string) (time.Time, error) {
return time.Parse(longDateTimeWithTimezoneFormat2, t)
}
// ParseFromLongDateTimeWithTimezoneRFC3339Format parses a formatted string in long date time RFC 3378 format
func ParseFromLongDateTimeWithTimezoneRFC3339Format(t string) (time.Time, error) {
return time.Parse(longDateTimeWithTimezoneRFC3339Format, t)
}
// ParseFromLongDateTimeWithoutSecond parses a formatted string in long date time format (no second)
func ParseFromLongDateTimeWithoutSecond(t string, utcOffset int16) (time.Time, error) {
timezone := time.FixedZone("Timezone", int(utcOffset)*60)