Skip to content

Commit

Permalink
Fix interval overflow (#1658)
Browse files Browse the repository at this point in the history
  • Loading branch information
reibitto authored and davecramer committed Dec 21, 2019
1 parent d164cba commit a44ab4b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
16 changes: 8 additions & 8 deletions pgjdbc/src/main/java/org/postgresql/util/PGInterval.java
Expand Up @@ -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;

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

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

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

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

/**
Expand Down
Expand Up @@ -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() {
Expand Down

0 comments on commit a44ab4b

Please sign in to comment.