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 class  DateUtil.Comparator  
  • Field Summary

    Fields 
    Modifier and Type Field Description
    static int fiscalYearStartMMDD  
    static long MILLIS_PER_DAY  
  • Constructor Summary

    Constructors 
    Constructor Description
    DateUtil()  
  • Method Summary

    Modifier and Type Method Description
    static int calculateDaysBetween​(int beginDate, int endDate)
    Calculate and return the number of days in between the two dates.
    static int calculateDaysInMonth​(int date)
    Calculate the number of days in the current month
    static int calculateDaysInYear​(int date)
    Calculate the number of days in the given year
    static int convertCalToInt​(java.util.Calendar c)  
    static int convertDateToInt​(java.util.Date longDt)  
    static 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.
    static int convertLongDateToInt​(long longDt)  
    static boolean dateIsAfterCurrentMonth​(java.util.Date date)  
    static long decrementDate​(long date)  
    static java.util.Date decrementDate​(java.util.Date date)  
    static java.util.Date decrementMonth​(java.util.Date date)  
    static int decrementYear​(int date)  
    static java.util.Date decrementYear​(java.util.Date date)  
    static 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
    static 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)
    static 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
    static 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)
    static int firstDayInMonth​(int date)  
    static java.util.Date firstDayInMonth​(java.util.Date date)  
    static int firstDayInQuarter​(int date)  
    static java.util.Date firstDayInQuarter​(java.util.Date date)  
    static int firstDayInWeek​(int date)  
    static int firstDayInYear​(int date)  
    static java.util.Date firstDayInYear​(java.util.Date date)  
    static long firstMinuteInDay​(long date)  
    static java.util.Date firstMinuteInDay​(java.util.Date date)  
    static double getAdjustedRate​(long value1, long value2)  
    static double getAdjustedRate​(long value1, long value2, double startRate)
    Return a rate such that Math.round(value1 * rate) = value2, if possible.
    static 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).
    static long getStrippedDate()  
    static int getStrippedDateInt()
    Return the current date encoded as an YYYYMMDD int
    static java.util.Date getStrippedDateObj()
    Deprecated.
    use getStrippedDateInt() instead
    static int incrementDate​(int date)  
    static int incrementDate​(int date, int numYears, int numMonths, int numDays)
    Add the given number of years, months, and days to the given date.
    static long incrementDate​(long date)  
    static java.util.Date incrementDate​(java.util.Date date)  
    static java.util.Date incrementMonth​(java.util.Date date)  
    static int incrementYear​(int date)  
    static java.util.Date incrementYear​(java.util.Date date)  
    static 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
    static 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)
    static 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
    static 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)
    static int lastDayInMonth​(int date)  
    static java.util.Date lastDayInMonth​(java.util.Date date)  
    static int lastDayInQuarter​(int date)  
    static java.util.Date lastDayInQuarter​(java.util.Date date)  
    static int lastDayInWeek​(int date)  
    static int lastDayInYear​(int date)  
    static java.util.Date lastDayInYear​(java.util.Date date)  
    static long lastMinuteInDay​(long date)  
    static java.util.Date lastMinuteInDay​(java.util.Date date)  
    static void main​(java.lang.String[] argv)
    Return a value1 such that Math.round(value1 * rate) = value2, if possible.
    static int minmax​(int min, int val, int max)  
    static float monthsInPeriod​(int start, int end)
    Counts the number of months between start (inclusive) and end (exclusive).
    static double safeRate​(double rate)
    If the given rate is zero, return a number that can be used as a denominator, otherwise,
    static 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.
    static void setToBeginningOfMonth​(java.util.Calendar c)  
    static void setToEndOfMonth​(java.util.Calendar c)  
    static void stripTimeFromCal​(java.util.Calendar c)  
    static 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)
    static java.util.Date stripTimeFromDate​(java.util.Date date)  
    static float yearsInPeriod​(int start, int end)
    Counts the number of years between start (inclusive) and end (exclusive).

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Constructor Details

  • Method Details

    • main

      public static void main​(java.lang.String[] argv) throws java.lang.Exception
      Return 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,