add seconds to time column in exported data
This commit is contained in:
@@ -40,6 +40,17 @@ func ParseNumericYearMonth(yearMonth string) (int32, int32, error) {
|
||||
return year, month, nil
|
||||
}
|
||||
|
||||
// FormatUnixTimeToLongDateTime returns a textual representation of the unix time formatted by long date time format
|
||||
func FormatUnixTimeToLongDateTime(unixTime int64, timezone *time.Location) string {
|
||||
t := parseFromUnixTime(unixTime)
|
||||
|
||||
if timezone != nil {
|
||||
t = t.In(timezone)
|
||||
}
|
||||
|
||||
return t.Format(longDateTimeFormat)
|
||||
}
|
||||
|
||||
// FormatUnixTimeToLongDateTimeInServerTimezone returns a textual representation of the unix time formatted by long date time format
|
||||
func FormatUnixTimeToLongDateTimeInServerTimezone(unixTime int64) string {
|
||||
return parseFromUnixTime(unixTime).Format(longDateTimeFormat)
|
||||
|
||||
@@ -16,6 +16,20 @@ func TestParseNumericYearMonth(t *testing.T) {
|
||||
assert.Equal(t, expectedMonth, actualMonth)
|
||||
}
|
||||
|
||||
func TestFormatUnixTimeToLongDateTime(t *testing.T) {
|
||||
unixTime := int64(1617228083)
|
||||
utcTimezone := time.FixedZone("Test Timezone", 0) // UTC
|
||||
utc8Timezone := time.FixedZone("Test Timezone", 28800) // UTC+8
|
||||
|
||||
expectedValue := "2021-03-31 22:01:23"
|
||||
actualValue := FormatUnixTimeToLongDateTime(unixTime, utcTimezone)
|
||||
assert.Equal(t, expectedValue, actualValue)
|
||||
|
||||
expectedValue = "2021-04-01 06:01:23"
|
||||
actualValue = FormatUnixTimeToLongDateTime(unixTime, utc8Timezone)
|
||||
assert.Equal(t, expectedValue, actualValue)
|
||||
}
|
||||
|
||||
func TestFormatUnixTimeToLongDateTimeWithoutSecond(t *testing.T) {
|
||||
unixTime := int64(1617228083)
|
||||
utcTimezone := time.FixedZone("Test Timezone", 0) // UTC
|
||||
|
||||
Reference in New Issue
Block a user