From 868504d7159da541b5d50195230a6beaf991de51 Mon Sep 17 00:00:00 2001 From: arisnguyenit97 Date: Sat, 14 Sep 2024 14:07:53 +0700 Subject: [PATCH] :mute: silent changes: add unify functions supporting Time4j #3 --- .../groovy/org/unify4j/common/Time4j.java | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/plugin/src/main/groovy/org/unify4j/common/Time4j.java b/plugin/src/main/groovy/org/unify4j/common/Time4j.java index 21e184e..745b023 100644 --- a/plugin/src/main/groovy/org/unify4j/common/Time4j.java +++ b/plugin/src/main/groovy/org/unify4j/common/Time4j.java @@ -12,6 +12,7 @@ import java.time.*; import java.time.format.DateTimeFormatter; import java.time.format.DateTimeParseException; +import java.time.format.TextStyle; import java.time.temporal.TemporalAdjusters; import java.util.*; import java.util.concurrent.TimeUnit; @@ -1600,4 +1601,58 @@ public static Date roundUpToNextHour(Date date, int hour) { LocalDateTime roundedUpTime = local.withMinute(0).withSecond(0); return Time4j.transform(roundedUpTime); } + + /** + * Gets the day of the week for a given {@link Calendar} instance. + * + * @param calendar The {@link Calendar} instance. + * @return The full name of the day of the week (e.g., "Monday", "Tuesday"). + */ + public static String getDayOfWeek(Calendar calendar) { + if (calendar == null) { + return ""; + } + SimpleDateFormat format = new SimpleDateFormat("EEEE"); + return format.format(calendar.getTime()); + } + + /** + * Gets the day of the week for a given {@link Date} instance. + * + * @param date The {@link Date} instance. + * @return The full name of the day of the week (e.g., "Monday", "Tuesday"). + */ + public static String getDayOfWeek(Date date) { + if (date == null) { + return ""; + } + SimpleDateFormat format = new SimpleDateFormat("EEEE"); + return format.format(date); + } + + /** + * Returns the day of the week for a given {@link LocalDate} object. + * + * @param date The {@link LocalDate} object. + * @return The full name of the day of the week (e.g., "Monday", "Tuesday"). + */ + public static String getDayOfWeekStr(LocalDate date) { + if (date == null) { + return ""; + } + return getDayOfWeek(date).getDisplayName(TextStyle.FULL, Locale.ENGLISH); + } + + /** + * Returns the day of the week for a given {@link LocalDateTime} object. + * + * @param date The {@link LocalDateTime} object. + * @return The full name of the day of the week (e.g., "Monday", "Tuesday"). + */ + public static String getDayOfWeek(LocalDateTime date) { + if (date == null) { + return ""; + } + return date.getDayOfWeek().getDisplayName(TextStyle.FULL, Locale.ENGLISH); + } }