aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIvan Frade <ifrade@google.com>2024-12-09 13:31:44 -0800
committerIvan Frade <ifrade@google.com>2024-12-09 13:35:00 -0800
commit76274b62a2cf4da2feb1ac7e9ed6c982d9d3f087 (patch)
tree6dd4da07b9e3ef6b4b3850b074be0a71a2853be1
parente081e9b9049ff3ffb085cae40d50ebdfb563ef17 (diff)
downloadjgit-76274b62a2cf4da2feb1ac7e9ed6c982d9d3f087.tar.gz
jgit-76274b62a2cf4da2feb1ac7e9ed6c982d9d3f087.zip
PersonIdent: Default to UTC in timezone parsing
The old method "getTimeZone(int tzOffset)" defaults to UTC if the offset is out of range, but the new "getZoneId(int tzOffset)" throws an exception. Return UTC if the offset is invalid, to keep the behavior consistent with older code. Change-Id: Iffe1980b3bd9c05ef2293635a1cbb493144afb79
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/lib/PersonIdent.java11
1 files changed, 9 insertions, 2 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/PersonIdent.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/PersonIdent.java
index 5d3db9e6ee..f22642c4ce 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/PersonIdent.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/PersonIdent.java
@@ -12,7 +12,10 @@
package org.eclipse.jgit.lib;
+import static java.time.ZoneOffset.UTC;
+
import java.io.Serializable;
+import java.time.DateTimeException;
import java.time.Instant;
import java.time.ZoneId;
import java.time.ZoneOffset;
@@ -54,11 +57,15 @@ public class PersonIdent implements Serializable {
* Translate a minutes offset into a ZoneId
*
* @param tzOffset as minutes east of UTC
- * @return a ZoneId for this offset
+ * @return a ZoneId for this offset (UTC if invalid)
* @since 7.1
*/
public static ZoneId getZoneId(int tzOffset) {
- return ZoneOffset.ofHoursMinutes(tzOffset / 60, tzOffset % 60);
+ try {
+ return ZoneOffset.ofHoursMinutes(tzOffset / 60, tzOffset % 60);
+ } catch (DateTimeException e) {
+ return UTC;
+ }
}
/**