import transaction from GnuCash database
This commit is contained in:
@@ -11,6 +11,7 @@ import (
|
||||
const (
|
||||
longDateTimeFormat = "2006-01-02 15:04:05"
|
||||
longDateTimeWithTimezoneFormat = "2006-01-02 15:04:05Z07:00"
|
||||
longDateTimeWithTimezoneFormat2 = "2006-01-02 15:04:05 Z0700"
|
||||
longDateTimeWithoutSecondFormat = "2006-01-02 15:04"
|
||||
shortDateTimeFormat = "2006-1-2 15:4:5"
|
||||
yearMonthDateTimeFormat = "2006-01"
|
||||
@@ -141,6 +142,11 @@ func ParseFromLongDateTimeWithTimezone(t string) (time.Time, error) {
|
||||
return time.Parse(longDateTimeWithTimezoneFormat, t)
|
||||
}
|
||||
|
||||
// ParseFromLongDateTimeWithTimezone2 parses a formatted string in long date time format
|
||||
func ParseFromLongDateTimeWithTimezone2(t string) (time.Time, error) {
|
||||
return time.Parse(longDateTimeWithTimezoneFormat2, 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)
|
||||
|
||||
@@ -140,6 +140,15 @@ func TestParseFromLongDateTimeWithTimezone(t *testing.T) {
|
||||
assert.Equal(t, expectedValue, actualValue)
|
||||
}
|
||||
|
||||
func TestParseFromLongDateTimeWithTimezone2(t *testing.T) {
|
||||
expectedValue := int64(1617238883)
|
||||
actualTime, err := ParseFromLongDateTimeWithTimezone2("2021-04-01 06:01:23 +0500")
|
||||
assert.Equal(t, nil, err)
|
||||
|
||||
actualValue := actualTime.Unix()
|
||||
assert.Equal(t, expectedValue, actualValue)
|
||||
}
|
||||
|
||||
func TestParseFromLongDateTimeWithoutSecond(t *testing.T) {
|
||||
expectedValue := int64(1691947440)
|
||||
actualTime, err := ParseFromLongDateTimeWithoutSecond("2023-08-13 17:24", 0)
|
||||
|
||||
Reference in New Issue
Block a user