We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 911a2bc commit c889796Copy full SHA for c889796
2 files changed
src/main/java/io/r2dbc/postgresql/codec/Interval.java
@@ -828,16 +828,24 @@ private static Interval parsePostgresIntervalValue(String value) {
828
829
token = st.nextToken();
830
831
- // This handles years, months, days for both, ISO and
+ // This handles millenniums, centuries, decades, years, months, weeks, days for both, ISO and
832
// Non-ISO intervals. Hours, minutes, seconds and microseconds
833
// are handled for Non-ISO intervals here.
834
835
- if (token.startsWith("year") || token.startsWith("yr")) {
836
- years = Integer.parseInt(valueToken);
+ if (token.startsWith("mill")) {
+ years = Math.addExact(years, Math.toIntExact(Math.multiplyExact(Integer.parseInt(valueToken), 1000)));
837
+ } else if (token.startsWith("cent") || token.equals("c")) {
838
+ years = Math.addExact(years, Math.toIntExact(Math.multiplyExact(Integer.parseInt(valueToken), 100)));
839
+ } else if (token.startsWith("dec")) {
840
+ years = Math.addExact(years, Math.toIntExact(Math.multiplyExact(Integer.parseInt(valueToken), 10)));
841
+ } else if (token.startsWith("year") || token.startsWith("yr")) {
842
+ years = Math.addExact(years, Math.toIntExact(Integer.parseInt(valueToken)));
843
} else if (token.startsWith("mon")) {
844
months = Integer.parseInt(valueToken);
845
+ } else if (token.startsWith("week") || token.equals("w")) {
846
+ days = Math.addExact(days, Math.toIntExact(Math.multiplyExact(Integer.parseInt(valueToken), 7)));
847
} else if (token.startsWith("day")) {
- days = Integer.parseInt(valueToken);
848
+ days = Math.addExact(days, Math.toIntExact(Integer.parseInt(valueToken)));
849
} else if (token.startsWith("hour") || token.startsWith("hr")) {
850
hours = Integer.parseInt(valueToken);
851
} else if (token.startsWith("min")) {
src/test/java/io/r2dbc/postgresql/codec/IntervalUnitTests.java
@@ -63,6 +63,12 @@ static Stream<Object[]> parseValues() {
63
new Object[]{"8 years 2 mons 3 days 04:05", Interval.of(8, 2, 3, 4, 5, 0, 0)},
64
new Object[]{"00:00:00", Interval.ZERO},
65
new Object[]{"-1 years -2 mons +3 days -04:05:06", Interval.of(-1, -2, 3, -4, -5, -6, 0)},
66
+ new Object[]{"4 weeks", Interval.of(0, 0, 28, 0, 0, 0.0)},
67
+ new Object[]{"1 w 3 days", Interval.of(0, 0, 10, 0, 0, 0.0)},
68
+ new Object[]{"2 millenniums 4 years", Interval.of(2004, 0, 0, 0, 0, 0.0)},
69
+ new Object[]{"1 dec 8 yrs", Interval.of(18, 0, 0, 0, 0, 0.0)},
70
+ new Object[]{"2 c 2 decade", Interval.of(220, 0, 0, 0, 0, 0.0)},
71
+ new Object[]{"1 century 4 days", Interval.of(100, 0, 4, 0, 0, 0.0)},
72
73
// intervalstyle=postgres_verbose
74
new Object[]{"@ 3 days 4 hours 5 mins 6 secs", Interval.of(0, 0, 3, 4, 5, 6, 0)},
0 commit comments