@@ -54,12 +54,12 @@ object PostgreSQLIntervalEncoderDecoder extends ColumnEncoderDecoder {
54
54
private def postgresHMSBuilder (builder : PeriodFormatterBuilder ) = builder
55
55
// .printZeroAlways // really all-or-nothing
56
56
.rejectSignedValues(true ) // XXX: sign should apply to all
57
- .appendHours .appendSeparator (" :" )
58
- .appendMinutes.appendSeparator (" :" )
57
+ .appendHours .appendSuffix (" :" )
58
+ .appendMinutes.appendSuffix (" :" )
59
59
.appendSecondsWithOptionalMillis
60
60
61
- private val secsParser = new PeriodFormatterBuilder ()
62
- .appendSecondsWithOptionalMillis
61
+ private val hmsParser =
62
+ postgresHMSBuilder( new PeriodFormatterBuilder ())
63
63
.toFormatter
64
64
65
65
private val postgresParser =
@@ -100,8 +100,8 @@ object PostgreSQLIntervalEncoderDecoder extends ColumnEncoderDecoder {
100
100
else {
101
101
/* try to guess based on what comes after the first number */
102
102
val i = value.indexWhere(! _.isDigit, if (" -+" .contains(value(0 ))) 1 else 0 )
103
- if (i <= 0 || value(i).equals( '.' )) /* just a number */
104
- secsParser /* postgres treats this as seconds */
103
+ if (i < 0 || " :. " .contains( value(i))) /* simple HMS (to support group negation) */
104
+ hmsParser
105
105
else if (value(i).equals('-' )) /* sql_standard: Y-M */
106
106
sqlParser
107
107
else if (value(i).equals(' ' ) && i+ 1 < value.length && value(i+ 1 ).isDigit) /* sql_standard: D H:M:S */
@@ -110,7 +110,9 @@ object PostgreSQLIntervalEncoderDecoder extends ColumnEncoderDecoder {
110
110
postgresParser
111
111
}
112
112
)
113
- if (value.endsWith(" ago" )) /* only really applies to postgres_verbose, but shouldn't hurt */
113
+ if ((format eq hmsParser) && value(0 ).equals('-' ))
114
+ format.parsePeriod(value.substring(1 )).negated
115
+ else if (value.endsWith(" ago" )) /* only really applies to postgres_verbose, but shouldn't hurt */
114
116
format.parsePeriod(value.stripSuffix(" ago" )).negated
115
117
else
116
118
format.parsePeriod(value)
0 commit comments