org.mmbase.util
Class DynamicDate

Package class diagram package DynamicDate
java.lang.Object
  extended by java.util.Date
      extended by org.mmbase.util.DynamicDate
All Implemented Interfaces:
Serializable, Cloneable, Comparable<Date>

public class DynamicDate
extends Date

A DynamicDate is a Date object that has no fixed value, like 'now'. It is unmodifiable, so all set-methods throw exceptions. There is no public constructor, but a public static getInstance(java.lang.String). Sadly, the Date object of Sun is implemented using private static methods which use private fields of the Date object, so not everything could be overridden perfectly. So, if e.g. a dynamic date could be an argument of an 'after' or 'before' method, it is better to wrap it with eval(java.lang.String) first. Basicly the following dynamic dates are possible:

The then found (absolute) date/time can then be offsetted with aditions like "- 1 minute", "+ 5 week". I.e. one of the binary operators '-' or '+' an integer and a time unit (in the singular). This process can be repeated so things like 'now + 5 minute + 3 second' will be correctly parsed. getDemo() returns a list of several strings which can be parsed.

Since:
MMBase-1.8
Author:
Michiel Meeuwissen
See Also:
Serialized Form

Field Summary
protected  String date
          The original string by which this instance was gotten.
 
Constructor Summary
protected DynamicDate(String d)
           
 
Method Summary
 boolean after(Date when)
           
 boolean before(Date when)
           
 Object clone()
           
 int compareTo(Date anotherDate)
           
 boolean equals(Object obj)
           
static Date eval(Date date)
          Makes sure the argument 'date' is no DynamicDate any more.
static Date eval(String format)
          This calls getInstance(java.lang.String), then eval(java.lang.String) and catches the parse-exception (in which case it will return -1).
protected  Date evalDate()
          This produces a normal Date object, and is called everytime when that is needed.
 int getDate()
          Deprecated. 
 int getDay()
          Deprecated. 
static String[] getDemo()
          Returns an arrays of example Strings that can be parsed by DynamicDate.
 String getFormat()
           
 int getHours()
          Deprecated. 
static Date getInstance(String format)
          Parses a format string and returns Date instance, possibly a 'dynamic one'.
 int getMinutes()
          Deprecated. 
 int getMonth()
          Deprecated. 
 int getSeconds()
          Deprecated. 
 long getTime()
           
 int getTimezoneOffset()
          Deprecated. 
 int getYear()
          Deprecated. 
 int hashCode()
           
static void main(String[] argv)
           
 void setDate(int date)
          Deprecated. 
 void setHours(int hours)
          Deprecated. 
 void setMinutes(int minutes)
          Deprecated. 
 void setMonth(int month)
          Deprecated. 
 void setSeconds(int seconds)
          Deprecated. 
 void setTime(long time)
          Deprecated. 
 void setYear(int year)
          Deprecated. 
 String toGMTString()
          Deprecated. 
 String toLocaleString()
          Deprecated. 
 String toString()
           
 
Methods inherited from class java.util.Date
parse, UTC
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

date

protected final String date
The original string by which this instance was gotten.

Constructor Detail

DynamicDate

protected DynamicDate(String d)
Method Detail

getInstance

public static Date getInstance(String format)
                        throws ParseException
Parses a format string and returns Date instance, possibly a 'dynamic one'. Not necessary a new one, which does not matter, because these objects are unmodifiable anyway. If the request date is not dynamic, but absolutely defined, a normal Date object is returned.

Throws:
ParseException

eval

public static Date eval(String format)
This calls getInstance(java.lang.String), then eval(java.lang.String) and catches the parse-exception (in which case it will return -1). This boils down to that this is a utility method to get a new Date object by String in just one call.

Since:
MMBase-1.8.7

eval

public static Date eval(Date date)
Makes sure the argument 'date' is no DynamicDate any more. So this returns a fixed date object when the argument is a DynamicDate and simply the argument if it is not.


getFormat

public String getFormat()

evalDate

protected Date evalDate()
This produces a normal Date object, and is called everytime when that is needed. Users can call it too, if they want to fixate that Date. You can also use eval(Date), which will work on a normal Date object too.


after

public boolean after(Date when)
Overrides:
after in class Date

before

public boolean before(Date when)
Overrides:
before in class Date

clone

public Object clone()
Overrides:
clone in class Date

compareTo

public int compareTo(Date anotherDate)
Specified by:
compareTo in interface Comparable<Date>
Overrides:
compareTo in class Date

equals

public boolean equals(Object obj)
Overrides:
equals in class Date

getDate

@Deprecated
public int getDate()
Deprecated. 

Overrides:
getDate in class Date

getDay

@Deprecated
public int getDay()
Deprecated. 

Overrides:
getDay in class Date

getHours

@Deprecated
public int getHours()
Deprecated. 

Overrides:
getHours in class Date

getMinutes

@Deprecated
public int getMinutes()
Deprecated. 

Overrides:
getMinutes in class Date

getMonth

@Deprecated
public int getMonth()
Deprecated. 

Overrides:
getMonth in class Date

getSeconds

@Deprecated
public int getSeconds()
Deprecated. 

Overrides:
getSeconds in class Date

getTime

public long getTime()
Overrides:
getTime in class Date

getTimezoneOffset

@Deprecated
public int getTimezoneOffset()
Deprecated. 

Overrides:
getTimezoneOffset in class Date

getYear

@Deprecated
public int getYear()
Deprecated. 

Overrides:
getYear in class Date

hashCode

public int hashCode()
Overrides:
hashCode in class Date

setDate

@Deprecated
public void setDate(int date)
Deprecated. 

Overrides:
setDate in class Date

setHours

@Deprecated
public void setHours(int hours)
Deprecated. 

Overrides:
setHours in class Date

setMinutes

@Deprecated
public void setMinutes(int minutes)
Deprecated. 

Overrides:
setMinutes in class Date

setMonth

@Deprecated
public void setMonth(int month)
Deprecated. 

Overrides:
setMonth in class Date

setSeconds

@Deprecated
public void setSeconds(int seconds)
Deprecated. 

Overrides:
setSeconds in class Date

setTime

@Deprecated
public void setTime(long time)
Deprecated. 

Overrides:
setTime in class Date

setYear

@Deprecated
public void setYear(int year)
Deprecated. 

Overrides:
setYear in class Date

toGMTString

@Deprecated
public String toGMTString()
Deprecated. 

Overrides:
toGMTString in class Date

toLocaleString

@Deprecated
public String toLocaleString()
Deprecated. 

Overrides:
toLocaleString in class Date

toString

public String toString()
Overrides:
toString in class Date

getDemo

public static String[] getDemo()
Returns an arrays of example Strings that can be parsed by DynamicDate. Most features are tested here.


main

public static void main(String[] argv)
                 throws ParseException,
                        ParseException
Throws:
ParseException


MMBase2 Utils 2.0-SNAPSHOT - 2013-03-30T06:24