fix: accept datetime-local history filters
This commit is contained in:
@@ -366,8 +366,8 @@ func normalizeRawFrameQuery(query RawFrameQuery) RawFrameQuery {
|
||||
query.Phone = strings.TrimSpace(query.Phone)
|
||||
query.DeviceID = strings.TrimSpace(query.DeviceID)
|
||||
query.MessageID = strings.TrimSpace(query.MessageID)
|
||||
query.DateFrom = strings.TrimSpace(query.DateFrom)
|
||||
query.DateTo = strings.TrimSpace(query.DateTo)
|
||||
query.DateFrom = normalizeDateTimeLiteral(query.DateFrom)
|
||||
query.DateTo = normalizeDateTimeLiteral(query.DateTo)
|
||||
if query.Limit <= 0 {
|
||||
query.Limit = 20
|
||||
}
|
||||
@@ -380,8 +380,8 @@ func normalizeLocationQuery(query LocationQuery) LocationQuery {
|
||||
query.VIN = strings.TrimSpace(query.VIN)
|
||||
query.Phone = strings.TrimSpace(query.Phone)
|
||||
query.DeviceID = strings.TrimSpace(query.DeviceID)
|
||||
query.DateFrom = strings.TrimSpace(query.DateFrom)
|
||||
query.DateTo = strings.TrimSpace(query.DateTo)
|
||||
query.DateFrom = normalizeDateTimeLiteral(query.DateFrom)
|
||||
query.DateTo = normalizeDateTimeLiteral(query.DateTo)
|
||||
if query.Limit <= 0 {
|
||||
query.Limit = 20
|
||||
}
|
||||
@@ -394,8 +394,8 @@ func normalizeMileagePointQuery(query MileagePointQuery) MileagePointQuery {
|
||||
query.VIN = strings.TrimSpace(query.VIN)
|
||||
query.Phone = strings.TrimSpace(query.Phone)
|
||||
query.DeviceID = strings.TrimSpace(query.DeviceID)
|
||||
query.DateFrom = strings.TrimSpace(query.DateFrom)
|
||||
query.DateTo = strings.TrimSpace(query.DateTo)
|
||||
query.DateFrom = normalizeDateTimeLiteral(query.DateFrom)
|
||||
query.DateTo = normalizeDateTimeLiteral(query.DateTo)
|
||||
if query.Limit <= 0 {
|
||||
query.Limit = 20
|
||||
}
|
||||
@@ -482,10 +482,10 @@ func rawFrameWhere(query RawFrameQuery) []string {
|
||||
}
|
||||
}
|
||||
if query.DateFrom != "" {
|
||||
add("ts >= '" + quote(query.DateFrom) + "'")
|
||||
add("ts >= '" + quote(normalizeDateTimeLiteral(query.DateFrom)) + "'")
|
||||
}
|
||||
if query.DateTo != "" {
|
||||
add("ts <= '" + quote(query.DateTo) + "'")
|
||||
add("ts <= '" + quote(normalizeDateTimeLiteral(query.DateTo)) + "'")
|
||||
}
|
||||
return where
|
||||
}
|
||||
@@ -511,10 +511,10 @@ func locationWhere(query LocationQuery) []string {
|
||||
add("device_id = '" + quote(query.DeviceID) + "'")
|
||||
}
|
||||
if query.DateFrom != "" {
|
||||
add("ts >= '" + quote(query.DateFrom) + "'")
|
||||
add("ts >= '" + quote(normalizeDateTimeLiteral(query.DateFrom)) + "'")
|
||||
}
|
||||
if query.DateTo != "" {
|
||||
add("ts <= '" + quote(query.DateTo) + "'")
|
||||
add("ts <= '" + quote(normalizeDateTimeLiteral(query.DateTo)) + "'")
|
||||
}
|
||||
return where
|
||||
}
|
||||
@@ -540,10 +540,10 @@ func mileagePointWhere(query MileagePointQuery) []string {
|
||||
add("device_id = '" + quote(query.DeviceID) + "'")
|
||||
}
|
||||
if query.DateFrom != "" {
|
||||
add("ts >= '" + quote(query.DateFrom) + "'")
|
||||
add("ts >= '" + quote(normalizeDateTimeLiteral(query.DateFrom)) + "'")
|
||||
}
|
||||
if query.DateTo != "" {
|
||||
add("ts <= '" + quote(query.DateTo) + "'")
|
||||
add("ts <= '" + quote(normalizeDateTimeLiteral(query.DateTo)) + "'")
|
||||
}
|
||||
return where
|
||||
}
|
||||
@@ -793,7 +793,7 @@ func parseMessageID(value string) (int64, bool) {
|
||||
}
|
||||
|
||||
func validDateTime(value string) bool {
|
||||
value = strings.TrimSpace(value)
|
||||
value = normalizeDateTimeLiteral(value)
|
||||
if value == "" {
|
||||
return true
|
||||
}
|
||||
@@ -805,6 +805,14 @@ func validDateTime(value string) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func normalizeDateTimeLiteral(value string) string {
|
||||
value = strings.TrimSpace(value)
|
||||
if len(value) == len("2006-01-02T15:04:05") && value[10] == 'T' {
|
||||
return value[:10] + " " + value[11:]
|
||||
}
|
||||
return value
|
||||
}
|
||||
|
||||
func safeIdentifier(value string) bool {
|
||||
if value == "" {
|
||||
return false
|
||||
|
||||
Reference in New Issue
Block a user