Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix interval overflow #1658

Merged
merged 1 commit into from Dec 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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