Skip to content

Commit

Permalink
🔇 silent changes: add unify functions supporting Time4j #3
Browse files Browse the repository at this point in the history
  • Loading branch information
pnguyen215 committed Sep 14, 2024
1 parent e877f20 commit 868504d
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions plugin/src/main/groovy/org/unify4j/common/Time4j.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}

0 comments on commit 868504d

Please sign in to comment.