org.jquantlib.time
Class Date
- java.lang.Object
-
- org.jquantlib.time.Date
-
- All Implemented Interfaces:
- java.io.Serializable, java.lang.Cloneable, java.lang.Comparable<Date>, Observable
public class Date extends java.lang.Object implements Observable, java.lang.Comparable<Date>, java.io.Serializable, java.lang.Cloneable
Date class to represent time in days.- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor and Description Date()Default constructor returning a null date.Date(java.util.Date date)Allows interoperability with JDK DateDate(int day, int month, int year)More traditional constructor.Date(int day, Month month, int year)More traditional constructor.Date(long serialNumber)Constructor taking a serial number as given by Applix or Excel.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method and Description Dateadd(int days)returns a new date incremented by the given number of daysDateadd(Period period)returns a new date incremented by the given periodDateaddAssign(int days)incrementsthisdate by the given number of daysDateaddAssign(Period period)incrementsthisdate by the given periodvoidaddObserver(Observer observer)Attaches a observer to the Observable.Dateclone()intcompareTo(Date o)intcountObservers()Counts how many Observers were attached to this class.intdayOfMonth()intdayOfYear()One-based (Jan 1st = 1)Datedec()1-day post-decrementvoiddeleteObserver(Observer observer)Detaches a previously attached observer to the observable.voiddeleteObservers()Detaches all previously attached observer to the observable.static DateendOfMonth(Date d)Last day of the month to which the given date belongsbooleaneq(Date another)booleanequals(java.lang.Object anObject)booleange(Date another)java.util.List<Observer>getObservers()Returns list of observers registered with the Observable.booleangt(Date another)inthashCode()Dateinc()1-day post-incrementstatic booleanisEndOfMonth(Date d)Whether a date is the last day of its monthstatic booleanisLeap(int year)Whether the given year is a leap onebooleanisNull()java.util.DateisoDate()Returns a java.util.Date configured for a ISO date formatterbooleanisToday()booleanle(Date another)java.util.DatelongDate()Retuirns a java.util.Date configured for a long date formatterstatic intlowerBound(java.util.List<Date> dates, Date value)This method is equivalent to std:lower_bound function Returns an index pointing to the first element in the ordered collection is equal or greater than passed valuebooleanlt(Date another)static Datemax(Date... t)Return the maximum Date in a range.static DatemaxDate()Latest allowed datestatic Datemin(Date... t)Return the minimum Date in a range.static DateminDate()Earliest allowed dateMonthmonth()booleanne(Date another)static DatenextWeekday(Date d, Weekday w)Next given weekday following or equal to the given datevoidnotifyObservers()Notifies all attached observers about changes in the observable.voidnotifyObservers(java.lang.Object arg)Notifies all attached observers about changes in the observable.static DatenthWeekday(int nth, Weekday dayOfWeek, int month, int year)Returns a new Date which is the n-th week day of a certain month/yearstatic DatenthWeekday(int n, Weekday w, Month m, int y)n-th given weekday in the given month and yearlongserialNumber()java.util.DateshortDate()Returns a java.util.Date configured for a short date formatterlongsub(Date another)Difference in days between datesDatesub(int days)returns a new date decremented by the given number of daysDatesub(Period period)returns a new date decremented by the given periodDatesubAssign(int days)decrementthisdate by the given number of daysDatesubAssign(Period period)decrementsthisdate by the given periodstatic DatetodaysDate()Today's date.java.lang.StringtoString()static intupperBound(java.util.List<Date> dates, Date value)This method is equivalent to C++ sdt:upper_bound function Returns an index pointing to the first element in the ordered collection which is greater than passed valueWeekdayweekday()intyear()
-
-
-
Constructor Detail
-
Date
public Date()
Default constructor returning a null date.
-
Date
public Date(long serialNumber)
Constructor taking a serial number as given by Applix or Excel.- Parameters:
serialNumber-
-
Date
public Date(int day, Month month, int year)More traditional constructor.- Parameters:
d-moreGreeks-y-
-
Date
public Date(int day, int month, int year)More traditional constructor.- Parameters:
d-moreGreeks-y-
-
Date
public Date(java.util.Date date)
Allows interoperability with JDK DateNOTE: Both java.util.Date and JQuantLib Date do not support time zones or high precision clocks. In other words, a day always has exactly 84,600 seconds, or 84,600,000 milliseconds.
-
-
Method Detail
-
weekday
public Weekday weekday()
-
dayOfMonth
public int dayOfMonth()
-
dayOfYear
public int dayOfYear()
One-based (Jan 1st = 1)- Returns:
-
month
public Month month()
-
year
public int year()
-
serialNumber
public long serialNumber()
-
addAssign
public Date addAssign(int days)
incrementsthisdate by the given number of days- Returns:
- this
-
addAssign
public Date addAssign(Period period)
incrementsthisdate by the given period- Returns:
- this
-
subAssign
public Date subAssign(int days)
decrementthisdate by the given number of days- Returns:
- this
-
subAssign
public Date subAssign(Period period)
decrementsthisdate by the given period- Returns:
- this
-
inc
public Date inc()
1-day post-increment- Returns:
- this
-
dec
public Date dec()
1-day post-decrement- Returns:
- this
-
add
public Date add(int days)
returns a new date incremented by the given number of days- Returns:
- a new instance
-
add
public Date add(Period period)
returns a new date incremented by the given period- Returns:
- a new instance
-
sub
public Date sub(int days)
returns a new date decremented by the given number of days- Returns:
- a new instance
-
sub
public Date sub(Period period)
returns a new date decremented by the given period- Returns:
- a new instance
-
sub
public long sub(Date another)
Difference in days between dates
-
eq
public boolean eq(Date another)
-
ne
public boolean ne(Date another)
-
lt
public boolean lt(Date another)
-
le
public boolean le(Date another)
-
gt
public boolean gt(Date another)
-
ge
public boolean ge(Date another)
-
isNull
public boolean isNull()
- Returns:
- true if this Date is null or non-valid date
-
isToday
public final boolean isToday()
-
longDate
public java.util.Date longDate()
Retuirns a java.util.Date configured for a long date formatterMethod
toStringwould return something like Mon, dd yyyy- Returns:
- a java.util.Date configured for a long date formatter
-
shortDate
public java.util.Date shortDate()
Returns a java.util.Date configured for a short date formatterMethod
toStringwould return something like mm/dd/yyyy- Returns:
- a java.util.Date configured for a short date formatter
-
isoDate
public java.util.Date isoDate()
Returns a java.util.Date configured for a ISO date formatterMethod
toStringwould return something like yyyy-mm-yy- Returns:
- a java.util.Date configured for a ISO date formatter
-
compareTo
public int compareTo(Date o)
- Specified by:
compareToin interfacejava.lang.Comparable<Date>
-
addObserver
public final void addObserver(Observer observer)
Description copied from interface:ObservableAttaches a observer to the Observable. After attachment the observer gets informed about changes in the Observable.- Specified by:
addObserverin interfaceObservable- Parameters:
observer- The observer to attach to the observable
-
countObservers
public final int countObservers()
Description copied from interface:ObservableCounts how many Observers were attached to this class.- Specified by:
countObserversin interfaceObservable- Returns:
- the number of Observers
- See Also:
Observer
-
deleteObserver
public final void deleteObserver(Observer observer)
Description copied from interface:ObservableDetaches a previously attached observer to the observable. After detachment the observer does no longer receive change notifications from the observable.- Specified by:
deleteObserverin interfaceObservable- Parameters:
observer- The observer to detach from the observable
-
notifyObservers
public final void notifyObservers()
Description copied from interface:ObservableNotifies all attached observers about changes in the observable.- Specified by:
notifyObserversin interfaceObservable
-
notifyObservers
public final void notifyObservers(java.lang.Object arg)
Description copied from interface:ObservableNotifies all attached observers about changes in the observable.- Specified by:
notifyObserversin interfaceObservable- Parameters:
arg- an arbitrary Object to be passed to the Observer
-
deleteObservers
public final void deleteObservers()
Description copied from interface:ObservableDetaches all previously attached observer to the observable. After detachment observers do not longer receive change notifications from the observable.- Specified by:
deleteObserversin interfaceObservable
-
getObservers
public final java.util.List<Observer> getObservers()
Description copied from interface:ObservableReturns list of observers registered with the Observable. List returned is unmodifiable list.- Specified by:
getObserversin interfaceObservable- Returns:
- list of observers
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
equals
public boolean equals(java.lang.Object anObject)
- Overrides:
equalsin classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
clone
public Date clone()
- Overrides:
clonein classjava.lang.Object
-
todaysDate
public static final Date todaysDate()
Today's date.- Returns:
- a new instance
-
minDate
public static final Date minDate()
Earliest allowed date- Returns:
- a new instance
-
maxDate
public static final Date maxDate()
Latest allowed date- Returns:
- a new instance
-
isLeap
public static final boolean isLeap(int year)
Whether the given year is a leap one- Parameters:
y-- Returns:
-
endOfMonth
public static final Date endOfMonth(Date d)
Last day of the month to which the given date belongs- Returns:
- a new instance
-
isEndOfMonth
public static final boolean isEndOfMonth(Date d)
Whether a date is the last day of its month- Returns:
-
nextWeekday
public static final Date nextWeekday(Date d, Weekday w)
Next given weekday following or equal to the given dateE.g., the Friday following Tuesday, JANUARY 15th, 2002 was JANUARY 18th, 2002.
- Returns:
- a new instance
- See Also:
http://www.cpearson.com/excel/DateTimeWS.htm
-
nthWeekday
public static final Date nthWeekday(int n, Weekday w, Month m, int y)
n-th given weekday in the given month and yearE.g., the 4th Thursday of March, 1998 was March 26th, 1998.
- Parameters:
n-w-m-y-- Returns:
- a new instance
- See Also:
http://www.cpearson.com/excel/DateTimeWS.htm
-
nthWeekday
public static final Date nthWeekday(int nth, Weekday dayOfWeek, int month, int year)
Returns a new Date which is the n-th week day of a certain month/year- Parameters:
nth- is the desired weekdayOfWeek- is the desired week daymonth- is the desired monthyear- is the desired year- Returns:
- a new instance
-
lowerBound
public static int lowerBound(java.util.List<Date> dates, Date value)
This method is equivalent to std:lower_bound function Returns an index pointing to the first element in the ordered collection is equal or greater than passed value- Parameters:
dates- order collection in ascending ordervalue- Date to be compared- Returns:
- index to element which is >= passed value
-
upperBound
public static int upperBound(java.util.List<Date> dates, Date value)
This method is equivalent to C++ sdt:upper_bound function Returns an index pointing to the first element in the ordered collection which is greater than passed value- Parameters:
dates- order collection in ascending ordervalue- Date to be compared- Returns:
- index to element which is > passed value
-
-
DataMelt 3.0 © DataMelt by jWork.ORG