jodd.datetime
Class TimeUtil

java.lang.Object
  extended by jodd.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 elsewhere, although JDateTime is recommended for all time manipulation.


Field Summary
static java.text.SimpleDateFormat HTTP_DATE_FORMAT
           
static long MILLIS_IN_DAY
           
static int SECONDS_IN_DAY
           
 
Constructor Summary
TimeUtil()
           
 
Method Summary
static int dayOfYear(int year, int month, int day)
          Calculates day of year from given time stamp.
static java.lang.String formatHttpDate(long millis)
          Formats time to HTTP date format.
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, int second, int millisecond)
          Checks if date and time are valid.
static boolean isValidTime(int hour, int minute, int second, int millisecond)
          Checks if time is valid.
static int toCalendarDayOfWeek(int dayOfWeek)
          Returns Calendar day-of-week from provided JDateTime.
static int toCalendarMonth(int month)
          Returns Calendar month from provided JDateTime month.
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, int second, int millisecond)
          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
 

Field Detail

SECONDS_IN_DAY

public static final int SECONDS_IN_DAY
See Also:
Constant Field Values

MILLIS_IN_DAY

public static final long MILLIS_IN_DAY
See Also:
Constant Field Values

HTTP_DATE_FORMAT

public static final java.text.SimpleDateFormat HTTP_DATE_FORMAT
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.

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

isLeapYear

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

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. It works only for years after 1582.

Returns:
length of the specified month in days

isValidDate

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

Returns:
true if date is valid, otherwise false

isValidTime

public static boolean isValidTime(int hour,
                                  int minute,
                                  int second,
                                  int millisecond)
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,
                                      int second,
                                      int millisecond)
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.

Returns:
Julian Date stamp

toJulianDate

public static JulianDateStamp toJulianDate(int year,
                                           int month,
                                           int day,
                                           int hour,
                                           int minute,
                                           int second,
                                           int millisecond)
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

toCalendarMonth

public static int toCalendarMonth(int month)
Returns Calendar month from provided JDateTime month.


toCalendarDayOfWeek

public static int toCalendarDayOfWeek(int dayOfWeek)
Returns Calendar day-of-week from provided JDateTime.


formatHttpDate

public static java.lang.String formatHttpDate(long millis)
Formats time to HTTP date format.



Copyright © 2003-2012 Jodd Team