Package org.drip.analytics.date
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
- Module = Product Core Module
- Library = Fixed Income Analytics
- Project = Date, Cash Flow, and Cash Flow Period Measure Generation Utilities
- Package = Date and Time Creation, Manipulation, and Usage
- Author:
- Lakshmi Krishnamurthy
-
Field Summary
Fields Modifier and Type Field Description static int
APRIL
Integer Month - Aprilstatic int
AUGUST
Integer Month - Auguststatic int
DECEMBER
Integer Month - Decemberstatic int
FEBRUARY
Integer Month - Februarystatic int
FRIDAY
Days of the week - Fridaystatic double
HALFSECOND
HALF_SECOND Constant for Julian Date Constructionstatic int
JANUARY
Integer Month - Januarystatic int
JGREG
JGREG Constant for Julian Date Constructionstatic int
JULY
Integer Month - Julystatic int
JUNE
Integer Month - Junestatic int
LEFT_INCLUDE
LEFT_INCLUDE includes the start date in the Feb29 checkstatic int
MARCH
Integer Month - Marchstatic int
MAY
Integer Month - Maystatic int
MONDAY
Days of the week - Mondaystatic int
NOVEMBER
Integer Month - Novemberstatic int
OCTOBER
Integer Month - Octoberstatic int
RIGHT_INCLUDE
RIGHT_INCLUDE includes the end date in the Feb29 checkstatic int
SATURDAY
Days of the week - Saturdaystatic int
SEPTEMBER
Integer Month - Septemberstatic int
SUNDAY
Days of the week - Sundaystatic int
THURSDAY
Days of the week - Thursdaystatic int
TUESDAY
Days of the week - Tuesdaystatic 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 Monthstatic boolean
ContainsFeb29(int iStartDate, int iEndDate, int iIncludeSide)
Indicate whether there is at least One Leap Day between 2 given Datesstatic JulianDate
CreateFromDDMMMYYYY(java.lang.String strDate)
Create a JulianDate from a String containing the Date in the DDMMMYYYY Formatstatic JulianDate
CreateFromMDY(java.lang.String strMDY, java.lang.String strDelim)
Create a JulianDate from a String containing Date in the DDMMYYYY Formatstatic JulianDate
CreateFromYMD(int iYear, int iMonth, int iDate)
Create a JulianDate from the Year/Month/Datestatic JulianDate
CreateFromYMD(java.lang.String strYMD, java.lang.String strDelim)
Create a JulianDate from a String containing Date in the YYYYMMDD Formatstatic 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 Instancestatic java.lang.String
DayChars(int iDay)
Get the English word for day corresponding to the input integerstatic int
DayOfTheWeek(java.util.Date dt)
Return the Day of the Week corresponding to the java.util.Date Instancestatic int
DaysElapsed(int iDate)
Number of Days elapsed in the Year represented by the given Julian Datestatic int
DaysInMonth(int iMonth, int iYear)
Get the maximum number of days in the given month and yearstatic int
DaysRemaining(int iDate)
Number of Days remaining in the Year represented by the given Julian Datestatic java.lang.String
DDMMMYYYY(int iJulian)
Create an DD/MMM/YYYY String from the Input Julian Integerstatic JulianDate
FromMDY(java.lang.String strMDY, java.lang.String strDelim)
Create a JulianDate from the MDYstatic boolean
IsEOM(int iDate)
Indicate if the given Date corresponds to a Month Endstatic boolean
IsLeapYear(int iDate)
Indicate if the Year of the given Julian Date is a Leap Yearstatic java.util.Date
JavaDateFromJulianDate(JulianDate dt)
Retrieve a Java Date Instance from the Julian Date Instancestatic JulianDate
MakeJulianDateFromBBGDate(java.lang.String strBBGDate)
Create a JulianDate from Bloomberg date stringstatic JulianDate
MakeJulianFromDDMMMYY(java.lang.String strDDMMMYY, java.lang.String strDelim)
Create a JulianDate from the DD MMM YYstatic JulianDate
MakeJulianFromRSEntry(java.util.Date dt)
Create a JulianDate from the java Datestatic JulianDate
MakeJulianFromYYYYMMDD(java.lang.String strYYYYMMDD, java.lang.String strDelim)
Create a JulianDate from the YYYY MM DDstatic java.lang.String
MakeOracleDateFromBBGDate(java.lang.String strBBGDate)
Create an Oracle date trigram from a Bloomberg date stringstatic java.lang.String
MakeOracleDateFromYYYYMMDD(java.lang.String strYYYYMMDD)
Create an Oracle Date Trigram from a YYYYMMDD Stringstatic 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 monthstatic int
MonthFromCode(char ch)
Retrieve the Month corresponding to the Month Digit Codestatic int
MonthFromMonthChars(java.lang.String strMonth)
Convert the month trigram/word to the corresponding month integerstatic java.lang.String
MonthTrigram(int iMonth)
Return the Month Trigram corresponding to the Input Integer Monthstatic int
NumFeb29(int iStartDate, int iEndDate, int iIncludeSide)
Calculate how many Leap Days exist between the 2 given Datesstatic JulianDate
Today()
Return a Julian Date corresponding to Todaystatic 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 Datestatic int
Year(int iJulian)
Return the Year corresponding to the Julian Datestatic int
Year(java.util.Date dt)
Return the Year corresponding to the java.util.Date Instancestatic java.lang.String
YYYYMMDD(int iJulian)
Create an YYYY/MM/DD String from the Input Julian IntegerMethods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Field Details
-
HALFSECOND
public static double HALFSECONDHALF_SECOND Constant for Julian Date Construction -
JGREG
public static int JGREGJGREG Constant for Julian Date Construction -
LEFT_INCLUDE
public static final int LEFT_INCLUDELEFT_INCLUDE includes the start date in the Feb29 check- See Also:
- Constant Field Values
-
RIGHT_INCLUDE
public static final int RIGHT_INCLUDERIGHT_INCLUDE includes the end date in the Feb29 check- See Also:
- Constant Field Values
-
MONDAY
public static final int MONDAYDays of the week - Monday- See Also:
- Constant Field Values
-
TUESDAY
public static final int TUESDAYDays of the week - Tuesday- See Also:
- Constant Field Values
-
WEDNESDAY
public static final int WEDNESDAYDays of the week - Wednesday- See Also:
- Constant Field Values
-
THURSDAY
public static final int THURSDAYDays of the week - Thursday- See Also:
- Constant Field Values
-
FRIDAY
public static final int FRIDAYDays of the week - Friday- See Also:
- Constant Field Values
-
SATURDAY
public static final int SATURDAYDays of the week - Saturday- See Also:
- Constant Field Values
-
SUNDAY
public static final int SUNDAYDays of the week - Sunday- See Also:
- Constant Field Values
-
JANUARY
public static final int JANUARYInteger Month - January- See Also:
- Constant Field Values
-
FEBRUARY
public static final int FEBRUARYInteger Month - February- See Also:
- Constant Field Values
-
MARCH
public static final int MARCHInteger Month - March- See Also:
- Constant Field Values
-
APRIL
public static final int APRILInteger Month - April- See Also:
- Constant Field Values
-
MAY
public static final int MAYInteger Month - May- See Also:
- Constant Field Values
-
JUNE
public static final int JUNEInteger Month - June- See Also:
- Constant Field Values
-
JULY
public static final int JULYInteger Month - July- See Also:
- Constant Field Values
-
AUGUST
public static final int AUGUSTInteger Month - August- See Also:
- Constant Field Values
-
SEPTEMBER
public static final int SEPTEMBERInteger Month - September- See Also:
- Constant Field Values
-
OCTOBER
public static final int OCTOBERInteger Month - October- See Also:
- Constant Field Values
-
NOVEMBER
public static final int NOVEMBERInteger Month - November- See Also:
- Constant Field Values
-
DECEMBER
public static final int DECEMBERInteger 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.ExceptionConvert YMD to an Integer Julian Date.- Parameters:
iYear
- YeariMonth
- MonthiDay
- 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.ExceptionReturn 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.ExceptionReturn 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.ExceptionReturn 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.ExceptionNumber 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.ExceptionNumber 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.ExceptionIndicate 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.ExceptionIndicate whether there is at least One Leap Day between 2 given Dates- Parameters:
iStartDate
- The Start DateiEndDate
- The End DateiIncludeSide
- 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.ExceptionCalculate how many Leap Days exist between the 2 given Dates- Parameters:
iStartDate
- The Start DateiEndDate
- The End DateiIncludeSide
- 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.ExceptionConvert 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.ExceptionGet the maximum number of days in the given month and year- Parameters:
iMonth
- Integer representing the monthiYear
- 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.ExceptionIndicate 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
Create a JulianDate from the Year/Month/Date- Parameters:
iYear
- YeariMonth
- MonthiDate
- Date- Returns:
- Julian Date corresponding to the specified Year/Month/Date
-
Today
Return a Julian Date corresponding to Today- Returns:
- JulianDate corresponding to Today
-
CreateFromDDMMMYYYY
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
Create a JulianDate from a String containing Date in the DDMMYYYY Format- Parameters:
strMDY
- String containing Date in the MM/DD/YYYY FormatstrDelim
- String Delimiter- Returns:
- The JulianDate Instance
-
CreateFromYMD
Create a JulianDate from a String containing Date in the YYYYMMDD Format- Parameters:
strYMD
- String containing Date in the YYYYMMDD FormatstrDelim
- String Delimiter- Returns:
- The JulianDate Instance
-
DayOfTheWeek
public static final int DayOfTheWeek(java.util.Date dt) throws java.lang.ExceptionReturn 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.ExceptionReturn 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.ExceptionReturn 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.ExceptionReturn 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
Create a JulianDate from the java Date- Parameters:
dt
- Java Date input- Returns:
- JulianDate output
-
JavaDateFromJulianDate
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 YYstrDelim
- 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 DDstrDelim
- Delimiter- Returns:
- JulianDate output
-
FromMDY
Create a JulianDate from the MDY- Parameters:
strMDY
- Java Date input as delimited M/D/YstrDelim
- Delimiter- Returns:
- JulianDate output
-
MakeJulianDateFromBBGDate
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.ExceptionRetrieve 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.ExceptionRetrieve 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
-