( h int64, hasSign bool, itm types.IntervalTypeMetadata, )
| 549 | } |
| 550 | |
| 551 | func (l *intervalLexer) parseShortDuration( |
| 552 | h int64, hasSign bool, itm types.IntervalTypeMetadata, |
| 553 | ) (duration.Duration, error) { |
| 554 | sign := int64(1) |
| 555 | if hasSign { |
| 556 | sign = -1 |
| 557 | } |
| 558 | // postgresToDuration() has rewound the cursor to just after the |
| 559 | // first number, so that we can check here there are no unwanted |
| 560 | // spaces. |
| 561 | if l.str[l.offset] != ':' { |
| 562 | return duration.Duration{}, pgerror.Newf( |
| 563 | pgcode.InvalidDatetimeFormat, "interval: invalid format %s", l.str[l.offset:]) |
| 564 | } |
| 565 | l.offset++ |
| 566 | // Parse the second number. |
| 567 | m, hasDecimal, mp := l.consumeNum() |
| 568 | |
| 569 | if m < 0 { |
| 570 | return duration.Duration{}, pgerror.Newf( |
| 571 | pgcode.InvalidDatetimeFormat, "interval: invalid format: %s", l.str) |
| 572 | } |
| 573 | // We have three possible formats: |
| 574 | // - MM:SS.ffffff |
| 575 | // - HH:MM (or MM:SS for MINUTE TO SECOND) |
| 576 | // - HH:MM:SS[.ffffff] |
| 577 | // |
| 578 | // The top format has the "h" field parsed above actually |
| 579 | // represent minutes. Get this out of the way first. |
| 580 | if hasDecimal { |
| 581 | l.consumeSpaces() |
| 582 | return duration.MakeDuration( |
| 583 | h*time.Minute.Nanoseconds()+ |
| 584 | sign*(m*time.Second.Nanoseconds()+ |
| 585 | floatToNanos(mp)), |
| 586 | 0, |
| 587 | 0, |
| 588 | ), nil |
| 589 | } |
| 590 | |
| 591 | // Remaining formats. |
| 592 | var s int64 |
| 593 | var sp float64 |
| 594 | hasSecondsComponent := false |
| 595 | if l.offset != len(l.str) && l.str[l.offset] == ':' { |
| 596 | hasSecondsComponent = true |
| 597 | // The last :NN part. |
| 598 | l.offset++ |
| 599 | s, _, sp = l.consumeNum() |
| 600 | if s < 0 { |
| 601 | return duration.Duration{}, pgerror.Newf( |
| 602 | pgcode.InvalidDatetimeFormat, "interval: invalid format: %s", l.str) |
| 603 | } |
| 604 | } |
| 605 | |
| 606 | l.consumeSpaces() |
| 607 | |
| 608 | if !hasSecondsComponent && itm.DurationField.IsMinuteToSecond() { |
no test coverage detected