jodd.datetime
Class TimeUtil

java.lang.Object
  extended byjodd.datetime.TimeUtil

public class TimeUtil
extends java.lang.Object

Date time calculations and utilities. TimeUtil is used by JDateTime and it contains few utilities that may be used elswhere, although JDateTime is recomended for all time manipulation.


Constructor Summary
TimeUtil()
           
 
Method Summary
static int dayOfYear(int year, int month, int day)
          Calculates day of year from given time stamp.
static DateTimeStamp fromJulianDate(double JD)
          Calculates time stamp from Astronomical Julian Date.
static DateTimeStamp fromJulianDate(JulianDateStamp jds)
          Calculates time stamp from Astronomical Julian Date.
static int getMonthLength(int year, int m)
          Returns the length of the specified month in days.
static boolean isLeapYear(int y)
          Check if the given year is leap year.
static boolean isValidDate(int year, int month, int day)
          Checks if date is valid.
static boolean isValidDateTime(DateTimeStamp dts)
          Checks if date and time are valid.
static boolean isValidDateTime(int year, int month, int day, int hour, int minute, double second)
          Checks if date and time are valid.
static boolean isValidTime(int hour, int minute, double second)
          Checks if time is valid.
static JulianDateStamp toJulianDate(DateTimeStamp time)
          Calculates Astronomical Julian Date from given time stamp.
static JulianDateStamp toJulianDate(int year, int month, int day, int hour, int minute, double second)
          Calculates Astronomical Julian Date from given time.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TimeUtil

public TimeUtil()
Method Detail

dayOfYear

public static int dayOfYear(int year,
                            int month,
                            int day)
Calculates day of year from given time stamp. It may not work for some dates in 1582.

Parameters:
year -
month -
day -
Returns:
day of year in range: [1-366]

isLeapYear

public static boolean isLeapYear(int y)
Check if the given year is leap year.

Parameters:
y - year to check
Returns:
true if the year is a leap year

getMonthLength

public static int getMonthLength(int year,
                                 int m)
Returns the length of the specified month in days. Month is 1 for January and 12 for December.

Parameters:
year - year
m - month
Returns:
length of the specified month in days

isValidDate

public static boolean isValidDate(int year,
                                  int month,
                                  int day)
Checks if date is valid.

Parameters:
year - year to check
month - month to check
day - day to check
Returns:
true if date is valid, otherwise false

isValidTime

public static boolean isValidTime(int hour,
                                  int minute,
                                  double second)
Checks if time is valid.

Parameters:
hour - hour to check
minute - minute to check
second - second to check
Returns:
true if time is valid, otherwise false

isValidDateTime

public static boolean isValidDateTime(int year,
                                      int month,
                                      int day,
                                      int hour,
                                      int minute,
                                      double second)
Checks if date and time are valid.

Parameters:
year - year to check
month - month to check
day - day to check
hour - hour to check
minute - minute to check
second - second to check
Returns:
true if date and time are valid, otherwise false

isValidDateTime

public static boolean isValidDateTime(DateTimeStamp dts)
Checks if date and time are valid.

Parameters:
dts - date/time stamp
Returns:
true if date and time are valid, otherwise false

toJulianDate

public static JulianDateStamp toJulianDate(DateTimeStamp time)
Calculates Astronomical Julian Date from given time stamp.

Parameters:
time -
Returns:
Julian Date stamp

toJulianDate

public static JulianDateStamp toJulianDate(int year,
                                           int month,
                                           int day,
                                           int hour,
                                           int minute,
                                           double second)
Calculates Astronomical Julian Date from given time.

Astronomical Julian Dates are counting from noon of the January 1st, -4712 (julian date 0 is -4712/01/01 12:00:00). Zero year exist. Julian Date is always GMT, there are no timezones.

Algorithm based on Numerical Recipesin C, 2nd ed., Cambridge University Press 1992, modified and enhanced by Igor Spasic.

Parameters:
year - year
month - month
day - day
hour - hour
minute - minute
second - second
Returns:
julian time stamp

fromJulianDate

public static DateTimeStamp fromJulianDate(double JD)
Calculates time stamp from Astronomical Julian Date.

Parameters:
JD - julian date
Returns:
time stamp

fromJulianDate

public static DateTimeStamp fromJulianDate(JulianDateStamp jds)
Calculates time stamp from Astronomical Julian Date. Algorithm based on Numerical Recipesin C, 2nd ed., Cambridge University Press 1992.

Parameters:
jds - julian date stamp
Returns:
time stamp


Jodd v0.24.5 Javadoc