MCPcopy
hub / github.com/rgburke/grv / processDateComparison

Method processDateComparison

cmd/grv/expression_processor.go:382–413  ·  view source on GitHub ↗
(fieldTypeDescriptor FieldTypeDescriptor)

Source from the content-addressed store, hash-verified

380}
381
382func (binaryExpression *BinaryExpression) processDateComparison(fieldTypeDescriptor FieldTypeDescriptor) (err error) {
383 isDateComparison, dateString, datePtr := binaryExpression.isDateComparison(fieldTypeDescriptor)
384 if !isDateComparison {
385 return
386 }
387
388 var dateFormat string
389
390 switch {
391 case dateFormatPattern.MatchString(dateString.value.value):
392 dateFormat = queryDateFormat
393 case dateTimeFormatPattern.MatchString(dateString.value.value):
394 dateFormat = queryDateTimeFormat
395 default:
396 return GenerateExpressionError(dateString, "Invalid date: %v. Format must be either %v or %v",
397 dateString.value.value, queryDateFormat, queryDateTimeFormat)
398 }
399
400 utcDateTime, err := time.Parse(dateFormat, dateString.value.value)
401 if err != nil {
402 return GenerateExpressionError(dateString, "Unable to parse date %v: %v", dateString.value.value, err)
403 }
404
405 dateTime := TimeWithLocation(utcDateTime, time.Local)
406
407 *datePtr = &DateLiteral{
408 dateTime: dateTime,
409 stringTime: dateString.value,
410 }
411
412 return
413}
414
415func (binaryExpression *BinaryExpression) isDateComparison(fieldTypeDescriptor FieldTypeDescriptor) (isDateComparison bool, dateString *StringLiteral, datePtr *Expression) {
416 var identifier *Identifier

Callers 1

ConvertTypesMethod · 0.95

Calls 4

isDateComparisonMethod · 0.95
GenerateExpressionErrorFunction · 0.85
TimeWithLocationFunction · 0.85
ParseMethod · 0.45

Tested by

no test coverage detected