org.mbari.util
Class TimeUtil

java.lang.Object
  extended byorg.mbari.util.TimeUtil

public class TimeUtil
extends java.lang.Object

Utilities for converting between diferent types of commonly used scientific date formats

Author:
Brian Schlining

Constructor Summary
TimeUtil()
           
 
Method Summary
static int dateToDayOfYear(java.util.Date date)
           
static int dateToDayOfYear(long millis)
           
static java.util.Date dayOfYearToDate(double dayOfYear, double year)
          Convert the Day of a Year to a Date object.
static java.util.Date dayOfYearToDate(double dayOfYear, int year)
          Convert the Day of a Year to a Date object
static java.util.Date dayOfYearToDate(float dayOfYear, int year)
          Convert the Day of a Year to a Date object
static java.util.Date dayOfYearToDate(int dayOfYear, int year)
          Convert the Day of a Year to a Date object
static double getJulianDate(java.util.Date date)
           
static double getJulianDate(long millis)
          Julian Date (not Day of Year).
static double[] getJulianDate(long[] millis)
           
static boolean isLeapYear(double year)
          Check to see if a year is a leap year
static boolean isLeapYear(int year)
          Check to see if a year is a leap year
static long serialDaysToUtc(double serialDay)
          Convert from serial days, the format used by matlab, (Serial days.01 jan 0000 00:00:00 = Day 1) to UTC (milliseconds since 01 Jan 1970 00:00:00).
static double toSerialDays(java.util.Date d)
          Convert a date object ot serial days
static double utcToSerialDays(double utc)
          Convert from UTC (milliseconds since 01 Jan 1970 00:00:00) to serial days, the format used by matlab (Serial days.
static double utcToSerialDays(long utc)
          Convert from UTC (milliseconds since 01 Jan 1970 00:00:00) to serial days, the format used by matlab (Serial days.
 
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

dayOfYearToDate

public static final java.util.Date dayOfYearToDate(double dayOfYear,
                                                   double year)
Convert the Day of a Year to a Date object. This method can handle days of the year greater than 365 (or 366 for leap years). It simple wraps the day around to the next year. For example: doyToDate(367, 1999) will return a Date object for Jan 2, 2000. All times must be in GMT.

Parameters:
dayOfYear - The decimal day of the year. Jan 01, 00:00:00 = 1
year - The year
Returns:
A Date object for the dayOfYear specified

dayOfYearToDate

public static final java.util.Date dayOfYearToDate(int dayOfYear,
                                                   int year)
Convert the Day of a Year to a Date object

Parameters:
dayOfYear - The decimal day of the year. Jan 01, 00:00:00 = 1
year - The year
Returns:
A Date object for the dayOfYear specified

dayOfYearToDate

public static final java.util.Date dayOfYearToDate(float dayOfYear,
                                                   int year)
Convert the Day of a Year to a Date object

Parameters:
dayOfYear - The decimal day of the year. Jan 01, 00:00:00 = 1
year - The year
Returns:
A Date object for the dayOfYear specified

dayOfYearToDate

public static final java.util.Date dayOfYearToDate(double dayOfYear,
                                                   int year)
Convert the Day of a Year to a Date object

Parameters:
dayOfYear - The decimal day of the year. Jan 01, 00:00:00 = 1
year - The year
Returns:
A Date object for the dayOfYear specified

utcToSerialDays

public static final double utcToSerialDays(long utc)
Convert from UTC (milliseconds since 01 Jan 1970 00:00:00) to serial days, the format used by matlab (Serial days. 01 jan 0000 00:00:00 = Day 1).

Parameters:
utc - time in UTC
Returns:
Serial day format utilized by matlab

utcToSerialDays

public static final double utcToSerialDays(double utc)
Convert from UTC (milliseconds since 01 Jan 1970 00:00:00) to serial days, the format used by matlab (Serial days. 01 jan 0000 00:00:00 = Day 1).

Parameters:
utc - time in UTC
Returns:
Serial day format utilized by matlab

serialDaysToUtc

public static final long serialDaysToUtc(double serialDay)
Convert from serial days, the format used by matlab, (Serial days.01 jan 0000 00:00:00 = Day 1) to UTC (milliseconds since 01 Jan 1970 00:00:00).

Parameters:
serialDay - The date value to be conerted
Returns:
UTC time

isLeapYear

public static final boolean isLeapYear(double year)
Check to see if a year is a leap year

Parameters:
year - The year in question
Returns:
True if the year is a leap year, false otherwise

isLeapYear

public static final boolean isLeapYear(int year)
Check to see if a year is a leap year

Parameters:
year - The year in question
Returns:
True if the year is a leap year, false otherwise

toSerialDays

public static double toSerialDays(java.util.Date d)
Convert a date object ot serial days

Parameters:
d - The data oject to be converted
Returns:
Serial date corresponding to the d

dateToDayOfYear

public static int dateToDayOfYear(java.util.Date date)

dateToDayOfYear

public static int dateToDayOfYear(long millis)

getJulianDate

public static double getJulianDate(java.util.Date date)

getJulianDate

public static double[] getJulianDate(long[] millis)

getJulianDate

public static double getJulianDate(long millis)
Julian Date (not Day of Year). Check values against matlabs juldate_.m on 14 Nov 2000. Found some problems so I checked it again on 16 Nov 2000. It appears to match exactly now.