import transaction from qif file
This commit is contained in:
@@ -140,6 +140,9 @@ func ParseAmount(amount string) (int64, error) {
|
||||
if amount[0] == '-' {
|
||||
amount = amount[1:]
|
||||
sign = -1
|
||||
} else if amount[0] == '+' {
|
||||
amount = amount[1:]
|
||||
sign = 1
|
||||
}
|
||||
|
||||
if len(amount) < 1 {
|
||||
|
||||
@@ -278,6 +278,21 @@ func TestParseAmount(t *testing.T) {
|
||||
actualValue, err = ParseAmount("-12.34")
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, expectedValue, actualValue)
|
||||
|
||||
expectedValue = int64(0)
|
||||
actualValue, err = ParseAmount("+0")
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, expectedValue, actualValue)
|
||||
|
||||
expectedValue = int64(12)
|
||||
actualValue, err = ParseAmount("+0.12")
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, expectedValue, actualValue)
|
||||
|
||||
expectedValue = int64(1234)
|
||||
actualValue, err = ParseAmount("+12.34")
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, expectedValue, actualValue)
|
||||
}
|
||||
|
||||
func TestParseAmount_InvalidAmount(t *testing.T) {
|
||||
|
||||
+24
-6
@@ -3,12 +3,15 @@ package utils
|
||||
import "regexp"
|
||||
|
||||
var (
|
||||
usernamePattern = regexp.MustCompile("^(?i)[a-z0-9_-]+$")
|
||||
emailPattern = regexp.MustCompile("^(?i)(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|\"(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21\\x23-\\x5b\\x5d-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])*\")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21-\\x5a\\x53-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])+)\\])$")
|
||||
hexRGBColorPattern = regexp.MustCompile("^(?i)([0-9a-f]{6}|[0-9a-f]{3})$")
|
||||
longDateTimePattern = regexp.MustCompile("^([1-9][0-9]{3})-(0[1-9]|1[0-2])-(0[1-9]|1[0-9]|2[0-9]|3[01]) ([0-1][0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9])$")
|
||||
longDateTimeWithoutSecondPattern = regexp.MustCompile("^([1-9][0-9]{3})-(0[1-9]|1[0-2])-(0[1-9]|1[0-9]|2[0-9]|3[01]) ([0-1][0-9]|2[0-3]):([0-5][0-9])$")
|
||||
longDatePattern = regexp.MustCompile("^([1-9][0-9]{3})-(0[1-9]|1[0-2])-(0[1-9]|1[0-9]|2[0-9]|3[01])$")
|
||||
usernamePattern = regexp.MustCompile("^(?i)[a-z0-9_-]+$")
|
||||
emailPattern = regexp.MustCompile("^(?i)(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|\"(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21\\x23-\\x5b\\x5d-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])*\")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21-\\x5a\\x53-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])+)\\])$")
|
||||
hexRGBColorPattern = regexp.MustCompile("^(?i)([0-9a-f]{6}|[0-9a-f]{3})$")
|
||||
longDateTimePattern = regexp.MustCompile("^([1-9][0-9]{3})-(0[1-9]|1[0-2])-(0[1-9]|1[0-9]|2[0-9]|3[01]) ([0-1][0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9])$")
|
||||
longDateTimeWithoutSecondPattern = regexp.MustCompile("^([1-9][0-9]{3})-(0[1-9]|1[0-2])-(0[1-9]|1[0-9]|2[0-9]|3[01]) ([0-1][0-9]|2[0-3]):([0-5][0-9])$")
|
||||
longDatePattern = regexp.MustCompile("^([1-9][0-9]{3})-(0[1-9]|1[0-2])-(0[1-9]|1[0-9]|2[0-9]|3[01])$")
|
||||
longOrShortYearMonthDayDatePattern = regexp.MustCompile("^([1-9][0-9]{3})[-/.']([1-9]|0[1-9]|1[0-2])[-/.']([1-9]|0[1-9]|1[0-9]|2[0-9]|3[01])$")
|
||||
longOrShortMonthDayYearDatePattern = regexp.MustCompile("^([1-9]|0[1-9]|1[0-2])[-/.']([1-9]|0[1-9]|1[0-9]|2[0-9]|3[01])[-/.']([1-9][0-9]{3})$")
|
||||
longOrShortDayMonthYearDatePattern = regexp.MustCompile("^([1-9]|0[1-9]|1[0-9]|2[0-9]|3[01])[-/.']([1-9]|0[1-9]|1[0-2])[-/.']([1-9][0-9]{3})$")
|
||||
)
|
||||
|
||||
// IsValidUsername reports whether username is valid
|
||||
@@ -40,3 +43,18 @@ func IsValidLongDateTimeWithoutSecondFormat(datetime string) bool {
|
||||
func IsValidLongDateFormat(date string) bool {
|
||||
return longDatePattern.MatchString(date)
|
||||
}
|
||||
|
||||
// IsValidYearMonthDayLongOrShortDateFormat reports long date is valid format
|
||||
func IsValidYearMonthDayLongOrShortDateFormat(date string) bool {
|
||||
return longOrShortYearMonthDayDatePattern.MatchString(date)
|
||||
}
|
||||
|
||||
// IsValidMonthDayYearLongOrShortDateFormat reports long date is valid format
|
||||
func IsValidMonthDayYearLongOrShortDateFormat(date string) bool {
|
||||
return longOrShortMonthDayYearDatePattern.MatchString(date)
|
||||
}
|
||||
|
||||
// IsValidDayMonthYearLongOrShortDateFormat reports long date is valid format
|
||||
func IsValidDayMonthYearLongOrShortDateFormat(date string) bool {
|
||||
return longOrShortDayMonthYearDatePattern.MatchString(date)
|
||||
}
|
||||
|
||||
@@ -229,3 +229,129 @@ func TestIsValidLongDateFormat_InvalidLongDateFormat(t *testing.T) {
|
||||
actualValue = IsValidLongDateFormat(datetime)
|
||||
assert.Equal(t, expectedValue, actualValue)
|
||||
}
|
||||
|
||||
func TestIsValidYearMonthDayLongOrShortDateFormat_ValidFormat(t *testing.T) {
|
||||
datetime := "2024-09-01"
|
||||
expectedValue := true
|
||||
actualValue := IsValidYearMonthDayLongOrShortDateFormat(datetime)
|
||||
assert.Equal(t, expectedValue, actualValue)
|
||||
|
||||
datetime = "2024-09-1"
|
||||
expectedValue = true
|
||||
actualValue = IsValidYearMonthDayLongOrShortDateFormat(datetime)
|
||||
assert.Equal(t, expectedValue, actualValue)
|
||||
|
||||
datetime = "2024-9-01"
|
||||
expectedValue = true
|
||||
actualValue = IsValidYearMonthDayLongOrShortDateFormat(datetime)
|
||||
assert.Equal(t, expectedValue, actualValue)
|
||||
|
||||
datetime = "2024-9-1"
|
||||
expectedValue = true
|
||||
actualValue = IsValidYearMonthDayLongOrShortDateFormat(datetime)
|
||||
assert.Equal(t, expectedValue, actualValue)
|
||||
|
||||
datetime = "9999-12-31"
|
||||
expectedValue = true
|
||||
actualValue = IsValidYearMonthDayLongOrShortDateFormat(datetime)
|
||||
assert.Equal(t, expectedValue, actualValue)
|
||||
|
||||
datetime = "2024/09/01"
|
||||
expectedValue = true
|
||||
actualValue = IsValidYearMonthDayLongOrShortDateFormat(datetime)
|
||||
assert.Equal(t, expectedValue, actualValue)
|
||||
|
||||
datetime = "2024.09.01"
|
||||
expectedValue = true
|
||||
actualValue = IsValidYearMonthDayLongOrShortDateFormat(datetime)
|
||||
assert.Equal(t, expectedValue, actualValue)
|
||||
|
||||
datetime = "2024'09.01"
|
||||
expectedValue = true
|
||||
actualValue = IsValidYearMonthDayLongOrShortDateFormat(datetime)
|
||||
assert.Equal(t, expectedValue, actualValue)
|
||||
}
|
||||
|
||||
func TestIsValidMonthDayYearLongOrShortDateFormat_ValidFormat(t *testing.T) {
|
||||
datetime := "09-01-2024"
|
||||
expectedValue := true
|
||||
actualValue := IsValidMonthDayYearLongOrShortDateFormat(datetime)
|
||||
assert.Equal(t, expectedValue, actualValue)
|
||||
|
||||
datetime = "09-1-2024"
|
||||
expectedValue = true
|
||||
actualValue = IsValidMonthDayYearLongOrShortDateFormat(datetime)
|
||||
assert.Equal(t, expectedValue, actualValue)
|
||||
|
||||
datetime = "9-01-2024"
|
||||
expectedValue = true
|
||||
actualValue = IsValidMonthDayYearLongOrShortDateFormat(datetime)
|
||||
assert.Equal(t, expectedValue, actualValue)
|
||||
|
||||
datetime = "9-1-2024"
|
||||
expectedValue = true
|
||||
actualValue = IsValidMonthDayYearLongOrShortDateFormat(datetime)
|
||||
assert.Equal(t, expectedValue, actualValue)
|
||||
|
||||
datetime = "12-31-9999"
|
||||
expectedValue = true
|
||||
actualValue = IsValidMonthDayYearLongOrShortDateFormat(datetime)
|
||||
assert.Equal(t, expectedValue, actualValue)
|
||||
|
||||
datetime = "09/01/2024"
|
||||
expectedValue = true
|
||||
actualValue = IsValidMonthDayYearLongOrShortDateFormat(datetime)
|
||||
assert.Equal(t, expectedValue, actualValue)
|
||||
|
||||
datetime = "09.01.2024"
|
||||
expectedValue = true
|
||||
actualValue = IsValidMonthDayYearLongOrShortDateFormat(datetime)
|
||||
assert.Equal(t, expectedValue, actualValue)
|
||||
|
||||
datetime = "09/01'2024"
|
||||
expectedValue = true
|
||||
actualValue = IsValidMonthDayYearLongOrShortDateFormat(datetime)
|
||||
assert.Equal(t, expectedValue, actualValue)
|
||||
}
|
||||
|
||||
func TestIsValidDayMonthYearLongDateFormat_ValidLongDateFormat(t *testing.T) {
|
||||
datetime := "01-09-2024"
|
||||
expectedValue := true
|
||||
actualValue := IsValidDayMonthYearLongOrShortDateFormat(datetime)
|
||||
assert.Equal(t, expectedValue, actualValue)
|
||||
|
||||
datetime = "1-09-2024"
|
||||
expectedValue = true
|
||||
actualValue = IsValidDayMonthYearLongOrShortDateFormat(datetime)
|
||||
assert.Equal(t, expectedValue, actualValue)
|
||||
|
||||
datetime = "01-9-2024"
|
||||
expectedValue = true
|
||||
actualValue = IsValidDayMonthYearLongOrShortDateFormat(datetime)
|
||||
assert.Equal(t, expectedValue, actualValue)
|
||||
|
||||
datetime = "1-9-2024"
|
||||
expectedValue = true
|
||||
actualValue = IsValidDayMonthYearLongOrShortDateFormat(datetime)
|
||||
assert.Equal(t, expectedValue, actualValue)
|
||||
|
||||
datetime = "31-12-9999"
|
||||
expectedValue = true
|
||||
actualValue = IsValidDayMonthYearLongOrShortDateFormat(datetime)
|
||||
assert.Equal(t, expectedValue, actualValue)
|
||||
|
||||
datetime = "01/09/2024"
|
||||
expectedValue = true
|
||||
actualValue = IsValidDayMonthYearLongOrShortDateFormat(datetime)
|
||||
assert.Equal(t, expectedValue, actualValue)
|
||||
|
||||
datetime = "01.09.2024"
|
||||
expectedValue = true
|
||||
actualValue = IsValidDayMonthYearLongOrShortDateFormat(datetime)
|
||||
assert.Equal(t, expectedValue, actualValue)
|
||||
|
||||
datetime = "01/09'2024"
|
||||
expectedValue = true
|
||||
actualValue = IsValidDayMonthYearLongOrShortDateFormat(datetime)
|
||||
assert.Equal(t, expectedValue, actualValue)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user