jodd.datetime
Class JDateTime

java.lang.Object
  extended by jodd.datetime.JDateTime
All Implemented Interfaces:
java.lang.Cloneable, java.lang.Comparable

public class JDateTime
extends java.lang.Object
implements java.lang.Comparable, java.lang.Cloneable

Universal all-in-one date and time class that uses Astronomical Julian Dates for time calculations. Guaranteed precision for all manipulations and calculations is up to 1 ms (0.001 sec).

The Julian day or Julian day number (JDN) is the (integer) number of days that have elapsed since Monday, January 1, 4713 BC in the proleptic Julian calendar 1. That day is counted as Julian day zero. Thus the multiples of 7 are Mondays. Negative values can also be used.

The Julian Date (JD) is the number of days (with decimal fraction of the day) that have elapsed since 12 noon Greenwich Mean Time (UT or TT) of that day. Rounding to the nearest integer gives the Julian day number.

JDateTime contains date/time information for current day. By default, behaviour and formats are set to ISO standard, although this may be changed.

JDateTime can be set in many different ways by using setXxx() methods or equivalent constructors. Moreover, date time information may be loaded from an instance of any available java date-time class. This functionality can be easily enhanced for any custom date/time class. Furthermore, JDateTime can be converted to any such date/time class.

Rolling dates with JDateTime is easy. For this JDateTime contains many addXxx() methods. Time can be added or subtracted with any value or more values at once. All combinations are valid. Calculations also performs month fixes by default.

JDateTime behaviour is set by several attributes (or parameters). Each one contains 2 values: one is the default value, used by all instances of JDateTime and the other one is just for a specific instance of JDateTime. This means that it is possible to set behaviour of all instances at once or of one particular instance.

Bellow is the list of behaviour attributes:

Optimization: although based on heavy calculations, JDateTime works significantly faster then java's Calendars. Since JDateTime doesn't use lazy initialization, setXxx() method is slower. However, this doesn't have much effect to the global performances: settings are usually not used without gettings:) As soon as any other method is used (getXxx() or addXxx()) performances of JDateTime becomes significantly better.

Year 1582 is (almost:) working: after 1582-10-04 (Thursday) is 1582-10-15 (Friday). Users must be aware of this when doing time rolling before across this period.

More info: Julian Date on Wikipedia


Field Summary
static int APRIL
           
static int AUGUST
           
protected  int dayofweek
          Day of week, range: [1-7] == [Monday - Sunday]
protected  int dayofyear
          Day of year, range: [1-365] or [1-366]
static int DECEMBER
           
static java.lang.String DEFAULT_FORMAT
           
static int FEBRUARY
           
protected  int firstDayOfWeek
           
protected  java.lang.String format
           
static int FRIDAY
           
static int JANUARY
           
static JulianDateStamp JD_1970
          Julian Date for 1970-01-01T00:00:00 (Thursday).
static JulianDateStamp JD_2001
          Julian Date for 2001-01-01T00:00:00 (Monday).
protected  JulianDateStamp jdate
          Current Julian Date.
protected  JdtFormatter jdtFormatter
           
static int JULY
           
static int JUNE
           
protected  boolean leap
          Leap year flag.
protected  java.util.Locale locale
           
static int MARCH
           
static int MAY
           
protected  int minDaysInFirstWeek
           
static int MONDAY
           
protected  boolean monthFix
           
protected  int mustHaveDayOfFirstWeek
           
static int NOVEMBER
           
static int OCTOBER
           
static int SATURDAY
           
static int SEPTEMBER
           
static int SUNDAY
           
static int THURSDAY
           
protected  DateTimeStamp time
          DateTimeStamp for current date.
protected  java.util.TimeZone timezone
           
protected  boolean trackDST
           
static int TUESDAY
           
static int WEDNESDAY
           
protected  int weekofmonth
          Week of month.
protected  int weekofyear
          Week of year, range: [1-52] or [1-53]
 
Constructor Summary
JDateTime()
          Constructor that sets current local date and time.
JDateTime(java.util.Calendar calendar)
          Creates JDateTime from Calendar.
JDateTime(java.util.Date date)
          Creates JDateTime from Date.
JDateTime(DateTimeStamp dts)
          Creates JDateTime from DateTimeStamp.
JDateTime(double jd)
          Creates JDateTime from double that represents JD.
JDateTime(int year, int month, int day)
          Constructor that sets just date.
JDateTime(int year, int month, int day, int hour, int minute, int second, int millisecond)
          Constructor that set date and time.
JDateTime(JulianDateStamp jds)
          Creates JDateTime from JulianDateStamp.
JDateTime(long millis)
          Constructor that sets current time specified as time in milliseconds, from the midnight, January 1, 1970 UTC.
JDateTime(java.lang.String src)
          Creates JDateTime from a string.
JDateTime(java.lang.String src, JdtFormat jdtFormat)
           
JDateTime(java.lang.String src, java.lang.String template)
          Creates JDateTime from a string, using specified template.
 
Method Summary
 void add(int year, int month, int day)
          Adds date, leaving time unchanged, with preset value of monthFix.
 void add(int year, int month, int day, boolean monthFix)
          Adds date, leaving time unchanged.
 void add(int year, int month, int day, int hour, int minute, int second, int millisecond)
          Performs time adding with preset value of monthFix attribute.
 void add(int year, int month, int day, int hour, int minute, int second, int millisecond, boolean monthFix)
          Adds time to current time.
 void addDay(int d)
          Adds days, with preset value of monthFix.
 void addDay(int d, boolean monthFix)
          Adds days.
 void addHour(int h)
          Adds hours, with preset value of monthFix.
 void addHour(int h, boolean monthFix)
          Adds hours.
 void addMillisecond(int ms)
          Adds milliseconds, with preset value of monthFix.
 void addMillisecond(int ms, boolean monthFix)
          Adds milliseconds.
 void addMinute(int m)
          Adds minutes, with preset value of monthFix.
 void addMinute(int m, boolean monthFix)
          Adds minutes.
 void addMonth(int m)
          Adds month, with preset value of monthFix.
 void addMonth(int m, boolean monthFix)
          Adds month.
protected  void addNoDST(int year, int month, int day, int hour, int minute, int second, int millisecond, boolean monthFix)
           
 void addSecond(int s)
          Adds seconds, with preset value of monthFix.
 void addSecond(int s, boolean monthFix)
          Adds seconds.
 void addTime(int hour, int minute, int second)
           
 void addTime(int hour, int minute, int second, boolean monthFix)
           
 void addTime(int hour, int minute, int second, int millisecond)
          Adds time, with preset value of monthFix.
 void addTime(int hour, int minute, int second, int millisecond, boolean monthFix)
          Adds time.
 void addYear(int y)
          Adds year, with preset value of monthFix.
 void addYear(int y, boolean monthFix)
          Adds year.
 void changeTimeZone(java.util.TimeZone timezone)
          Changes current timezone.
 JDateTime clone()
           
 int compareDateTo(JDateTime jd)
          Compares current JDateTime date with another date.
 int compareTo(JDateTime jd)
           
 int compareTo(java.lang.Object o)
          Compares current JDateTime object with another one, up to 1 millisecond.
 java.util.Calendar convertToCalendar()
          Converts to Calendar instance.
 java.util.Date convertToDate()
          Converts to Date instance.
 java.sql.Date convertToSqlDate()
          Converts to java.sql.Date instance.
 java.sql.Time convertToSqlTime()
          Converts to Time instance.
 java.sql.Timestamp convertToSqlTimestamp()
          Converts to Timestamp instance.
 int daysBetween(JDateTime then)
          Returns number of full days between two dates.
 int daysBetween(JulianDateStamp then)
          Returns number of full days between two dates.
 boolean equals(java.lang.Object obj)
           
 boolean equalsDate(int year, int month, int day)
          Returns true if provided date is equal to current one.
 boolean equalsDate(JDateTime date)
          Returns true if two dates are equal.
 boolean equalsTime(JDateTime date)
          Returns true if two times are equal.
 DateTimeStamp getDateTimeStamp()
          Returns current DateTimeStamp.
 int getDay()
          Returns current day of month.
 int getDayOfMonth()
          Returns current day of month.
 int getDayOfWeek()
          Returns current day of week.
 int getDayOfYear()
          Returns current day of year.
 int getEra()
          Returns era: AD(1) or BC(0).
 int getFirstDayOfWeek()
          Returns actual the first day of the week.
 java.lang.String getFormat()
          Returns format.
 int getHour()
          Returns current hour.
 JdtFormatter getJdtFormatter()
          Returns actual JdtFormatter.
 JulianDateStamp getJulianDate()
          Returns JulianDateStamp.
 double getJulianDateDouble()
          Returns JD as double value.
 int getJulianDayNumber()
          Returns JDN.
 java.util.Locale getLocale()
          Return currently active locale.
 int getMillisecond()
          Returns current milliseconds.
 int getMillisOfDay()
          Calculates the number of milliseconds of a day.
 int getMinDaysInFirstWeek()
          Returns actual minimal number of days of the first week.
 int getMinute()
          Returns current minutes.
 JulianDateStamp getModifiedJulianDate()
          Returns Modified Julian Date (MJD), where date starts from midnight rather than noon.
 double getModifiedJulianDateDouble()
           
 int getMonth()
          Returns current month.
 int getMonthLength()
          Returns the length of the current month in days.
 int getMonthLength(int m)
          Returns the length of the specified month in days.
 int getMustHaveDayOfFirstWeek()
          Returns actual must have day of the 1st week.
 JulianDateStamp getReducedJulianDate()
          Returns Reduced Julian Date (RJD), used by astronomers.
 double getReducedJulianDateDouble()
           
 int getSecond()
          Return current seconds.
 long getTimeInMillis()
          Returns time based on current time in milliseconds.
 java.util.TimeZone getTimeZone()
          Return currently active time zone.
 JulianDateStamp getTruncatedJulianDate()
          Returns Truncated Julian Day (TJD), introduced by NASA for the space program.
 double getTruncatedJulianDateDouble()
           
 int getWeekOfMonth()
          Returns current week of month.
 int getWeekOfYear()
          Returns current week of year.
 int getYear()
          Returns current year.
 int hashCode()
           
 boolean isAfter(JDateTime then)
          Returns true if current time is after then provided time.
 boolean isAfterDate(JDateTime then)
          Returns true if current date is after then provided date.
 boolean isBefore(JDateTime then)
          Returns true if current time is before then provided time.
 boolean isBeforeDate(JDateTime then)
          Returns true if current date is before then provided date.
 boolean isInDaylightTime()
          Returns true if current date is in daylight savings time in the time zone.
 boolean isLeapYear()
          Returns true if current year is leap year.
 boolean isMonthFix()
          Returns true if month fix is active.
 boolean isTrackDST()
           
 boolean isValid(java.lang.String s)
          Checks if some string represents a valid date using actual template.
 boolean isValid(java.lang.String s, java.lang.String template)
          Checks if some string represents a valid date using provided template.
 void parse(java.lang.String src)
          Sets date/time from a string and currently active template.
 void parse(java.lang.String src, JdtFormat jdtFormat)
           
 void parse(java.lang.String src, java.lang.String format)
          Sets date/time from a string given in provided template.
 void set(int year, int month, int day)
          Sets date, time is set to midnight (00:00:00.000).
 void set(int year, int month, int day, int hour, int minute, int second, int millisecond)
          Core method that sets date and time.
 void setCurrentTime()
          Sets current local date and time.
 void setDate(int year, int month, int day)
          Sets date, time remains unchanged.
 void setDateTime(java.util.Calendar calendar)
          Sets current date and time from Calendar.
 void setDateTime(java.util.Date date)
          Sets current date and time from Date.
 void setDateTimeStamp(DateTimeStamp dts)
          Loads current date time information.
 void setDay(int d)
          Sets current day of month.
 void setFormat(java.lang.String format)
          Defines default format.
 void setHour(int h)
          Set current hour.
 void setJdtFormat(JdtFormat jdtFormat)
          Sets both format and formatter from provided JdtFormat.
 void setJdtFormatter(JdtFormatter jdtFormatter)
          Defines custom formatter.
 void setJulianDate(double jd)
          Sets JD.
 void setJulianDate(JulianDateStamp jds)
          Sets current Julian Date.
 void setLocale(java.util.Locale locale)
          Sets custom locale.
 void setMillisecond(int m)
          Sets current millisecond.
 void setMinute(int m)
          Set current minute.
 void setModifiedJulianDate(double mjd)
           
 void setMonth(int m)
          Sets current month.
 void setMonthFix(boolean monthFix)
          Sets custom month fix value.
 void setReducedJulianDate(double rjd)
           
 void setSecond(int s)
          Sets current second.
 void setSecond(int s, int m)
           
 void setTime(int hour, int minute, int second, int millisecond)
          Sets time, date is unchanged.
 void setTimeInMillis(long millis)
          Sets the time based on current time in milliseconds.
 void setTimeZone(java.util.TimeZone timezone)
          Sets time zone without changing the time.
 void setTrackDST(boolean trackDST)
           
 void setTruncatedJulianDate(double tjd)
           
 void setWeekDefinition(int start, int must)
          Defines week definitions.
 void setWeekDefinitionAlt(int start, int min)
          Defines week alternatively.
 void setYear(int y)
          Sets current year.
 void sub(int year, int month, int day)
           
 void sub(int year, int month, int day, boolean monthFix)
           
 void sub(int year, int month, int day, int hour, int minute, int second, int millisecond)
           
 void sub(int year, int month, int day, int hour, int minute, int second, int millisecond, boolean monthFix)
           
 void subDay(int d)
           
 void subDay(int d, boolean monthFix)
           
 void subHour(int h)
           
 void subHour(int h, boolean monthFix)
           
 void subMillisecond(int ms)
           
 void subMillisecond(int ms, boolean monthFix)
           
 void subMinute(int m)
           
 void subMinute(int m, boolean monthFix)
           
 void subMonth(int m)
           
 void subMonth(int m, boolean monthFix)
           
 void subSecond(int s)
           
 void subSecond(int s, boolean monthFix)
           
 void subTime(int hour, int minute, int second)
           
 void subTime(int hour, int minute, int second, boolean monthFix)
           
 void subTime(int hour, int minute, int second, int millisecond)
           
 void subTime(int hour, int minute, int second, int millisecond, boolean monthFix)
           
 void subYear(int y)
           
 void subYear(int y, boolean monthFix)
           
 java.lang.String toString()
          Returns spring representation of current date/time in currently active format.
 java.lang.String toString(JdtFormat jdtFormat)
           
 java.lang.String toString(java.lang.String format)
          Returns string representation of date/time in specified format.
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

DEFAULT_FORMAT

public static final java.lang.String DEFAULT_FORMAT
See Also:
Constant Field Values

MONDAY

public static final int MONDAY
See Also:
Constant Field Values

TUESDAY

public static final int TUESDAY
See Also:
Constant Field Values

WEDNESDAY

public static final int WEDNESDAY
See Also:
Constant Field Values

THURSDAY

public static final int THURSDAY
See Also:
Constant Field Values

FRIDAY

public static final int FRIDAY
See Also:
Constant Field Values

SATURDAY

public static final int SATURDAY
See Also:
Constant Field Values

SUNDAY

public static final int SUNDAY
See Also:
Constant Field Values

JANUARY

public static final int JANUARY
See Also:
Constant Field Values

FEBRUARY

public static final int FEBRUARY
See Also:
Constant Field Values

MARCH

public static final int MARCH
See Also:
Constant Field Values

APRIL

public static final int APRIL
See Also:
Constant Field Values

MAY

public static final int MAY
See Also:
Constant Field Values

JUNE

public static final int JUNE
See Also:
Constant Field Values

JULY

public static final int JULY
See Also:
Constant Field Values

AUGUST

public static final int AUGUST
See Also:
Constant Field Values

SEPTEMBER

public static final int SEPTEMBER
See Also:
Constant Field Values

OCTOBER

public static final int OCTOBER
See Also:
Constant Field Values

NOVEMBER

public static final int NOVEMBER
See Also:
Constant Field Values

DECEMBER

public static final int DECEMBER
See Also:
Constant Field Values

time

protected DateTimeStamp time
DateTimeStamp for current date.


dayofweek

protected int dayofweek
Day of week, range: [1-7] == [Monday - Sunday]


dayofyear

protected int dayofyear
Day of year, range: [1-365] or [1-366]


leap

protected boolean leap
Leap year flag.


weekofyear

protected int weekofyear
Week of year, range: [1-52] or [1-53]


weekofmonth

protected int weekofmonth
Week of month.


jdate

protected JulianDateStamp jdate
Current Julian Date.


JD_1970

public static final JulianDateStamp JD_1970
Julian Date for 1970-01-01T00:00:00 (Thursday).


JD_2001

public static final JulianDateStamp JD_2001
Julian Date for 2001-01-01T00:00:00 (Monday).


trackDST

protected boolean trackDST

monthFix

protected boolean monthFix

timezone

protected java.util.TimeZone timezone

locale

protected java.util.Locale locale

format

protected java.lang.String format

jdtFormatter

protected JdtFormatter jdtFormatter

firstDayOfWeek

protected int firstDayOfWeek

mustHaveDayOfFirstWeek

protected int mustHaveDayOfFirstWeek

minDaysInFirstWeek

protected int minDaysInFirstWeek
Constructor Detail

JDateTime

public JDateTime(int year,
                 int month,
                 int day,
                 int hour,
                 int minute,
                 int second,
                 int millisecond)
Constructor that set date and time.

Parameters:
year - year to set
month - month to set
day - day to set
hour - hours to set
minute - minutes to set
second - seconds to set
millisecond - milliseconds to set
See Also:
set(int, int, int, int, int, int, int)

JDateTime

public JDateTime(int year,
                 int month,
                 int day)
Constructor that sets just date. Time is set to 00:00:00.

Parameters:
year - year to set
month - month to set
day - day to set
See Also:
set(int, int, int)

JDateTime

public JDateTime(long millis)
Constructor that sets current time specified as time in milliseconds, from the midnight, January 1, 1970 UTC.

Parameters:
millis - time in milliseconds, from the midnight, January 1, 1970 UTC
See Also:
setTimeInMillis(long )

JDateTime

public JDateTime()
Constructor that sets current local date and time.


JDateTime

public JDateTime(java.util.Calendar calendar)
Creates JDateTime from Calendar.


JDateTime

public JDateTime(java.util.Date date)
Creates JDateTime from Date.


JDateTime

public JDateTime(DateTimeStamp dts)
Creates JDateTime from DateTimeStamp.


JDateTime

public JDateTime(JulianDateStamp jds)
Creates JDateTime from JulianDateStamp.


JDateTime

public JDateTime(double jd)
Creates JDateTime from double that represents JD.


JDateTime

public JDateTime(java.lang.String src)
Creates JDateTime from a string.


JDateTime

public JDateTime(java.lang.String src,
                 java.lang.String template)
Creates JDateTime from a string, using specified template.


JDateTime

public JDateTime(java.lang.String src,
                 JdtFormat jdtFormat)
Method Detail

getDateTimeStamp

public DateTimeStamp getDateTimeStamp()
Returns current DateTimeStamp. Returned instance is still used internally (i.e. it is not cloned before returning).


setDateTimeStamp

public void setDateTimeStamp(DateTimeStamp dts)
Loads current date time information.


setJulianDate

public void setJulianDate(JulianDateStamp jds)
Sets current Julian Date. This is the core of the JDateTime class and it is used by all other classes. This method performs all calculations required for whole class.

Parameters:
jds - current julian date

getJulianDate

public JulianDateStamp getJulianDate()
Returns JulianDateStamp. It is the same instance used internally.


getJulianDayNumber

public int getJulianDayNumber()
Returns JDN. Note that JDN is not equal to integer part of julian date. It is calculated by rounding to the nearest integer.


set

public void set(int year,
                int month,
                int day,
                int hour,
                int minute,
                int second,
                int millisecond)
Core method that sets date and time. All others set() methods use this one. Milliseconds are truncated after 3rd digit.

Parameters:
year - year to set
month - month to set
day - day to set
hour - hour to set
minute - minute to set
second - second to set

add

public void add(int year,
                int month,
                int day,
                int hour,
                int minute,
                int second,
                int millisecond,
                boolean monthFix)
Adds time to current time. The main add method - all other add() methods must use this one.

There are 2 different kinds of addings, when months are added:

Parameters:
year - delta year
month - delta month
day - delta days
hour - delta hours
minute - delta minutes
second - delta seconds
monthFix - true for month fixing, false otherwise

addNoDST

protected void addNoDST(int year,
                        int month,
                        int day,
                        int hour,
                        int minute,
                        int second,
                        int millisecond,
                        boolean monthFix)

sub

public void sub(int year,
                int month,
                int day,
                int hour,
                int minute,
                int second,
                int millisecond,
                boolean monthFix)

add

public void add(int year,
                int month,
                int day,
                int hour,
                int minute,
                int second,
                int millisecond)
Performs time adding with preset value of monthFix attribute.

Parameters:
year - delta year
month - delta month
day - delta days
hour - delta hours
minute - delta minutes
second - delta seconds
See Also:
add(int, int, int, int, int, int, int, boolean)

sub

public void sub(int year,
                int month,
                int day,
                int hour,
                int minute,
                int second,
                int millisecond)

add

public void add(int year,
                int month,
                int day,
                boolean monthFix)
Adds date, leaving time unchanged.

Parameters:
year - years to add
month - months to add
day - days to add
monthFix - true for month fixing, false otherwise
See Also:
add(int, int, int, int, int, int, int, boolean)

sub

public void sub(int year,
                int month,
                int day,
                boolean monthFix)

add

public void add(int year,
                int month,
                int day)
Adds date, leaving time unchanged, with preset value of monthFix. attribute.

Parameters:
year - years to add
month - months to add
day - days to add
See Also:
add(int, int, int, boolean)

sub

public void sub(int year,
                int month,
                int day)

addTime

public void addTime(int hour,
                    int minute,
                    int second,
                    int millisecond,
                    boolean monthFix)
Adds time.

Parameters:
hour - hours to add
minute - minutes to add
second - seconds to add
monthFix - true for month fixing, false otherwise
See Also:
add(int, int, int, int, int, int, int)

subTime

public void subTime(int hour,
                    int minute,
                    int second,
                    int millisecond,
                    boolean monthFix)

addTime

public void addTime(int hour,
                    int minute,
                    int second,
                    boolean monthFix)

subTime

public void subTime(int hour,
                    int minute,
                    int second,
                    boolean monthFix)

addTime

public void addTime(int hour,
                    int minute,
                    int second,
                    int millisecond)
Adds time, with preset value of monthFix.

Parameters:
hour - hours to add
minute - minutes to add
second - seconds to add
See Also:
addTime(int, int, int, int, boolean)

subTime

public void subTime(int hour,
                    int minute,
                    int second,
                    int millisecond)

addTime

public void addTime(int hour,
                    int minute,
                    int second)

subTime

public void subTime(int hour,
                    int minute,
                    int second)

addYear

public void addYear(int y,
                    boolean monthFix)
Adds year.

Parameters:
y - year to add
monthFix - true for month fixing, false otherwise

subYear

public void subYear(int y,
                    boolean monthFix)

addYear

public void addYear(int y)
Adds year, with preset value of monthFix.

Parameters:
y - year to add

subYear

public void subYear(int y)

addMonth

public void addMonth(int m,
                     boolean monthFix)
Adds month.

Parameters:
m - month to add
monthFix - true for month fixing, false otherwise

subMonth

public void subMonth(int m,
                     boolean monthFix)

addMonth

public void addMonth(int m)
Adds month, with preset value of monthFix.

Parameters:
m - month to add

subMonth

public void subMonth(int m)

addDay

public void addDay(int d,
                   boolean monthFix)
Adds days.

Parameters:
d - days to add
monthFix - true for month fixing, false otherwise

subDay

public void subDay(int d,
                   boolean monthFix)

addDay

public void addDay(int d)
Adds days, with preset value of monthFix.

Parameters:
d - days to add

subDay

public void subDay(int d)

addHour

public void addHour(int h,
                    boolean monthFix)
Adds hours.

Parameters:
h - hours to add
monthFix - true for month fixing, false otherwise

subHour

public void subHour(int h,
                    boolean monthFix)

addHour

public void addHour(int h)
Adds hours, with preset value of monthFix.

Parameters:
h - hours to add

subHour

public void subHour(int h)

addMinute

public void addMinute(int m,
                      boolean monthFix)
Adds minutes.

Parameters:
m - minutes to add.
monthFix - true for month fixing, false otherwise

subMinute

public void subMinute(int m,
                      boolean monthFix)

addMinute

public void addMinute(int m)
Adds minutes, with preset value of monthFix.

Parameters:
m - minutes to add.

subMinute

public void subMinute(int m)

addSecond

public void addSecond(int s,
                      boolean monthFix)
Adds seconds.

Parameters:
s - seconds to add
monthFix - true for month fixing, false otherwise

subSecond

public void subSecond(int s,
                      boolean monthFix)

addSecond

public void addSecond(int s)
Adds seconds, with preset value of monthFix.

Parameters:
s - seconds to add

subSecond

public void subSecond(int s)

addMillisecond

public void addMillisecond(int ms,
                           boolean monthFix)
Adds milliseconds.

Parameters:
ms - milliseconds to add
monthFix - true for month fixing, false otherwise

subMillisecond

public void subMillisecond(int ms,
                           boolean monthFix)

addMillisecond

public void addMillisecond(int ms)
Adds milliseconds, with preset value of monthFix.

Parameters:
ms - milliseconds to add

subMillisecond

public void subMillisecond(int ms)

set

public void set(int year,
                int month,
                int day)
Sets date, time is set to midnight (00:00:00.000).

Parameters:
year - year to set
month - month to set
day - day to set

setTime

public void setTime(int hour,
                    int minute,
                    int second,
                    int millisecond)
Sets time, date is unchanged.

Parameters:
hour - hours to set
minute - minutes to set
second - seconds to set

setDate

public void setDate(int year,
                    int month,
                    int day)
Sets date, time remains unchanged.

Parameters:
year - year
month - month
day - day

setTimeInMillis

public void setTimeInMillis(long millis)
Sets the time based on current time in milliseconds. Current time is calculated from the midnight, January 1, 1970 UTC.

Calculation is divided in two steps, due to precision issues.

Parameters:
millis - time in milliseconds, from the midnight, January 1, 1970 UTC

getTimeInMillis

public long getTimeInMillis()
Returns time based on current time in milliseconds. Current time is calculated from the midnight, January 1, 1970 UTC.

Due to possible huge values calculation is divided in two steps: first for fractional difference, and then for integer parts.

Returns:
time in milliseconds, from the midnight, January 1, 1970 UTC

setYear

public void setYear(int y)
Sets current year.

Parameters:
y - year to set

setMonth

public void setMonth(int m)
Sets current month.

Parameters:
m - month to set

setDay

public void setDay(int d)
Sets current day of month.

Parameters:
d - day to set

setHour

public void setHour(int h)
Set current hour.

Parameters:
h - hour to set

setMinute

public void setMinute(int m)
Set current minute.

Parameters:
m - minutes to set

setSecond

public void setSecond(int s)
Sets current second.

Parameters:
s - seconds and milliseconds to set

setSecond

public void setSecond(int s,
                      int m)

setMillisecond

public void setMillisecond(int m)
Sets current millisecond.

Parameters:
m - milliseconds to set

getYear

public int getYear()
Returns current year.


getMonth

public int getMonth()
Returns current month.


getDay

public int getDay()
Returns current day of month.

See Also:
getDayOfMonth()

getDayOfMonth

public int getDayOfMonth()
Returns current day of month.

See Also:
getDay()

getHour

public int getHour()
Returns current hour.


getMinute

public int getMinute()
Returns current minutes.


getSecond

public int getSecond()
Return current seconds. For an integer value, just cast the returned value.


getMillisecond

public int getMillisecond()
Returns current milliseconds.


getDayOfWeek

public int getDayOfWeek()
Returns current day of week.


getDayOfYear

public int getDayOfYear()
Returns current day of year.


isLeapYear

public boolean isLeapYear()
Returns true if current year is leap year.


getWeekOfYear

public int getWeekOfYear()
Returns current week of year.


getWeekOfMonth

public int getWeekOfMonth()
Returns current week of month.


getMonthLength

public int getMonthLength(int m)
Returns the length of the specified month in days.


getMonthLength

public int getMonthLength()
Returns the length of the current month in days.


getEra

public int getEra()
Returns era: AD(1) or BC(0).


getMillisOfDay

public int getMillisOfDay()
Calculates the number of milliseconds of a day.


setCurrentTime

public void setCurrentTime()
Sets current local date and time.


setDateTime

public void setDateTime(java.util.Calendar calendar)
Sets current date and time from Calendar.


setDateTime

public void setDateTime(java.util.Date date)
Sets current date and time from Date.


convertToDate

public java.util.Date convertToDate()
Converts to Date instance.


convertToCalendar

public java.util.Calendar convertToCalendar()
Converts to Calendar instance.


convertToSqlDate

public java.sql.Date convertToSqlDate()
Converts to java.sql.Date instance.


convertToSqlTime

public java.sql.Time convertToSqlTime()
Converts to Time instance.


convertToSqlTimestamp

public java.sql.Timestamp convertToSqlTimestamp()
Converts to Timestamp instance.


isTrackDST

public boolean isTrackDST()

setTrackDST

public void setTrackDST(boolean trackDST)

isMonthFix

public boolean isMonthFix()
Returns true if month fix is active.


setMonthFix

public void setMonthFix(boolean monthFix)
Sets custom month fix value.


changeTimeZone

public void changeTimeZone(java.util.TimeZone timezone)
Changes current timezone. Current time is changed if time zone has been changed.


setTimeZone

public void setTimeZone(java.util.TimeZone timezone)
Sets time zone without changing the time.


getTimeZone

public java.util.TimeZone getTimeZone()
Return currently active time zone.


isInDaylightTime

public boolean isInDaylightTime()
Returns true if current date is in daylight savings time in the time zone.


setLocale

public void setLocale(java.util.Locale locale)
Sets custom locale.


getLocale

public java.util.Locale getLocale()
Return currently active locale.


setFormat

public void setFormat(java.lang.String format)
Defines default format.


getFormat

public java.lang.String getFormat()
Returns format.


setJdtFormatter

public void setJdtFormatter(JdtFormatter jdtFormatter)
Defines custom formatter.


getJdtFormatter

public JdtFormatter getJdtFormatter()
Returns actual JdtFormatter.


setJdtFormat

public void setJdtFormat(JdtFormat jdtFormat)
Sets both format and formatter from provided JdtFormat.


toString

public java.lang.String toString(java.lang.String format)
Returns string representation of date/time in specified format.


toString

public java.lang.String toString()
Returns spring representation of current date/time in currently active format.

Overrides:
toString in class java.lang.Object
See Also:
getFormat()

toString

public java.lang.String toString(JdtFormat jdtFormat)

parse

public void parse(java.lang.String src,
                  java.lang.String format)
Sets date/time from a string given in provided template.

Parameters:
src - string containing date time information
format - format template

parse

public void parse(java.lang.String src)
Sets date/time from a string and currently active template.

Parameters:
src - string containing date time information
See Also:
getFormat()

parse

public void parse(java.lang.String src,
                  JdtFormat jdtFormat)

isValid

public boolean isValid(java.lang.String s)
Checks if some string represents a valid date using actual template.

Returns:
true if date is valid, otherwise false

isValid

public boolean isValid(java.lang.String s,
                       java.lang.String template)
Checks if some string represents a valid date using provided template.

Returns:
true if date is valid, otherwise false

setWeekDefinition

public void setWeekDefinition(int start,
                              int must)
Defines week definitions.

Parameters:
start - first day in week, [1-7],
must - must have day of the 1st week, [1-7]

getFirstDayOfWeek

public int getFirstDayOfWeek()
Returns actual the first day of the week.


getMustHaveDayOfFirstWeek

public int getMustHaveDayOfFirstWeek()
Returns actual must have day of the 1st week.


getMinDaysInFirstWeek

public int getMinDaysInFirstWeek()
Returns actual minimal number of days of the first week. It is calculated from must have day of the first week.

Returns:
minimal number of days of the first week

setWeekDefinitionAlt

public void setWeekDefinitionAlt(int start,
                                 int min)
Defines week alternatively.

Parameters:
start - first day in week
min - minimal days of week

equals

public boolean equals(java.lang.Object obj)
Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

clone

public JDateTime clone()
Overrides:
clone in class java.lang.Object

compareTo

public int compareTo(java.lang.Object o)
Compares current JDateTime object with another one, up to 1 millisecond.

Specified by:
compareTo in interface java.lang.Comparable
Parameters:
o - JDateTime to compare
Returns:
-1 if the current object is less than the argument, 0 if the argument is equal, and 1 if the current object is greater than the argument

compareTo

public int compareTo(JDateTime jd)

compareDateTo

public int compareDateTo(JDateTime jd)
Compares current JDateTime date with another date. Time component is ignored.


isAfter

public boolean isAfter(JDateTime then)
Returns true if current time is after then provided time.


isBefore

public boolean isBefore(JDateTime then)
Returns true if current time is before then provided time.


isAfterDate

public boolean isAfterDate(JDateTime then)
Returns true if current date is after then provided date. Time component is ignored.


isBeforeDate

public boolean isBeforeDate(JDateTime then)
Returns true if current date is before then provided date. Time component is ignored.


daysBetween

public int daysBetween(JDateTime then)
Returns number of full days between two dates.


daysBetween

public int daysBetween(JulianDateStamp then)
Returns number of full days between two dates.


getJulianDateDouble

public double getJulianDateDouble()
Returns JD as double value.


setJulianDate

public void setJulianDate(double jd)
Sets JD.


getReducedJulianDate

public JulianDateStamp getReducedJulianDate()
Returns Reduced Julian Date (RJD), used by astronomers. RJD = JD − 2400000


getReducedJulianDateDouble

public double getReducedJulianDateDouble()

setReducedJulianDate

public void setReducedJulianDate(double rjd)

getModifiedJulianDate

public JulianDateStamp getModifiedJulianDate()
Returns Modified Julian Date (MJD), where date starts from midnight rather than noon. RJD = JD − 2400000.5


getModifiedJulianDateDouble

public double getModifiedJulianDateDouble()

setModifiedJulianDate

public void setModifiedJulianDate(double mjd)

getTruncatedJulianDate

public JulianDateStamp getTruncatedJulianDate()
Returns Truncated Julian Day (TJD), introduced by NASA for the space program. TJD began at midnight at the beginning of May 24, 1968 (Friday).


getTruncatedJulianDateDouble

public double getTruncatedJulianDateDouble()

setTruncatedJulianDate

public void setTruncatedJulianDate(double tjd)

equalsDate

public boolean equalsDate(int year,
                          int month,
                          int day)
Returns true if provided date is equal to current one. May be used for date validation test.


equalsDate

public boolean equalsDate(JDateTime date)
Returns true if two dates are equal. Time component is ignored.


equalsTime

public boolean equalsTime(JDateTime date)
Returns true if two times are equal. Date component is ignored.



Copyright © 2003-2012 Jodd Team