diff options
author | Ivan Frade <ifrade@google.com> | 2024-11-15 10:26:21 -0800 |
---|---|---|
committer | Matthias Sohn <matthias.sohn@sap.com> | 2024-11-19 13:00:58 +0100 |
commit | 92b35db291b5c661037b2724ac40488dbb44f52d (patch) | |
tree | 403ae4afa1bc9478aa1bdfce958214fb4c7fdfc0 /org.eclipse.jgit.test/tst/org/eclipse/jgit | |
parent | 307ef6b4b51f5f9266f6212015a9b5a1f1e75df4 (diff) | |
download | jgit-92b35db291b5c661037b2724ac40488dbb44f52d.tar.gz jgit-92b35db291b5c661037b2724ac40488dbb44f52d.zip |
PersonIdent: Use java.time instead of older Date and milliseconds
From errorprone: Date has a bad API that leads to bugs; prefer
java.time.Instant or LocalDate.
Replace the long with milliseconds and int with minutes offset with an
Instant and a ZoneOffset. Create new constructors and deprecate
variants with Date, milliseconds and minute offsets.
When comparing instances of PersonIdent truncate the timestamp precision
to 1 second since git commit timestamps are persisted with 1 second
precision [1].
[1] https://git-scm.com/docs/git-commit#Documentation/git-commit.txt-Gitinternalformat
Change-Id: Id4ba1f108e1ba0bfcdd87ba37c67e2d3cc7d254f
Diffstat (limited to 'org.eclipse.jgit.test/tst/org/eclipse/jgit')
-rw-r--r-- | org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/PersonIdentTest.java | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/PersonIdentTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/PersonIdentTest.java index 97da1757e0..943a68b82c 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/PersonIdentTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/PersonIdentTest.java @@ -55,7 +55,8 @@ public class PersonIdentTest { p.getWhenAsInstant()); assertEquals("A U Thor <author@example.com> 1142878501 -0500", p.toExternalString()); - assertEquals(ZoneId.of("GMT-05:00"), p.getZoneId()); + assertEquals(ZoneId.of("GMT-05:00").getRules().getOffset( + Instant.ofEpochMilli(1142878501000L)), p.getZoneOffset()); } @Test @@ -69,7 +70,8 @@ public class PersonIdentTest { p.getWhenAsInstant()); assertEquals("A U Thor <author@example.com> 1142878501 +0530", p.toExternalString()); - assertEquals(ZoneId.of("GMT+05:30"), p.getZoneId()); + assertEquals(ZoneId.of("GMT+05:30").getRules().getOffset( + Instant.ofEpochMilli(1142878501000L)), p.getZoneOffset()); } @SuppressWarnings("unused") |