Skip to content

Commit 868504d

Browse files
committed
🔇 silent changes: add unify functions supporting Time4j #3
1 parent e877f20 commit 868504d

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

plugin/src/main/groovy/org/unify4j/common/Time4j.java

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import java.time.*;
1313
import java.time.format.DateTimeFormatter;
1414
import java.time.format.DateTimeParseException;
15+
import java.time.format.TextStyle;
1516
import java.time.temporal.TemporalAdjusters;
1617
import java.util.*;
1718
import java.util.concurrent.TimeUnit;
@@ -1600,4 +1601,58 @@ public static Date roundUpToNextHour(Date date, int hour) {
16001601
LocalDateTime roundedUpTime = local.withMinute(0).withSecond(0);
16011602
return Time4j.transform(roundedUpTime);
16021603
}
1604+
1605+
/**
1606+
* Gets the day of the week for a given {@link Calendar} instance.
1607+
*
1608+
* @param calendar The {@link Calendar} instance.
1609+
* @return The full name of the day of the week (e.g., "Monday", "Tuesday").
1610+
*/
1611+
public static String getDayOfWeek(Calendar calendar) {
1612+
if (calendar == null) {
1613+
return "";
1614+
}
1615+
SimpleDateFormat format = new SimpleDateFormat("EEEE");
1616+
return format.format(calendar.getTime());
1617+
}
1618+
1619+
/**
1620+
* Gets the day of the week for a given {@link Date} instance.
1621+
*
1622+
* @param date The {@link Date} instance.
1623+
* @return The full name of the day of the week (e.g., "Monday", "Tuesday").
1624+
*/
1625+
public static String getDayOfWeek(Date date) {
1626+
if (date == null) {
1627+
return "";
1628+
}
1629+
SimpleDateFormat format = new SimpleDateFormat("EEEE");
1630+
return format.format(date);
1631+
}
1632+
1633+
/**
1634+
* Returns the day of the week for a given {@link LocalDate} object.
1635+
*
1636+
* @param date The {@link LocalDate} object.
1637+
* @return The full name of the day of the week (e.g., "Monday", "Tuesday").
1638+
*/
1639+
public static String getDayOfWeekStr(LocalDate date) {
1640+
if (date == null) {
1641+
return "";
1642+
}
1643+
return getDayOfWeek(date).getDisplayName(TextStyle.FULL, Locale.ENGLISH);
1644+
}
1645+
1646+
/**
1647+
* Returns the day of the week for a given {@link LocalDateTime} object.
1648+
*
1649+
* @param date The {@link LocalDateTime} object.
1650+
* @return The full name of the day of the week (e.g., "Monday", "Tuesday").
1651+
*/
1652+
public static String getDayOfWeek(LocalDateTime date) {
1653+
if (date == null) {
1654+
return "";
1655+
}
1656+
return date.getDayOfWeek().getDisplayName(TextStyle.FULL, Locale.ENGLISH);
1657+
}
16031658
}

0 commit comments

Comments
 (0)