mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Support for timestamp with timezone containing offset as ID
This commit is contained in:
@@ -165,6 +165,7 @@ func ParseTimeDetectLayout(tmStr string, timezone string) (time.Time, error) {
|
||||
rfc3339Rule := regexp.MustCompile(`^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.+$`)
|
||||
sqlRule := regexp.MustCompile(`^\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2}$`)
|
||||
gotimeRule := regexp.MustCompile(`^\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2}\.?\d*\s[+,-]\d+\s\w+$`)
|
||||
gotimeRule2 := regexp.MustCompile(`^\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2}\.?\d*\s[+,-]\d+\s[+,-]\d+$`)
|
||||
fsTimestamp := regexp.MustCompile(`^\d{16}$`)
|
||||
astTimestamp := regexp.MustCompile(`^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d*[+,-]\d+$`)
|
||||
unixTimestampRule := regexp.MustCompile(`^\d{10}$`)
|
||||
@@ -179,6 +180,8 @@ func ParseTimeDetectLayout(tmStr string, timezone string) (time.Time, error) {
|
||||
return time.Parse(time.RFC3339, tmStr)
|
||||
case gotimeRule.MatchString(tmStr):
|
||||
return time.Parse("2006-01-02 15:04:05.999999999 -0700 MST", tmStr)
|
||||
case gotimeRule2.MatchString(tmStr):
|
||||
return time.Parse("2006-01-02 15:04:05.999999999 -0700 -0700", tmStr)
|
||||
case sqlRule.MatchString(tmStr):
|
||||
return time.ParseInLocation("2006-01-02 15:04:05", tmStr, loc)
|
||||
case fsTimestamp.MatchString(tmStr):
|
||||
|
||||
@@ -153,6 +153,22 @@ func TestParseTimeDetectLayout(t *testing.T) {
|
||||
if err == nil {
|
||||
t.Errorf("Expecting error")
|
||||
}
|
||||
loc, err := time.LoadLocation("Asia/Kabul")
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
expectedTime = time.Date(2013, 12, 30, 15, 0, 1, 0, loc)
|
||||
goTmStr2 := "2013-12-30 15:00:01 +0430 +0430"
|
||||
goTm, err = ParseTimeDetectLayout(goTmStr2, "")
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
} else if !goTm.Equal(expectedTime) {
|
||||
t.Errorf("Unexpected time parsed: %v, expecting: %v", goTm, expectedTime)
|
||||
}
|
||||
//goTmStr2 = "2013-12-30 15:00:01 +0430"
|
||||
//if _, err = ParseTimeDetectLayout(goTmStr2, ""); err != nil {
|
||||
// t.Errorf("Expecting error")
|
||||
//}
|
||||
fsTmstampStr := "1394291049287234"
|
||||
fsTm, err := ParseTimeDetectLayout(fsTmstampStr, "")
|
||||
expectedTime = time.Date(2014, 3, 8, 15, 4, 9, 287234000, time.UTC)
|
||||
|
||||
Reference in New Issue
Block a user