From 76274b62a2cf4da2feb1ac7e9ed6c982d9d3f087 Mon Sep 17 00:00:00 2001 From: Ivan Frade Date: Mon, 9 Dec 2024 13:31:44 -0800 Subject: 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 --- org.eclipse.jgit/src/org/eclipse/jgit/lib/PersonIdent.java | 11 +++++++++-- 1 file 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; + } } /** -- cgit v1.2.3