ucar.unidata.util
Class DateUtil

java.lang.Object
  extended by ucar.unidata.util.DateUtil

public class DateUtil
extends java.lang.Object

A set of date oriented utilities

Since:
May 4, 2007 1:01:53 PM
Author:
edavis and the IDV development team

Field Summary
static java.lang.String[] DATE_FORMATS
          A set of date formats
static java.lang.String[] DATE_PATTERNS
          a set of regular expressions that go along with the below DATE_FORMATS
static long MILLIS
          milliseconds in a millisecond
static long MILLIS_CENTURY
          milliseconds in a century (approximately)
static long MILLIS_DAY
          milliseconds in a day
static long MILLIS_DECADE
          milliseconds in a decade (approximately)
static long MILLIS_HOUR
          milliseconds in an hour
static long MILLIS_MILLENIUM
          milliseconds in a century (approximately)
static long MILLIS_MINUTE
          milliseconds in a minute
static long MILLIS_MONTH
          milliseconds in a month (approximately)
static long MILLIS_SECOND
          milliseconds in a second
static long MILLIS_WEEK
          milliseconds in a week
static long MILLIS_YEAR
          milliseconds in a year (approximately)
static java.lang.String[] MONTH_NAMES
          _more_
static java.util.TimeZone TIMEZONE_GMT
          timezone
 
Constructor Summary
DateUtil()
           
 
Method Summary
static long daysToMillis(double days)
          utility to convert a given number of days to milliseconds
static java.util.Date decodeWMODate(java.lang.String wmoDate, java.util.Date baseDate)
          Decode a date from a WMO header of the form ddHHmm.
static java.text.SimpleDateFormat findFormatter(java.lang.String dateString)
          This finds the SDF to use for the given date string
static java.lang.String getCurrentSystemTimeAsISO8601()
          format current time
static java.util.Date[] getDateRange(java.lang.String fromDate, java.lang.String toDate, java.util.Date dflt)
          This gets a date range based on the text dates.
static java.util.Date getRelativeDate(java.util.Date from, java.lang.String relativeTimeString)
          Get a new date relative to the given date.
static java.lang.String getTimeAsISO8601(java.util.Date date)
          format time
static java.lang.String getTimeAsISO8601(long time)
          format time
static long hoursToMillis(double hour)
          utility to convert a given number of hours to milliseconds
static void main(java.lang.String[] args)
          main
static java.util.Date max(java.util.Date date1, java.util.Date date2)
          Get the maximum of the 2 dates
static double millisToHours(double millis)
          _more_
static double millisToMinutes(double millis)
          utility to convert a given number of milliseconds to minutes
static java.util.Date min(java.util.Date date1, java.util.Date date2)
          Get the minimum of the 2 dates
static long minutesToMillis(double minutes)
          utility to convert a given number of minutes to milliseconds
static java.util.Date parse(java.lang.String s)
          Parse the date string
static java.util.Date parseRelative(java.util.Date baseDate, java.lang.String s, int roundDays)
          parse the date string (s) (e.g., -1 hour) that is relative to the given baseDate
static long parseRelativeTimeString(java.lang.String relativeTimeString)
          Return the delta number of milliseconds specified in the relative time string
static java.util.Date roundByDay(java.util.Date dttm, int day)
          Rounds up or down (if negative) the number of days.
static double[] toSeconds(java.lang.String[] s)
          parse the array of date strings and returns the date as seconds
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MONTH_NAMES

public static final java.lang.String[] MONTH_NAMES
_more_


MILLIS

public static final long MILLIS
milliseconds in a millisecond

See Also:
Constant Field Values

MILLIS_SECOND

public static final long MILLIS_SECOND
milliseconds in a second

See Also:
Constant Field Values

MILLIS_MINUTE

public static final long MILLIS_MINUTE
milliseconds in a minute

See Also:
Constant Field Values

MILLIS_HOUR

public static final long MILLIS_HOUR
milliseconds in an hour

See Also:
Constant Field Values

MILLIS_DAY

public static final long MILLIS_DAY
milliseconds in a day

See Also:
Constant Field Values

MILLIS_WEEK

public static final long MILLIS_WEEK
milliseconds in a week

See Also:
Constant Field Values

MILLIS_MONTH

public static final long MILLIS_MONTH
milliseconds in a month (approximately)

See Also:
Constant Field Values

MILLIS_YEAR

public static final long MILLIS_YEAR
milliseconds in a year (approximately)

See Also:
Constant Field Values

MILLIS_DECADE

public static final long MILLIS_DECADE
milliseconds in a decade (approximately)

See Also:
Constant Field Values

MILLIS_CENTURY

public static final long MILLIS_CENTURY
milliseconds in a century (approximately)

See Also:
Constant Field Values

MILLIS_MILLENIUM

public static final long MILLIS_MILLENIUM
milliseconds in a century (approximately)

See Also:
Constant Field Values

TIMEZONE_GMT

public static final java.util.TimeZone TIMEZONE_GMT
timezone


DATE_PATTERNS

public static final java.lang.String[] DATE_PATTERNS
a set of regular expressions that go along with the below DATE_FORMATS


DATE_FORMATS

public static final java.lang.String[] DATE_FORMATS
A set of date formats

Constructor Detail

DateUtil

public DateUtil()
Method Detail

getCurrentSystemTimeAsISO8601

public static java.lang.String getCurrentSystemTimeAsISO8601()
format current time

Returns:
current time formatted

getTimeAsISO8601

public static java.lang.String getTimeAsISO8601(java.util.Date date)
format time

Parameters:
date - date
Returns:
formatted time

min

public static java.util.Date min(java.util.Date date1,
                                 java.util.Date date2)
Get the minimum of the 2 dates

Parameters:
date1 - date1
date2 - date2
Returns:
The minimum of the 2 dates

max

public static java.util.Date max(java.util.Date date1,
                                 java.util.Date date2)
Get the maximum of the 2 dates

Parameters:
date1 - date1
date2 - date2
Returns:
The maximum of the 2 dates

getTimeAsISO8601

public static java.lang.String getTimeAsISO8601(long time)
format time

Parameters:
time - time
Returns:
formatted time

roundByDay

public static java.util.Date roundByDay(java.util.Date dttm,
                                        int day)
Rounds up or down (if negative) the number of days.

Parameters:
dttm - date to round
day - number of days
Returns:
rounded date.

findFormatter

public static java.text.SimpleDateFormat findFormatter(java.lang.String dateString)
This finds the SDF to use for the given date string

Parameters:
dateString - example date
Returns:
formatter to use

getDateRange

public static java.util.Date[] getDateRange(java.lang.String fromDate,
                                            java.lang.String toDate,
                                            java.util.Date dflt)
                                     throws java.text.ParseException
This gets a date range based on the text dates. The incoming dates can be of the form:
 absolute date
 now (for current time)
 relative date (e.g., (offset unit), -5 seconds, +2 hours, +5 days, -3 weeks, -1 month
 This is calculated relative to the other date, e.g:
 -1 hour, now

 

Parameters:
fromDate - from date
toDate - to date
dflt - base default date
Returns:
date range
Throws:
java.text.ParseException - On badness

parseRelative

public static java.util.Date parseRelative(java.util.Date baseDate,
                                           java.lang.String s,
                                           int roundDays)
                                    throws java.text.ParseException
parse the date string (s) (e.g., -1 hour) that is relative to the given baseDate

Parameters:
baseDate - base date
s - date string
roundDays - round down or up the given number of days
Returns:
date
Throws:
java.text.ParseException - on badness

parse

public static java.util.Date parse(java.lang.String s)
                            throws java.text.ParseException
Parse the date string

Parameters:
s - date string
Returns:
date
Throws:
java.text.ParseException - on badness

toSeconds

public static double[] toSeconds(java.lang.String[] s)
                          throws java.text.ParseException
parse the array of date strings and returns the date as seconds

Parameters:
s - array of date strings
Returns:
array of seconds
Throws:
java.text.ParseException - On badness

daysToMillis

public static long daysToMillis(double days)
utility to convert a given number of days to milliseconds

Parameters:
days - days
Returns:
milliseconds

hoursToMillis

public static long hoursToMillis(double hour)
utility to convert a given number of hours to milliseconds

Parameters:
hour - hours
Returns:
milliseconds

millisToMinutes

public static double millisToMinutes(double millis)
utility to convert a given number of milliseconds to minutes

Parameters:
millis - milliseconds
Returns:
minutes

millisToHours

public static double millisToHours(double millis)
_more_

Parameters:
millis - _more_
Returns:
_more_

minutesToMillis

public static long minutesToMillis(double minutes)
utility to convert a given number of minutes to milliseconds

Parameters:
minutes - minutes
Returns:
milliseconds

getRelativeDate

public static java.util.Date getRelativeDate(java.util.Date from,
                                             java.lang.String relativeTimeString)
Get a new date relative to the given date.

Parameters:
from - base date
relativeTimeString - Relative time string, e.g., -1 hour
Returns:
new date

parseRelativeTimeString

public static long parseRelativeTimeString(java.lang.String relativeTimeString)
Return the delta number of milliseconds specified in the relative time string

Parameters:
relativeTimeString - This is of the form "offset unit", e.g.:
 -1 hour
 +2 weeks
 etc.
 
Returns:
milliseconds

decodeWMODate

public static java.util.Date decodeWMODate(java.lang.String wmoDate,
                                           java.util.Date baseDate)
Decode a date from a WMO header of the form ddHHmm.

Parameters:
wmoDate - WMO header string
baseDate - base date to get the year and month
Returns:
the date that is represented by wmoDate

main

public static void main(java.lang.String[] args)
                 throws java.lang.Exception
main

Parameters:
args - args
Throws:
java.lang.Exception - On badness