Package com.helger.datetime.util
Class PDTHelper
- java.lang.Object
-
- com.helger.datetime.util.PDTHelper
-
@Immutable public final class PDTHelper extends Object
Some date/time utility methods.- Author:
- Philip Helger
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static intbirthdayCompare(LocalDate aDate1, LocalDate aDate2)Compare two dates by birthday.static booleanbirthdayEquals(LocalDate aDate1, LocalDate aDate2)Check if the two birthdays are equal.static DayOfWeekgetAsDayOfWeek(int nCalendarDayOfWeek)Convert from Calendar day of week toDayOfWeekenum.static MonthgetAsMonth(int nMonth)GetMonthfrom int value in a non-throwing version.static intgetCalendarDayOfWeek(DayOfWeek eDOW)Convert fromDayOfWeekto Calendar day of week.static LocalDategetCurrentOrNextWeekday()static LocalDategetCurrentOrNextWeekday(LocalDate aStart)Get the next week day based on the provided date.static LocalDategetCurrentOrNextWeekendkDay()Get the next weekend day based on the provided date.static LocalDategetCurrentOrNextWeekendkDay(LocalDate aStart)Get the next weekend day based on the provided date.static longgetDaysBetween(Temporal aStartIncl, Temporal aEndExcl)static intgetEndWeekOfMonth(LocalDate aDT, Locale aLocale)static intgetEndWeekOfMonth(LocalDateTime aDT, Locale aLocale)Get the end-week number for the passed year and month.static intgetEndWeekOfMonth(ZonedDateTime aDT, Locale aLocale)static LocalDategetMax(LocalDate aDate1, LocalDate aDate2)static LocalDateTimegetMax(LocalDateTime aDateTime1, LocalDateTime aDateTime2)static LocalTimegetMax(LocalTime aTime1, LocalTime aTime2)static OffsetDateTimegetMax(OffsetDateTime aDateTime1, OffsetDateTime aDateTime2)static ZonedDateTimegetMax(ZonedDateTime aDateTime1, ZonedDateTime aDateTime2)static LocalDategetMin(LocalDate aDate1, LocalDate aDate2)static LocalDateTimegetMin(LocalDateTime aDateTime1, LocalDateTime aDateTime2)static LocalTimegetMin(LocalTime aTime1, LocalTime aTime2)static OffsetDateTimegetMin(OffsetDateTime aDateTime1, OffsetDateTime aDateTime2)static ZonedDateTimegetMin(ZonedDateTime aDateTime1, ZonedDateTime aDateTime2)static intgetStartWeekOfMonth(LocalDate aDT, Locale aLocale)static intgetStartWeekOfMonth(LocalDateTime aDT, Locale aLocale)Get the start--week number for the passed year and month.static intgetStartWeekOfMonth(ZonedDateTime aDT, Locale aLocale)static intgetWeekDays(LocalDate aStartDate, LocalDate aEndDate)Count all non-weekend days in the range.static intgetWeekOfWeekBasedYear(TemporalAccessor aDT, Locale aLocale)static booleanisBetweenIncl(LocalDate aDate, LocalDate aLowerBound, LocalDate aUpperBound)static booleanisFirstDayOfWeek(DayOfWeek nDayOfWeek)static booleanisFirstDayOfWeek(LocalDate aDT)static booleanisFirstDayOfWeek(LocalDateTime aDT)static booleanisFirstDayOfWeek(ZonedDateTime aDT)static booleanisLastDayOfWeek(DayOfWeek nDayOfWeek)static booleanisLastDayOfWeek(LocalDate aDT)static booleanisLastDayOfWeek(LocalDateTime aDT)static booleanisLastDayOfWeek(ZonedDateTime aDT)static booleanisNewYearsEve(LocalDate aDate)static booleanisNullValue(LocalDate aDate)static booleanisNullValue(LocalDateTime aDateTime)static booleanisNullValue(LocalTime aTime)static booleanisNullValue(ZonedDateTime aDateTime)static booleanisSameMonthAndDay(LocalDate x, LocalDate y)static booleanisSameYearAndDay(LocalDate x, LocalDate y)static booleanisSameYearAndWeek(LocalDate x, LocalDate y, Locale aLocale)static booleanisWeekend(LocalDate aDT)static booleanisWeekend(LocalDateTime aDT)static booleanisWeekendDay(DayOfWeek nDayOfWeek)static booleanisWorkDay(LocalDate aDate)
-
-
-
Method Detail
-
isNullValue
public static boolean isNullValue(@Nullable LocalDateTime aDateTime)
-
isNullValue
public static boolean isNullValue(@Nullable ZonedDateTime aDateTime)
-
isWeekendDay
public static boolean isWeekendDay(DayOfWeek nDayOfWeek)
-
isWeekend
public static boolean isWeekend(@Nonnull LocalDateTime aDT)
-
isFirstDayOfWeek
public static boolean isFirstDayOfWeek(DayOfWeek nDayOfWeek)
-
isFirstDayOfWeek
public static boolean isFirstDayOfWeek(@Nonnull ZonedDateTime aDT)
-
isFirstDayOfWeek
public static boolean isFirstDayOfWeek(@Nonnull LocalDateTime aDT)
-
isLastDayOfWeek
public static boolean isLastDayOfWeek(DayOfWeek nDayOfWeek)
-
isLastDayOfWeek
public static boolean isLastDayOfWeek(@Nonnull ZonedDateTime aDT)
-
isLastDayOfWeek
public static boolean isLastDayOfWeek(@Nonnull LocalDateTime aDT)
-
getWeekDays
public static int getWeekDays(@Nonnull LocalDate aStartDate, @Nonnull LocalDate aEndDate)
Count all non-weekend days in the range. Does not consider holidays!- Parameters:
aStartDate- start dateaEndDate- end date- Returns:
- days not counting Saturdays and Sundays. If start date is after end date, the value will be negative! If start date equals end date the return will be 1 if it is a week day.
-
isSameYearAndDay
public static boolean isSameYearAndDay(@Nonnull LocalDate x, @Nonnull LocalDate y)
-
isSameYearAndWeek
public static boolean isSameYearAndWeek(@Nonnull LocalDate x, @Nonnull LocalDate y, @Nonnull Locale aLocale)
-
isSameMonthAndDay
public static boolean isSameMonthAndDay(@Nonnull LocalDate x, @Nonnull LocalDate y)
-
isBetweenIncl
public static boolean isBetweenIncl(@Nullable LocalDate aDate, @Nullable LocalDate aLowerBound, @Nullable LocalDate aUpperBound)
-
getWeekOfWeekBasedYear
public static int getWeekOfWeekBasedYear(@Nonnull TemporalAccessor aDT, @Nonnull Locale aLocale)
-
getStartWeekOfMonth
public static int getStartWeekOfMonth(@Nonnull LocalDateTime aDT, @Nonnull Locale aLocale)
Get the start--week number for the passed year and month.- Parameters:
aDT- The object to use year and month from.aLocale- Locale to use. May not benull.- Returns:
- the start week number.
-
getStartWeekOfMonth
public static int getStartWeekOfMonth(@Nonnull LocalDate aDT, @Nonnull Locale aLocale)
-
getStartWeekOfMonth
public static int getStartWeekOfMonth(@Nonnull ZonedDateTime aDT, @Nonnull Locale aLocale)
-
getEndWeekOfMonth
public static int getEndWeekOfMonth(@Nonnull LocalDateTime aDT, @Nonnull Locale aLocale)
Get the end-week number for the passed year and month.- Parameters:
aDT- The object to use year and month from.aLocale- Locale to use. May not benull.- Returns:
- The end week number.
-
getEndWeekOfMonth
public static int getEndWeekOfMonth(@Nonnull LocalDate aDT, @Nonnull Locale aLocale)
-
getEndWeekOfMonth
public static int getEndWeekOfMonth(@Nonnull ZonedDateTime aDT, @Nonnull Locale aLocale)
-
getCurrentOrNextWeekday
@Nonnull public static LocalDate getCurrentOrNextWeekday(@Nonnull LocalDate aStart)
Get the next week day based on the provided date. If the provided date is a week day day, the provided date is returned. A week day is determined by not being a weekend day (usually Saturday or Sunday).- Parameters:
aStart- The date to start at. May not benull.- Returns:
- The next matching date. Never
null.
-
getCurrentOrNextWeekendkDay
@Nonnull public static LocalDate getCurrentOrNextWeekendkDay(@Nonnull LocalDate aStart)
Get the next weekend day based on the provided date. If the provided date is a weekend day, the provided date is returned. Weekend day are Saturday or Sunday.- Parameters:
aStart- The date to start at. May not benull.- Returns:
- The next matching date.
-
getCurrentOrNextWeekendkDay
@Nonnull public static LocalDate getCurrentOrNextWeekendkDay()
Get the next weekend day based on the provided date. If the provided date is a weekend day, the provided date is returned. Weekend day are Saturday or Sunday.- Returns:
- The next matching date.
-
birthdayCompare
public static int birthdayCompare(@Nullable LocalDate aDate1, @Nullable LocalDate aDate2)
Compare two dates by birthday. This means, the dates are only compared by day and month, and not by year!- Parameters:
aDate1- First date. May benull.aDate2- Second date. May benull.- Returns:
- same as
Comparator.compare(Object, Object)
-
birthdayEquals
public static boolean birthdayEquals(@Nullable LocalDate aDate1, @Nullable LocalDate aDate2)
Check if the two birthdays are equal. Equal birthdays are identified by equal months and equal days.- Parameters:
aDate1- First date. May benull.aDate2- Second date. May benull.- Returns:
trueif month and day are equal
-
getMax
@Nonnull public static LocalDate getMax(@Nonnull LocalDate aDate1, @Nonnull LocalDate aDate2)
-
getMax
@Nonnull public static LocalTime getMax(@Nonnull LocalTime aTime1, @Nonnull LocalTime aTime2)
-
getMax
@Nonnull public static LocalDateTime getMax(@Nonnull LocalDateTime aDateTime1, @Nonnull LocalDateTime aDateTime2)
-
getMax
@Nonnull public static ZonedDateTime getMax(@Nonnull ZonedDateTime aDateTime1, @Nonnull ZonedDateTime aDateTime2)
-
getMax
@Nonnull public static OffsetDateTime getMax(@Nonnull OffsetDateTime aDateTime1, @Nonnull OffsetDateTime aDateTime2)
-
getMin
@Nonnull public static LocalDate getMin(@Nonnull LocalDate aDate1, @Nonnull LocalDate aDate2)
-
getMin
@Nonnull public static LocalTime getMin(@Nonnull LocalTime aTime1, @Nonnull LocalTime aTime2)
-
getMin
@Nonnull public static LocalDateTime getMin(@Nonnull LocalDateTime aDateTime1, @Nonnull LocalDateTime aDateTime2)
-
getMin
@Nonnull public static ZonedDateTime getMin(@Nonnull ZonedDateTime aDateTime1, @Nonnull ZonedDateTime aDateTime2)
-
getMin
@Nonnull public static OffsetDateTime getMin(@Nonnull OffsetDateTime aDateTime1, @Nonnull OffsetDateTime aDateTime2)
-
getDaysBetween
public static long getDaysBetween(@Nonnull Temporal aStartIncl, @Nonnull Temporal aEndExcl)
-
getAsDayOfWeek
@Nonnull public static DayOfWeek getAsDayOfWeek(int nCalendarDayOfWeek)
Convert from Calendar day of week toDayOfWeekenum.- Parameters:
nCalendarDayOfWeek- Day of week - must be between 1 and 7.- Returns:
DayOfWeekand nevernull.- Since:
- 8.6.3
-
getCalendarDayOfWeek
public static int getCalendarDayOfWeek(@Nonnull DayOfWeek eDOW)
Convert fromDayOfWeekto Calendar day of week.- Parameters:
eDOW- Day of week. May not benull.- Returns:
- Something between Calendar.SUNDAY and Calendar.SATURDAY
- Since:
- 8.6.3
-
-