Class DateMath
- java.lang.Object
-
- org.linuxforhealth.fhir.database.utils.common.DateMath
-
public class DateMath extends java.lang.ObjectSimple utility class to handle the date arithmetic we need for rolling date-based partitions TODO use java.time instead
-
-
Constructor Summary
Constructors Constructor Description DateMath()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.util.DateaddDays(java.util.Date d, int howMany)Add howMany days to the givenDatestatic java.util.DateaddMonths(java.util.Date d, int howMany)Add howMany months to the givenDatestatic java.util.DateaddSeconds(java.util.Date d, int howMany)Add the requested number of seconds to the given datestatic java.lang.Stringformat(java.util.Date d)Format the date value as yyyy-MM-ddstatic java.lang.Stringformat2(java.util.Date d)Alternate format of the date value: yyyyMMddstatic java.util.Datemax(java.util.Date d1, java.util.Date d2)Return the max of 2 datesstatic java.util.Dateparse(java.lang.String str)Parse the date string which is expected to be yyyy-MM-ddstatic java.util.DatetruncateToDay(java.util.Date d)Truncate the date to the beginning of the daystatic java.util.DatetruncateToMonth(java.util.Date d)Truncate the date to the midnight on the first day of the month
-
-
-
Method Detail
-
addDays
public static java.util.Date addDays(java.util.Date d, int howMany)Add howMany days to the givenDate- Parameters:
d-howMany-- Returns:
-
addMonths
public static java.util.Date addMonths(java.util.Date d, int howMany)Add howMany months to the givenDate- Parameters:
d-howMany-- Returns:
-
parse
public static java.util.Date parse(java.lang.String str)
Parse the date string which is expected to be yyyy-MM-dd- Parameters:
str-- Returns:
-
format
public static java.lang.String format(java.util.Date d)
Format the date value as yyyy-MM-dd- Parameters:
d-- Returns:
-
format2
public static java.lang.String format2(java.util.Date d)
Alternate format of the date value: yyyyMMdd- Parameters:
d-- Returns:
-
truncateToMonth
public static java.util.Date truncateToMonth(java.util.Date d)
Truncate the date to the midnight on the first day of the month- Parameters:
d-- Returns:
-
truncateToDay
public static java.util.Date truncateToDay(java.util.Date d)
Truncate the date to the beginning of the day- Parameters:
d-- Returns:
-
addSeconds
public static java.util.Date addSeconds(java.util.Date d, int howMany)Add the requested number of seconds to the given date- Parameters:
d-howMany-- Returns:
-
max
public static java.util.Date max(java.util.Date d1, java.util.Date d2)Return the max of 2 dates- Parameters:
d1-d2-- Returns:
- max date
-
-