Skip to content
Permalink
Browse files
Fix interval overflow (#1658)
  • Loading branch information
reibitto authored and davecramer committed Dec 21, 2019
1 parent d164cba commit a44ab4becd9e5c198bfbce84fc87da6d01e5f25a
Showing with 17 additions and 8 deletions.
  1. +8 −8 pgjdbc/src/main/java/org/postgresql/util/PGInterval.java
  2. +9 −0 pgjdbc/src/test/java/org/postgresql/test/jdbc2/IntervalTest.java
@@ -17,10 +17,10 @@
public class PGInterval extends PGobject implements Serializable, Cloneable {

private int years;
private byte months;
private byte days;
private byte hours;
private byte minutes;
private int months;
private int days;
private int hours;
private int minutes;
private int wholeSeconds;
private int microSeconds;

@@ -280,7 +280,7 @@ public int getMonths() {
* @param months months to set
*/
public void setMonths(int months) {
this.months = (byte) months;
this.months = months;
}

/**
@@ -298,7 +298,7 @@ public int getDays() {
* @param days days to set
*/
public void setDays(int days) {
this.days = (byte)days;
this.days = days;
}

/**
@@ -316,7 +316,7 @@ public int getHours() {
* @param hours hours to set
*/
public void setHours(int hours) {
this.hours = (byte)hours;
this.hours = hours;
}

/**
@@ -334,7 +334,7 @@ public int getMinutes() {
* @param minutes minutes to set
*/
public void setMinutes(int minutes) {
this.minutes = (byte)minutes;
this.minutes = minutes;
}

/**
@@ -174,6 +174,15 @@ public void testOfflineTests() throws Exception {
assertEquals(-15, pgi.getHours());
assertEquals(57, pgi.getMinutes());
assertEquals(-12.1, pgi.getSeconds(), 0);

// Unjustified interval test
pgi = new PGInterval("@ 0 years 0 mons 0 days 900 hours 0 mins 0.00 secs");
assertEquals(0, pgi.getYears());
assertEquals(0, pgi.getMonths());
assertEquals(0, pgi.getDays());
assertEquals(900, pgi.getHours());
assertEquals(0, pgi.getMinutes());
assertEquals(0, pgi.getSeconds(), 0);
}

private Calendar getStartCalendar() {

0 comments on commit a44ab4b

Please sign in to comment.