Skip to content

Commit f44f6ca

Browse files
committed
Use modern Java time APIs
1 parent f07a1ab commit f44f6ca

File tree

3 files changed

+17
-13
lines changed

3 files changed

+17
-13
lines changed

CHANGELOG.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,16 @@ CHANGELOG
1010
2GB ByteBuffer limit. Files under 2GB continue to use a single ByteBuffer
1111
for optimal performance. Requested by nonetallt. GitHub #154. Fixed by
1212
Silvano Cerza. GitHub #289.
13+
* `Metadata.getBuildDate()` has been replaced with `buildTime()`, which returns
14+
`java.time.Instant` instead of `java.util.Date`. The instant represents the
15+
database build time in UTC.
1316
* `DatabaseRecord`, `Metadata`, `Network`, and internal `DecodedValue` classes
1417
have been converted to records. The following API changes were made:
1518
* `DatabaseRecord.getData()` and `DatabaseRecord.getNetwork()` have been
1619
replaced with record accessor methods `data()` and `network()`.
17-
* `Metadata.getBuildDate()` has been renamed to `buildDate()` to follow record
18-
naming conventions. All other simple getter methods on `Metadata` (e.g.,
19-
`getBinaryFormatMajorVersion()`, `getDatabaseType()`, etc.) have been
20-
replaced with their corresponding record accessor methods (e.g.,
21-
`binaryFormatMajorVersion()`, `databaseType()`, etc.).
20+
* Simple getter methods on `Metadata` (e.g., `getBinaryFormatMajorVersion()`,
21+
`getDatabaseType()`, etc.) have been replaced with their corresponding record
22+
accessor methods (e.g., `binaryFormatMajorVersion()`, `databaseType()`, etc.).
2223
* `Network.getNetworkAddress()` and `Network.getPrefixLength()` have been
2324
replaced with record accessor methods `networkAddress()` and `prefixLength()`.
2425

src/main/java/com/maxmind/db/Metadata.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.maxmind.db;
22

33
import java.math.BigInteger;
4-
import java.util.Date;
4+
import java.time.Instant;
55
import java.util.List;
66
import java.util.Map;
77

@@ -46,9 +46,9 @@ public record Metadata(
4646
public Metadata {}
4747

4848
/**
49-
* @return the date of the database build.
49+
* @return the instant of the database build in UTC.
5050
*/
51-
public Date buildDate() {
52-
return new Date(buildEpoch.longValue() * 1000);
51+
public Instant buildTime() {
52+
return Instant.ofEpochSecond(buildEpoch.longValue());
5353
}
5454
}

src/test/java/com/maxmind/db/ReaderTest.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,11 @@
1919
import java.math.BigInteger;
2020
import java.net.InetAddress;
2121
import java.net.UnknownHostException;
22+
import java.time.Instant;
23+
import java.time.LocalDate;
24+
import java.time.ZoneOffset;
2225
import java.util.ArrayList;
2326
import java.util.Arrays;
24-
import java.util.Calendar;
2527
import java.util.HashMap;
2628
import java.util.List;
2729
import java.util.Map;
@@ -1295,10 +1297,11 @@ private void testMetadata(Reader reader, int ipVersion, long recordSize) {
12951297
assertEquals(description, metadata.description());
12961298
assertEquals(recordSize, metadata.recordSize());
12971299

1298-
var cal = Calendar.getInstance();
1299-
cal.set(2014, Calendar.JANUARY, 1);
1300+
var january2014 = LocalDate.of(2014, 1, 1)
1301+
.atStartOfDay(ZoneOffset.UTC)
1302+
.toInstant();
13001303

1301-
assertTrue(metadata.buildDate().compareTo(cal.getTime()) > 0);
1304+
assertTrue(metadata.buildTime().isAfter(january2014));
13021305
}
13031306

13041307
private void testIpV4(Reader reader, File file) throws IOException {

0 commit comments

Comments
 (0)