Skip to content

Commit ba90228

Browse files
author
Sagar Agarwal
committed
Fix the values for duration constants
1 parent 95c0b1b commit ba90228

File tree

2 files changed

+14
-16
lines changed

2 files changed

+14
-16
lines changed

google-cloud-spanner/src/main/java/com/google/cloud/spanner/Interval.java

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
* broken into two components microseconds and nanoFractions, where nanoFractions can range from
3030
* [-999, 999]. Internally, Spanner supports Interval value with the following range of individual
3131
* fields: months: [-120000, 120000] days: [-3660000, 3660000] nanoseconds: [-316224000000000000000,
32-
* 316224000000000000000] Interval value created outside the specified domain will return error when
32+
* 316224000000000000000]. Interval value created outside the specified domain will return error when
3333
* sent to Spanner backend.
3434
*/
3535
@Immutable
@@ -43,21 +43,19 @@ public class Interval implements Serializable {
4343
public static final long SECONDS_PER_MINUTE = 60;
4444
public static final long SECONDS_PER_HOUR = MINUTES_PER_HOUR * SECONDS_PER_MINUTE;
4545
public static final long MILLIS_PER_SECOND = 1000;
46-
public static final long MICROS_PER_MILLI = 1000;
47-
public static final long NANOS_PER_MICRO = 1000;
48-
public static final long MICROS_PER_SECOND = MICROS_PER_MILLI * MILLIS_PER_SECOND;
46+
public static final long MICROS_PER_MILLISECOND = 1000;
47+
public static final long MICROS_PER_SECOND = MICROS_PER_MILLISECOND * MILLIS_PER_SECOND;
4948
public static final long MICROS_PER_MINUTE = SECONDS_PER_MINUTE * MICROS_PER_SECOND;
5049
public static final long MICROS_PER_HOUR = SECONDS_PER_HOUR * MICROS_PER_SECOND;
51-
public static final BigInteger NANOS_PER_MICROSECOND =
52-
BigInteger.valueOf(MICROS_PER_SECOND * NANOS_PER_MICRO);
50+
public static final long NANOS_PER_MICROSECOND = 1000;
5351
public static final BigInteger NANOS_PER_MILLISECOND =
54-
BigInteger.valueOf(MILLIS_PER_SECOND * NANOS_PER_MICRO);
52+
BigInteger.valueOf(MICROS_PER_MILLISECOND * NANOS_PER_MICROSECOND);
5553
public static final BigInteger NANOS_PER_SECOND =
56-
BigInteger.valueOf(MICROS_PER_SECOND * NANOS_PER_MICRO);
54+
BigInteger.valueOf(MICROS_PER_SECOND * NANOS_PER_MICROSECOND);
5755
public static final BigInteger NANOS_PER_MINUTE =
58-
BigInteger.valueOf(MICROS_PER_MINUTE * NANOS_PER_MICRO);
56+
BigInteger.valueOf(MICROS_PER_MINUTE * NANOS_PER_MICROSECOND);
5957
public static final BigInteger NANOS_PER_HOUR =
60-
BigInteger.valueOf(MICROS_PER_HOUR * NANOS_PER_MICRO);
58+
BigInteger.valueOf(MICROS_PER_HOUR * NANOS_PER_MICROSECOND);
6159
public static final Interval ZERO = Interval.builder().build();
6260

6361
/** Regex to parse ISO8601 interval format- `P[n]Y[n]M[n]DT[n]H[n]M[n([.,][fraction])]S` */
@@ -115,7 +113,7 @@ public static Interval ofMilliseconds(long milliseconds) {
115113
/** Creates an interval with specified number of microseconds. */
116114
public static Interval ofMicroseconds(long micros) {
117115
return builder()
118-
.setNanoseconds(BigInteger.valueOf(micros).multiply(NANOS_PER_MICROSECOND))
116+
.setNanoseconds(BigInteger.valueOf(micros).multiply(BigInteger.valueOf(NANOS_PER_MICROSECOND)))
119117
.build();
120118
}
121119

google-cloud-spanner/src/test/java/com/google/cloud/spanner/IntervalTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public void testOfSeconds() {
4949
assertEquals(0, interval.getMonths());
5050
assertEquals(0, interval.getDays());
5151
assertEquals(
52-
BigInteger.valueOf(10).multiply(Interval.NANOS_PER_SECOND), interval.getNanoseconds());
52+
BigInteger.valueOf(10000000000L), interval.getNanoseconds());
5353
}
5454

5555
@Test
@@ -58,7 +58,7 @@ public void testOfMilliseconds() {
5858
assertEquals(0, interval.getMonths());
5959
assertEquals(0, interval.getDays());
6060
assertEquals(
61-
BigInteger.valueOf(10).multiply(Interval.NANOS_PER_MILLISECOND), interval.getNanoseconds());
61+
BigInteger.valueOf(10000000L), interval.getNanoseconds());
6262
}
6363

6464
@Test
@@ -67,7 +67,7 @@ public void testOfMicroseconds() {
6767
assertEquals(0, interval.getMonths());
6868
assertEquals(0, interval.getDays());
6969
assertEquals(
70-
BigInteger.valueOf(10).multiply(Interval.NANOS_PER_MICROSECOND), interval.getNanoseconds());
70+
BigInteger.valueOf(10000), interval.getNanoseconds());
7171
}
7272

7373
@Test
@@ -262,8 +262,8 @@ public void testToISO8601() {
262262
public void testGetNanoseconds() {
263263
Interval interval1 =
264264
Interval.fromMonthsDaysNanos(
265-
10, 20, BigInteger.valueOf(30 * Interval.NANOS_PER_MICRO + 40));
266-
assertEquals(30 * Interval.NANOS_PER_MICRO + 40, interval1.getNanoseconds().longValueExact());
265+
10, 20, BigInteger.valueOf(30 * Interval.NANOS_PER_MICROSECOND + 40));
266+
assertEquals(30040, interval1.getNanoseconds().longValueExact());
267267

268268
Interval interval2 = Interval.fromMonthsDaysNanos(0, 0, BigInteger.valueOf(123456789));
269269
assertEquals(123456789, interval2.getNanoseconds().longValueExact());

0 commit comments

Comments
 (0)