From b7856f885bf02af20b07359823396a92ffa6e76e Mon Sep 17 00:00:00 2001 From: Ivan Frade Date: Tue, 12 Nov 2024 12:29:13 -0800 Subject: [PATCH] SystemReader: add method to get LocalDateTime Using #civilNow() because in the documentation, this calendar-based representation is called "civil time". Change-Id: Iaa363e66683cb548419666068a4ffef44a776e12 --- .../src/org/eclipse/jgit/util/SystemReader.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/util/SystemReader.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/SystemReader.java index 7cdf0ee1a2..55cc878e02 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/util/SystemReader.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/SystemReader.java @@ -26,6 +26,7 @@ import java.nio.file.Paths; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.time.Instant; +import java.time.LocalDateTime; import java.time.ZoneId; import java.time.ZoneOffset; import java.util.Locale; @@ -538,6 +539,17 @@ public abstract class SystemReader { return Instant.ofEpochMilli(getCurrentTime()); } + /** + * Get "now" as civil time, in the System timezone + * + * @return the current system time + * + * @since 7.1 + */ + public LocalDateTime civilNow() { + return LocalDateTime.ofInstant(now(), getTimeZoneId()); + } + /** * Get clock instance preferred by this system. * -- 2.39.5