Package com.infinitekind.util
Class DateUtil
java.lang.Object
com.infinitekind.util.DateUtil
public class DateUtil
extends java.lang.Object
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classDateUtil.Comparator -
Field Summary
Fields Modifier and Type Field Description static intfiscalYearStartMMDDstatic longMILLIS_PER_DAY -
Constructor Summary
Constructors Constructor Description DateUtil() -
Method Summary
Modifier and Type Method Description static intcalculateDaysBetween(int beginDate, int endDate)Calculate and return the number of days in between the two dates.static intcalculateDaysInMonth(int date)Calculate the number of days in the current monthstatic intcalculateDaysInYear(int date)Calculate the number of days in the given yearstatic intconvertCalToInt(java.util.Calendar c)static intconvertDateToInt(java.util.Date longDt)static java.util.DateconvertIntDateToLong(int intDt)Function used to convert an integer date representation to a long date representation that can be used by the java.util.Date and Calendar objects, or code that interfaces with older versions of Moneydance.static intconvertLongDateToInt(long longDt)static booleandateIsAfterCurrentMonth(java.util.Date date)static longdecrementDate(long date)static java.util.DatedecrementDate(java.util.Date date)static java.util.DatedecrementMonth(java.util.Date date)static intdecrementYear(int date)static java.util.DatedecrementYear(java.util.Date date)static intfirstDayInFiscalQuarter(int date)Return the first date of the fiscal quarter containing 'date' if the fiscal year starts on the default fiscal year start date (month and day) specified in DateUtil.fiscalYearStartMMDDstatic intfirstDayInFiscalQuarter(int date, int fiscalYearStartMMDD)Return the first date of the fiscal quarter containing 'date' if the fiscal year starts on the given day of the year (encoded as an integer of the form MMDD)static intfirstDayInFiscalYear(int date)Return the first date of the fiscal year containing 'date' if the fiscal year starts on the default fiscal year start date (month and day) specified in DateUtil.fiscalYearStartMMDDstatic intfirstDayInFiscalYear(int date, int fiscalYearStartMMDD)Return the first date of the fiscal year containing 'date' if the fiscal year starts on the given day of the year (encoded as an integer of the form MMDD)static intfirstDayInMonth(int date)static java.util.DatefirstDayInMonth(java.util.Date date)static intfirstDayInQuarter(int date)static java.util.DatefirstDayInQuarter(java.util.Date date)static intfirstDayInWeek(int date)static intfirstDayInYear(int date)static java.util.DatefirstDayInYear(java.util.Date date)static longfirstMinuteInDay(long date)static java.util.DatefirstMinuteInDay(java.util.Date date)static doublegetAdjustedRate(long value1, long value2)static doublegetAdjustedRate(long value1, long value2, double startRate)Return a rate such that Math.round(value1 * rate) = value2, if possible.static intgetDate(int year, int month, int day)Get the date corresponding to the given year, month and day in int date form (basically an integer YYYYMMDD).static longgetStrippedDate()static intgetStrippedDateInt()Return the current date encoded as an YYYYMMDD intstatic java.util.DategetStrippedDateObj()Deprecated.use getStrippedDateInt() insteadstatic intincrementDate(int date)static intincrementDate(int date, int numYears, int numMonths, int numDays)Add the given number of years, months, and days to the given date.static longincrementDate(long date)static java.util.DateincrementDate(java.util.Date date)static java.util.DateincrementMonth(java.util.Date date)static intincrementYear(int date)static java.util.DateincrementYear(java.util.Date date)static intlastDayInFiscalQuarter(int date)Return the last date of the fiscal quarter containing 'date' if the fiscal year starts on the default fiscal year start date (month and day) specified in DateUtil.fiscalYearStartMMDDstatic intlastDayInFiscalQuarter(int date, int fiscalYearStartMMDD)Return the last date of the fiscal quarter containing 'date' if the fiscal year starts on the given day of the year (encoded as an integer of the form MMDD)static intlastDayInFiscalYear(int date)Return the last date of the fiscal year containing 'date' if the fiscal year starts on the default fiscal year start date (month and day) specified in DateUtil.fiscalYearStartMMDDstatic intlastDayInFiscalYear(int date, int fiscalYearStartMMDD)Return the last date of the fiscal year containing 'date' if the fiscal year starts on the given day of the year (encoded as an integer of the form MMDD)static intlastDayInMonth(int date)static java.util.DatelastDayInMonth(java.util.Date date)static intlastDayInQuarter(int date)static java.util.DatelastDayInQuarter(java.util.Date date)static intlastDayInWeek(int date)static intlastDayInYear(int date)static java.util.DatelastDayInYear(java.util.Date date)static longlastMinuteInDay(long date)static java.util.DatelastMinuteInDay(java.util.Date date)static voidmain(java.lang.String[] argv)Return a value1 such that Math.round(value1 * rate) = value2, if possible.static intminmax(int min, int val, int max)static floatmonthsInPeriod(int start, int end)Counts the number of months between start (inclusive) and end (exclusive).static doublesafeRate(double rate)If the given rate is zero, return a number that can be used as a denominator, otherwise,static voidsetCalendarDate(java.util.Calendar c, int date)Set the given Calendar object to the given integer-encoded date where the decimal value of the integer is YYYYMMDD.static voidsetToBeginningOfMonth(java.util.Calendar c)static voidsetToEndOfMonth(java.util.Calendar c)static voidstripTimeFromCal(java.util.Calendar c)static longstripTimeFromDate(long date)Get the date value for the given time value (ie get the long value representation with the same date, but with the time set to around noon)static java.util.DatestripTimeFromDate(java.util.Date date)static floatyearsInPeriod(int start, int end)Counts the number of years between start (inclusive) and end (exclusive).
-
Field Details
-
MILLIS_PER_DAY
public static final long MILLIS_PER_DAY- See Also:
- Constant Field Values
-
fiscalYearStartMMDD
public static int fiscalYearStartMMDD
-
-
Constructor Details
-
DateUtil
public DateUtil()
-
-
Method Details
-
main
public static void main(java.lang.String[] argv) throws java.lang.ExceptionReturn a value1 such that Math.round(value1 * rate) = value2, if possible.- Throws:
java.lang.Exception
-
getAdjustedRate
public static final double getAdjustedRate(long value1, long value2) -
getAdjustedRate
public static final double getAdjustedRate(long value1, long value2, double startRate)Return a rate such that Math.round(value1 * rate) = value2, if possible. This uses the startRate as a starting point. -
dateIsAfterCurrentMonth
public static boolean dateIsAfterCurrentMonth(java.util.Date date) -
minmax
public static final int minmax(int min, int val, int max) -
setCalendarDate
public static final void setCalendarDate(java.util.Calendar c, int date)Set the given Calendar object to the given integer-encoded date where the decimal value of the integer is YYYYMMDD. -
convertDateToInt
public static final int convertDateToInt(java.util.Date longDt) -
convertLongDateToInt
public static final int convertLongDateToInt(long longDt) -
convertCalToInt
public static final int convertCalToInt(java.util.Calendar c) -
convertIntDateToLong
public static final java.util.Date convertIntDateToLong(int intDt)Function used to convert an integer date representation to a long date representation that can be used by the java.util.Date and Calendar objects, or code that interfaces with older versions of Moneydance. -
getStrippedDate
public static final long getStrippedDate() -
getStrippedDateInt
public static final int getStrippedDateInt()Return the current date encoded as an YYYYMMDD int -
getStrippedDateObj
public static final java.util.Date getStrippedDateObj()Deprecated.use getStrippedDateInt() instead -
stripTimeFromDate
public static final long stripTimeFromDate(long date)Get the date value for the given time value (ie get the long value representation with the same date, but with the time set to around noon) -
stripTimeFromDate
public static final java.util.Date stripTimeFromDate(java.util.Date date) -
stripTimeFromCal
public static final void stripTimeFromCal(java.util.Calendar c) -
setToBeginningOfMonth
public static final void setToBeginningOfMonth(java.util.Calendar c) -
setToEndOfMonth
public static final void setToEndOfMonth(java.util.Calendar c) -
lastMinuteInDay
public static final java.util.Date lastMinuteInDay(java.util.Date date) -
lastMinuteInDay
public static final long lastMinuteInDay(long date) -
firstMinuteInDay
public static final java.util.Date firstMinuteInDay(java.util.Date date) -
firstMinuteInDay
public static final long firstMinuteInDay(long date) -
incrementDate
public static final java.util.Date incrementDate(java.util.Date date) -
incrementDate
public static final int incrementDate(int date) -
getDate
public static final int getDate(int year, int month, int day)Get the date corresponding to the given year, month and day in int date form (basically an integer YYYYMMDD). -
incrementDate
public static final int incrementDate(int date, int numYears, int numMonths, int numDays)Add the given number of years, months, and days to the given date. -
calculateDaysBetween
public static final int calculateDaysBetween(int beginDate, int endDate)Calculate and return the number of days in between the two dates. -
calculateDaysInMonth
public static final int calculateDaysInMonth(int date)Calculate the number of days in the current month -
calculateDaysInYear
public static final int calculateDaysInYear(int date)Calculate the number of days in the given year -
monthsInPeriod
public static final float monthsInPeriod(int start, int end)Counts the number of months between start (inclusive) and end (exclusive). Fractional months are determined in terms of the number of days in the last monthly period. -
yearsInPeriod
public static final float yearsInPeriod(int start, int end)Counts the number of years between start (inclusive) and end (exclusive). Fractional years are determined in terms of the number of months in the last year and then by the number of days in the last month. -
incrementDate
public static final long incrementDate(long date) -
decrementDate
public static final java.util.Date decrementDate(java.util.Date date) -
decrementMonth
public static java.util.Date decrementMonth(java.util.Date date) -
incrementMonth
public static java.util.Date incrementMonth(java.util.Date date) -
decrementDate
public static final long decrementDate(long date) -
incrementYear
public static final java.util.Date incrementYear(java.util.Date date) -
incrementYear
public static final int incrementYear(int date) -
decrementYear
public static final java.util.Date decrementYear(java.util.Date date) -
decrementYear
public static final int decrementYear(int date) -
firstDayInQuarter
public static final java.util.Date firstDayInQuarter(java.util.Date date) -
firstDayInQuarter
public static final int firstDayInQuarter(int date) -
firstDayInFiscalQuarter
public static final int firstDayInFiscalQuarter(int date)Return the first date of the fiscal quarter containing 'date' if the fiscal year starts on the default fiscal year start date (month and day) specified in DateUtil.fiscalYearStartMMDD -
firstDayInFiscalQuarter
public static final int firstDayInFiscalQuarter(int date, int fiscalYearStartMMDD)Return the first date of the fiscal quarter containing 'date' if the fiscal year starts on the given day of the year (encoded as an integer of the form MMDD) -
lastDayInFiscalQuarter
public static final int lastDayInFiscalQuarter(int date)Return the last date of the fiscal quarter containing 'date' if the fiscal year starts on the default fiscal year start date (month and day) specified in DateUtil.fiscalYearStartMMDD -
lastDayInFiscalQuarter
public static final int lastDayInFiscalQuarter(int date, int fiscalYearStartMMDD)Return the last date of the fiscal quarter containing 'date' if the fiscal year starts on the given day of the year (encoded as an integer of the form MMDD) -
lastDayInQuarter
public static final java.util.Date lastDayInQuarter(java.util.Date date) -
lastDayInQuarter
public static final int lastDayInQuarter(int date) -
firstDayInMonth
public static final java.util.Date firstDayInMonth(java.util.Date date) -
firstDayInMonth
public static final int firstDayInMonth(int date) -
lastDayInMonth
public static final java.util.Date lastDayInMonth(java.util.Date date) -
lastDayInMonth
public static final int lastDayInMonth(int date) -
firstDayInYear
public static final java.util.Date firstDayInYear(java.util.Date date) -
firstDayInYear
public static final int firstDayInYear(int date) -
lastDayInYear
public static final java.util.Date lastDayInYear(java.util.Date date) -
lastDayInYear
public static final int lastDayInYear(int date) -
lastDayInFiscalYear
public static final int lastDayInFiscalYear(int date)Return the last date of the fiscal year containing 'date' if the fiscal year starts on the default fiscal year start date (month and day) specified in DateUtil.fiscalYearStartMMDD -
lastDayInFiscalYear
public static final int lastDayInFiscalYear(int date, int fiscalYearStartMMDD)Return the last date of the fiscal year containing 'date' if the fiscal year starts on the given day of the year (encoded as an integer of the form MMDD) -
firstDayInFiscalYear
public static final int firstDayInFiscalYear(int date)Return the first date of the fiscal year containing 'date' if the fiscal year starts on the default fiscal year start date (month and day) specified in DateUtil.fiscalYearStartMMDD -
firstDayInFiscalYear
public static final int firstDayInFiscalYear(int date, int fiscalYearStartMMDD)Return the first date of the fiscal year containing 'date' if the fiscal year starts on the given day of the year (encoded as an integer of the form MMDD) -
firstDayInWeek
public static final int firstDayInWeek(int date) -
lastDayInWeek
public static final int lastDayInWeek(int date) -
safeRate
public static final double safeRate(double rate)If the given rate is zero, return a number that can be used as a denominator, otherwise,
-