Class DateUtil

java.lang.Object
org.drip.analytics.date.DateUtil

public class DateUtil
extends java.lang.Object
DateUtil contains Various Utilities for manipulating Date. The Julian Date - Gregorian Date Inter Conversion follows the following References:

  • Fliegel, H. F., and T. C. van Flandern (1968): A Machine Algorithm for Processing Calendar Dates Communications of the ACM 11 657
  • Fenton, D. (2001): Julian to Calendar Date Conversion http://mathforum.org/library/drmath/view/51907.html


Author:
Lakshmi Krishnamurthy
  • Field Summary

    Fields
    Modifier and Type Field Description
    static int APRIL
    Integer Month - April
    static int AUGUST
    Integer Month - August
    static int DECEMBER
    Integer Month - December
    static int FEBRUARY
    Integer Month - February
    static int FRIDAY
    Days of the week - Friday
    static double HALFSECOND
    HALF_SECOND Constant for Julian Date Construction
    static int JANUARY
    Integer Month - January
    static int JGREG
    JGREG Constant for Julian Date Construction
    static int JULY
    Integer Month - July
    static int JUNE
    Integer Month - June
    static int LEFT_INCLUDE
    LEFT_INCLUDE includes the start date in the Feb29 check
    static int MARCH
    Integer Month - March
    static int MAY
    Integer Month - May
    static int MONDAY
    Days of the week - Monday
    static int NOVEMBER
    Integer Month - November
    static int OCTOBER
    Integer Month - October
    static int RIGHT_INCLUDE
    RIGHT_INCLUDE includes the end date in the Feb29 check
    static int SATURDAY
    Days of the week - Saturday
    static int SEPTEMBER
    Integer Month - September
    static int SUNDAY
    Days of the week - Sunday
    static int THURSDAY
    Days of the week - Thursday
    static int TUESDAY
    Days of the week - Tuesday
    static int WEDNESDAY
    Days of the week - Wednesday
  • Constructor Summary

    Constructors
    Constructor Description
    DateUtil()  
  • Method Summary

    Modifier and Type Method Description
    static char CodeFromMonth​(int iMonth)
    Retrieve the Digit Code corresponding to the Month
    static boolean ContainsFeb29​(int iStartDate, int iEndDate, int iIncludeSide)
    Indicate whether there is at least One Leap Day between 2 given Dates
    static JulianDate CreateFromDDMMMYYYY​(java.lang.String strDate)
    Create a JulianDate from a String containing the Date in the DDMMMYYYY Format
    static JulianDate CreateFromMDY​(java.lang.String strMDY, java.lang.String strDelim)
    Create a JulianDate from a String containing Date in the DDMMYYYY Format
    static JulianDate CreateFromYMD​(int iYear, int iMonth, int iDate)
    Create a JulianDate from the Year/Month/Date
    static JulianDate CreateFromYMD​(java.lang.String strYMD, java.lang.String strDelim)
    Create a JulianDate from a String containing Date in the YYYYMMDD Format
    static int Date​(int iJulian)
    Return the Date given the Julian Date represented by the Integer.
    static int Day​(java.util.Date dt)
    Return the Day corresponding to the java.util.Date Instance
    static java.lang.String DayChars​(int iDay)
    Get the English word for day corresponding to the input integer
    static int DayOfTheWeek​(java.util.Date dt)
    Return the Day of the Week corresponding to the java.util.Date Instance
    static int DaysElapsed​(int iDate)
    Number of Days elapsed in the Year represented by the given Julian Date
    static int DaysInMonth​(int iMonth, int iYear)
    Get the maximum number of days in the given month and year
    static int DaysRemaining​(int iDate)
    Number of Days remaining in the Year represented by the given Julian Date
    static java.lang.String DDMMMYYYY​(int iJulian)
    Create an DD/MMM/YYYY String from the Input Julian Integer
    static JulianDate FromMDY​(java.lang.String strMDY, java.lang.String strDelim)
    Create a JulianDate from the MDY
    static boolean IsEOM​(int iDate)
    Indicate if the given Date corresponds to a Month End
    static boolean IsLeapYear​(int iDate)
    Indicate if the Year of the given Julian Date is a Leap Year
    static java.util.Date JavaDateFromJulianDate​(JulianDate dt)
    Retrieve a Java Date Instance from the Julian Date Instance
    static JulianDate MakeJulianDateFromBBGDate​(java.lang.String strBBGDate)
    Create a JulianDate from Bloomberg date string
    static JulianDate MakeJulianFromDDMMMYY​(java.lang.String strDDMMMYY, java.lang.String strDelim)
    Create a JulianDate from the DD MMM YY
    static JulianDate MakeJulianFromRSEntry​(java.util.Date dt)
    Create a JulianDate from the java Date
    static JulianDate MakeJulianFromYYYYMMDD​(java.lang.String strYYYYMMDD, java.lang.String strDelim)
    Create a JulianDate from the YYYY MM DD
    static java.lang.String MakeOracleDateFromBBGDate​(java.lang.String strBBGDate)
    Create an Oracle date trigram from a Bloomberg date string
    static java.lang.String MakeOracleDateFromYYYYMMDD​(java.lang.String strYYYYMMDD)
    Create an Oracle Date Trigram from a YYYYMMDD String
    static int Month​(int iJulian)
    Return the Month given the Julian Date represented by the Integer.
    static int Month​(java.util.Date dt)
    Return the Month corresponding to the java.util.Date Instance.
    static java.lang.String MonthChar​(int iMonth)
    Return the English word corresponding to the input integer month
    static int MonthFromCode​(char ch)
    Retrieve the Month corresponding to the Month Digit Code
    static int MonthFromMonthChars​(java.lang.String strMonth)
    Convert the month trigram/word to the corresponding month integer
    static java.lang.String MonthTrigram​(int iMonth)
    Return the Month Trigram corresponding to the Input Integer Month
    static int NumFeb29​(int iStartDate, int iEndDate, int iIncludeSide)
    Calculate how many Leap Days exist between the 2 given Dates
    static JulianDate Today()
    Return a Julian Date corresponding to Today
    static int ToJulian​(int iYear, int iMonth, int iDay)
    Convert YMD to an Integer Julian Date.
    static java.lang.String Vintage​(int iJulian)
    Return the Vintage corresponding to the Julian Date
    static int Year​(int iJulian)
    Return the Year corresponding to the Julian Date
    static int Year​(java.util.Date dt)
    Return the Year corresponding to the java.util.Date Instance
    static java.lang.String YYYYMMDD​(int iJulian)
    Create an YYYY/MM/DD String from the Input Julian Integer

    Methods inherited from class java.lang.Object

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

    • HALFSECOND

      public static double HALFSECOND
      HALF_SECOND Constant for Julian Date Construction
    • JGREG

      public static int JGREG
      JGREG Constant for Julian Date Construction
    • LEFT_INCLUDE

      public static final int LEFT_INCLUDE
      LEFT_INCLUDE includes the start date in the Feb29 check
      See Also:
      Constant Field Values
    • RIGHT_INCLUDE

      public static final int RIGHT_INCLUDE
      RIGHT_INCLUDE includes the end date in the Feb29 check
      See Also:
      Constant Field Values
    • MONDAY

      public static final int MONDAY
      Days of the week - Monday
      See Also:
      Constant Field Values
    • TUESDAY

      public static final int TUESDAY
      Days of the week - Tuesday
      See Also:
      Constant Field Values
    • WEDNESDAY

      public static final int WEDNESDAY
      Days of the week - Wednesday
      See Also:
      Constant Field Values
    • THURSDAY

      public static final int THURSDAY
      Days of the week - Thursday
      See Also:
      Constant Field Values
    • FRIDAY

      public static final int FRIDAY
      Days of the week - Friday
      See Also:
      Constant Field Values
    • SATURDAY

      public static final int SATURDAY
      Days of the week - Saturday
      See Also:
      Constant Field Values
    • SUNDAY

      public static final int SUNDAY
      Days of the week - Sunday
      See Also:
      Constant Field Values
    • JANUARY

      public static final int JANUARY
      Integer Month - January
      See Also:
      Constant Field Values
    • FEBRUARY

      public static final int FEBRUARY
      Integer Month - February
      See Also:
      Constant Field Values
    • MARCH

      public static final int MARCH
      Integer Month - March
      See Also:
      Constant Field Values
    • APRIL

      public static final int APRIL
      Integer Month - April
      See Also:
      Constant Field Values
    • MAY

      public static final int MAY
      Integer Month - May
      See Also:
      Constant Field Values
    • JUNE

      public static final int JUNE
      Integer Month - June
      See Also:
      Constant Field Values
    • JULY

      public static final int JULY
      Integer Month - July
      See Also:
      Constant Field Values
    • AUGUST

      public static final int AUGUST
      Integer Month - August
      See Also:
      Constant Field Values
    • SEPTEMBER

      public static final int SEPTEMBER
      Integer Month - September
      See Also:
      Constant Field Values
    • OCTOBER

      public static final int OCTOBER
      Integer Month - October
      See Also:
      Constant Field Values
    • NOVEMBER

      public static final int NOVEMBER
      Integer Month - November
      See Also:
      Constant Field Values
    • DECEMBER

      public static final int DECEMBER
      Integer Month - December
      See Also:
      Constant Field Values
  • Constructor Details

    • DateUtil

      public DateUtil()
  • Method Details

    • ToJulian

      public static int ToJulian​(int iYear, int iMonth, int iDay) throws java.lang.Exception
      Convert YMD to an Integer Julian Date.
      Parameters:
      iYear - Year
      iMonth - Month
      iDay - Day
      Returns:
      Integer representing the Julian Date
      Throws:
      java.lang.Exception - Thrown if the Inputs are invalid
    • YYYYMMDD

      public static java.lang.String YYYYMMDD​(int iJulian)
      Create an YYYY/MM/DD String from the Input Julian Integer
      Parameters:
      iJulian - Integer representing Julian Date
      Returns:
      YYYY/MM/DD Date String
    • DDMMMYYYY

      public static java.lang.String DDMMMYYYY​(int iJulian)
      Create an DD/MMM/YYYY String from the Input Julian Integer
      Parameters:
      iJulian - Integer representing Julian Date
      Returns:
      DD/MMM/YYYY Date String
    • Year

      public static int Year​(int iJulian) throws java.lang.Exception
      Return the Year corresponding to the Julian Date
      Parameters:
      iJulian - Integer representing Julian Date
      Returns:
      integer representing the month
      Throws:
      java.lang.Exception - Thrown if the Input Date in invalid
    • Month

      public static int Month​(int iJulian) throws java.lang.Exception
      Return the Month given the Julian Date represented by the Integer.
      Parameters:
      iJulian - Integer representing Julian Date
      Returns:
      Integer representing the Month
      Throws:
      java.lang.Exception - Thrown if the Input Date is invalid
    • Date

      public static int Date​(int iJulian) throws java.lang.Exception
      Return the Date given the Julian Date represented by the Integer.
      Parameters:
      iJulian - Integer representing Julian Date
      Returns:
      Integer representing the Date
      Throws:
      java.lang.Exception - Thrown if the Input Date is invalid
    • Vintage

      public static java.lang.String Vintage​(int iJulian)
      Return the Vintage corresponding to the Julian Date
      Parameters:
      iJulian - Integer representing Julian Date
      Returns:
      String Representing the Vintage
    • DaysElapsed

      public static final int DaysElapsed​(int iDate) throws java.lang.Exception
      Number of Days elapsed in the Year represented by the given Julian Date
      Parameters:
      iDate - Integer representing Julian Date
      Returns:
      Integer representing the Number of Days in the Current Year
      Throws:
      java.lang.Exception - Thrown if the Input Date is invalid
    • DaysRemaining

      public static final int DaysRemaining​(int iDate) throws java.lang.Exception
      Number of Days remaining in the Year represented by the given Julian Date
      Parameters:
      iDate - Integer representing Julian Date
      Returns:
      Integer representing the Number of Days remaining in the Current Year
      Throws:
      java.lang.Exception - Thrown if the Input Date is invalid
    • IsLeapYear

      public static final boolean IsLeapYear​(int iDate) throws java.lang.Exception
      Indicate if the Year of the given Julian Date is a Leap Year
      Parameters:
      iDate - Input Date
      Returns:
      TRUE - Date falls on a Leap Year
      Throws:
      java.lang.Exception - Thrown if Input is invalid
    • ContainsFeb29

      public static final boolean ContainsFeb29​(int iStartDate, int iEndDate, int iIncludeSide) throws java.lang.Exception
      Indicate whether there is at least One Leap Day between 2 given Dates
      Parameters:
      iStartDate - The Start Date
      iEndDate - The End Date
      iIncludeSide - INCLUDE_LEFT or INCLUDE_RIGHT indicating whether the starting date, the ending date, or both dates are to be included
      Returns:
      TRUE - There is at least One Feb29 between the Dates
      Throws:
      java.lang.Exception - If inputs are invalid
    • NumFeb29

      public static final int NumFeb29​(int iStartDate, int iEndDate, int iIncludeSide) throws java.lang.Exception
      Calculate how many Leap Days exist between the 2 given Dates
      Parameters:
      iStartDate - The Start Date
      iEndDate - The End Date
      iIncludeSide - INCLUDE_LEFT or INCLUDE_RIGHT indicating whether the starting date, the ending date, or both dates are to be included
      Returns:
      Number of Leap Days
      Throws:
      java.lang.Exception - Thrown if the Inputs are invalid
    • MonthChar

      public static final java.lang.String MonthChar​(int iMonth)
      Return the English word corresponding to the input integer month
      Parameters:
      iMonth - Integer representing the month
      Returns:
      String of the English word
    • MonthTrigram

      public static java.lang.String MonthTrigram​(int iMonth)
      Return the Month Trigram corresponding to the Input Integer Month
      Parameters:
      iMonth - Integer representing the Month
      Returns:
      String representing the Month Trigram (used, e.g., in Oracle DB)
    • MonthFromMonthChars

      public static final int MonthFromMonthChars​(java.lang.String strMonth) throws java.lang.Exception
      Convert the month trigram/word to the corresponding month integer
      Parameters:
      strMonth - Month trigram or English Word
      Returns:
      Integer representing the Month
      Throws:
      java.lang.Exception - Thrown on Invalid Input Month
    • DayChars

      public static java.lang.String DayChars​(int iDay)
      Get the English word for day corresponding to the input integer
      Parameters:
      iDay - Integer representing the day
      Returns:
      String representing the English word for the day
    • DaysInMonth

      public static final int DaysInMonth​(int iMonth, int iYear) throws java.lang.Exception
      Get the maximum number of days in the given month and year
      Parameters:
      iMonth - Integer representing the month
      iYear - Integer representing the year
      Returns:
      Integer representing the maximum days
      Throws:
      java.lang.Exception - Thrown if inputs are invalid
    • IsEOM

      public static final boolean IsEOM​(int iDate) throws java.lang.Exception
      Indicate if the given Date corresponds to a Month End
      Parameters:
      iDate - The Date
      Returns:
      TRUE - Date Corresponds to EOM
      Throws:
      java.lang.Exception - Thrown if input date is invalid
    • CreateFromYMD

      public static final JulianDate CreateFromYMD​(int iYear, int iMonth, int iDate)
      Create a JulianDate from the Year/Month/Date
      Parameters:
      iYear - Year
      iMonth - Month
      iDate - Date
      Returns:
      Julian Date corresponding to the specified Year/Month/Date
    • Today

      public static final JulianDate Today()
      Return a Julian Date corresponding to Today
      Returns:
      JulianDate corresponding to Today
    • CreateFromDDMMMYYYY

      public static final JulianDate CreateFromDDMMMYYYY​(java.lang.String strDate)
      Create a JulianDate from a String containing the Date in the DDMMMYYYY Format
      Parameters:
      strDate - String containing the Date in the DDMMMYYYY Format
      Returns:
      The JulianDate Instance
    • CreateFromMDY

      public static final JulianDate CreateFromMDY​(java.lang.String strMDY, java.lang.String strDelim)
      Create a JulianDate from a String containing Date in the DDMMYYYY Format
      Parameters:
      strMDY - String containing Date in the MM/DD/YYYY Format
      strDelim - String Delimiter
      Returns:
      The JulianDate Instance
    • CreateFromYMD

      public static final JulianDate CreateFromYMD​(java.lang.String strYMD, java.lang.String strDelim)
      Create a JulianDate from a String containing Date in the YYYYMMDD Format
      Parameters:
      strYMD - String containing Date in the YYYYMMDD Format
      strDelim - String Delimiter
      Returns:
      The JulianDate Instance
    • DayOfTheWeek

      public static final int DayOfTheWeek​(java.util.Date dt) throws java.lang.Exception
      Return the Day of the Week corresponding to the java.util.Date Instance
      Parameters:
      dt - The java.util.Date Instance
      Returns:
      The Day Of The Week
      Throws:
      java.lang.Exception - Thrown if Input Date is invalid
    • Day

      public static final int Day​(java.util.Date dt) throws java.lang.Exception
      Return the Day corresponding to the java.util.Date Instance
      Parameters:
      dt - The java.util.Date Instance
      Returns:
      The Day
      Throws:
      java.lang.Exception - Thrown if Inputs are Invalid
    • Month

      public static final int Month​(java.util.Date dt) throws java.lang.Exception
      Return the Month corresponding to the java.util.Date Instance. 1 is January, and 12 is December
      Parameters:
      dt - The java.util.Date Instance
      Returns:
      The Month
      Throws:
      java.lang.Exception - Thrown if Inputs are Invalid
    • Year

      public static final int Year​(java.util.Date dt) throws java.lang.Exception
      Return the Year corresponding to the java.util.Date Instance
      Parameters:
      dt - The java.util.Date Instance
      Returns:
      The Year
      Throws:
      java.lang.Exception - Thrown if Inputs are Invalid
    • MakeOracleDateFromYYYYMMDD

      public static java.lang.String MakeOracleDateFromYYYYMMDD​(java.lang.String strYYYYMMDD)
      Create an Oracle Date Trigram from a YYYYMMDD String
      Parameters:
      strYYYYMMDD - Date String in the YYYYMMDD Format.
      Returns:
      Oracle Date Trigram String
    • MakeOracleDateFromBBGDate

      public static java.lang.String MakeOracleDateFromBBGDate​(java.lang.String strBBGDate)
      Create an Oracle date trigram from a Bloomberg date string
      Parameters:
      strBBGDate - Bloomberg date string
      Returns:
      Oracle date trigram string
    • MakeJulianFromRSEntry

      public static final JulianDate MakeJulianFromRSEntry​(java.util.Date dt)
      Create a JulianDate from the java Date
      Parameters:
      dt - Java Date input
      Returns:
      JulianDate output
    • JavaDateFromJulianDate

      public static final java.util.Date JavaDateFromJulianDate​(JulianDate dt)
      Retrieve a Java Date Instance from the Julian Date Instance
      Parameters:
      dt - Julian Date Instance
      Returns:
      The Java Date Instance
    • MakeJulianFromDDMMMYY

      public static final JulianDate MakeJulianFromDDMMMYY​(java.lang.String strDDMMMYY, java.lang.String strDelim)
      Create a JulianDate from the DD MMM YY
      Parameters:
      strDDMMMYY - Java Date input as delimited DD MMM YY
      strDelim - Delimiter
      Returns:
      JulianDate output
    • MakeJulianFromYYYYMMDD

      public static final JulianDate MakeJulianFromYYYYMMDD​(java.lang.String strYYYYMMDD, java.lang.String strDelim)
      Create a JulianDate from the YYYY MM DD
      Parameters:
      strYYYYMMDD - Java Date input as delimited YYYY MM DD
      strDelim - Delimiter
      Returns:
      JulianDate output
    • FromMDY

      public static final JulianDate FromMDY​(java.lang.String strMDY, java.lang.String strDelim)
      Create a JulianDate from the MDY
      Parameters:
      strMDY - Java Date input as delimited M/D/Y
      strDelim - Delimiter
      Returns:
      JulianDate output
    • MakeJulianDateFromBBGDate

      public static final JulianDate MakeJulianDateFromBBGDate​(java.lang.String strBBGDate)
      Create a JulianDate from Bloomberg date string
      Parameters:
      strBBGDate - Bloomberg date string
      Returns:
      The new JulianDate
    • MonthFromCode

      public static final int MonthFromCode​(char ch) throws java.lang.Exception
      Retrieve the Month corresponding to the Month Digit Code
      Parameters:
      ch - The Month Digit Code
      Returns:
      The Month corresponding to the Month Digit Code
      Throws:
      java.lang.Exception - Thrown if the Digit Code is Invalid
    • CodeFromMonth

      public static final char CodeFromMonth​(int iMonth) throws java.lang.Exception
      Retrieve the Digit Code corresponding to the Month
      Parameters:
      iMonth - The Month
      Returns:
      The Digit Code corresponding to the Month
      Throws:
      java.lang.Exception - Thrown if the Digit Code cannot be computed