igpp.util
Class Date3

java.lang.Object
  extended by igpp.util.Date3

public class Date3
extends Object

Methods to manipulate dates.

Version:
1.00 2007
Author:
Todd King

Field Summary
static String ABBRDFS
          1989/01/19 11:45:30.234
static String AMER
          jan 19, 1983 11:45:30.234
static String AMERDATE
          1/19/83 11:45:30.234
static String BINARY
          758979930.234
static String CLUSTER
          19-01-1989 11:45:30.234
static String CONVENTION
          1989-01-19 11:45:30.234
static String DFS
          1989-JAN-19 11:45:30.234
static String DOY
          1983 303 11:45:30.234
static String EURO
          19 jan 1983 11:45:30.234
static String EURODATE
          19.1.83 11:45:30.234
static String HIGHLOW
          83 01 19 00 11 45 30.234
static String ISEEDATE
          83 019 JAN 19 11 45 30.234
static String ISO
          19890119T114530.234
static String ISO8601
          1989-01-19T11:45:30.234 or 1989-019T11:45:30.234 with omissions
static String JAPANDATE
          83.1.19 11:45:30.234
static String NIPPONDATE
          83.19.1 11:45:30.234
static String PDS
          1989-01-19T11:45:30.234 or 1989-019T11:45:30.234 with omissions
 
Constructor Summary
Date3()
           
 
Method Summary
static void advance(Calendar time, double minutes)
          Advances the time by a specified number of minutes.
static int compareTo(Calendar aTime, Calendar anotherTime)
          Compare a time to this instance for ordering.
static String convert(String date, String toFormat, String fromFormat)
          Convert a date string in one format into another format.
static String elapsed(Calendar startTime)
          Given a starting time calculated the elapsed time since and for as a string.
static String findTimePattern(String name)
          Returns the time format specification that matches the given standard format name.
static Calendar getCalendar(long tick)
          Create a Calendar based on a the number of milliseconds since the epoch (00:00:00 GMT, January 1, 1970).
static Calendar getCalendar(String date)
          Parse a standard format time string into a Calendar object.
static String getDateFormat()
          Get the current date format used for all date manipulation.
static String getDateString(Calendar cal)
          Create a standard format time string for a Calendar
static String getDateString(Calendar cal, String form)
          Create a formated time string for a Calendar.
static String getDateString(Date date)
          Create a standard format time string for a Date
static String getDateString(Date date, String form)
          Create a formated time string for a Date.
static String getDateString(long tick)
          Create a standard format time string for a long (count of seconds).
static String getDateString(long tick, String form)
          Create a formated time string for a long (count of seconds).
static String getDateString(String date, String form)
          Parse a time string using parseISO8601() and create a formated time string.
static Calendar getDawn()
          Sets the time to the earliest possible time.
static int getDaysInMonth(Calendar cal)
          Determines the number of days in the month.
static Calendar getEternity()
          Sets the time to the latest possible time.
static String getISO8601DateString(Calendar cal)
          Create a standard ISO-8601 format time string for a Calendar.
static String getISO8601DateString(Date date)
          Create a standard ISO-8601 format time string for a Date.
static String getISO8601DateString(String date)
          Create a standard ISO-8601 format time string from a string.
static Calendar getNow()
          Return a calendar object set to the current time.
static Calendar getTomorrow()
          Return a calendar object set to the current time on tomorrow.
static Calendar interpret(String value)
          Convert a string into a Calendar by intepreting the passed value.
static boolean isAfter(Calendar compareDate, Calendar baseDate)
          Checks if one time is on or after another time.
static boolean isAfter(String compareDate, String baseDate)
          Checks if one ISO8601 time is on or after another ISO8601 time.
static boolean isBefore(Calendar compareDate, Calendar baseDate)
          Checks if one time is on or before another time.
static boolean isBefore(String compareDate, String baseDate)
          Checks if one ISO8601 time is on or before another ISO8601 time.
static boolean isEmpty(String base)
          Determines if a date string is "empty".
static boolean isInSpan(Calendar compare, Calendar spanStart, Calendar spanEnd)
          Checks if a time is within a time span.
static boolean isInSpan(String compareStart, String compareEnd, String baseStart, String baseEnd)
          Checks if a start and end ISO-8601 time is within another start and end ISO-8601 time.
static boolean isOnOrAfter(Calendar compareDate, Calendar baseDate)
          Checks if one time is on or after another time.
static boolean isOnOrAfter(String compareDate, String baseDate)
          Checks if one ISO-8601 time is on or after another ISO-8601 time.
static boolean isOnOrBefore(Calendar compareDate, Calendar baseDate)
          Checks if one time is on or before another time.
static boolean isOnOrBefore(String compareDate, String baseDate)
          Checks if one ISO8601 time is on or before another ISO8601 time.
static void main(String[] args)
          Command-line interface
static String now()
          Create a standard format time string for the current system time.
static Calendar parse(String value, String pattern)
          Parses a string into a Date using the given pattern.
static Calendar parseISO8601(String date)
          Parses an ISO-8601 formatted time string.
static Calendar parseISO8601(String date, Boolean ceil)
          Parses an ISO-8601 formatted time string.
static Calendar parseISO8601Duration(String duration)
          Parses an ISO-8601 formatted duration string.
static String sanitizeDate(String date)
          Replaces any "T" which may appear in an ISO-8601 compliant date string with a space.
static void setDateFormat(String dateFormat)
          Sets the date format to use for all date manipulation.
static Calendar setLimit(Boolean ceil, Calendar cal, int field)
          Set the maximum (ceil) or minimum (floor) value for a time field.
static long span(Calendar startTime, Calendar endTime)
          Returns the number of milliseconds between a time and this time.
static String translateISO8601Duration(String duration)
          Parses an ISO-8601 formatted duration string and describe it in human terms.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

AMERDATE

public static final String AMERDATE
1/19/83 11:45:30.234

See Also:
Constant Field Values

EURODATE

public static final String EURODATE
19.1.83 11:45:30.234

See Also:
Constant Field Values

AMER

public static final String AMER
jan 19, 1983 11:45:30.234

See Also:
Constant Field Values

EURO

public static final String EURO
19 jan 1983 11:45:30.234

See Also:
Constant Field Values

DOY

public static final String DOY
1983 303 11:45:30.234

See Also:
Constant Field Values

JAPANDATE

public static final String JAPANDATE
83.1.19 11:45:30.234

See Also:
Constant Field Values

NIPPONDATE

public static final String NIPPONDATE
83.19.1 11:45:30.234

See Also:
Constant Field Values

HIGHLOW

public static final String HIGHLOW
83 01 19 00 11 45 30.234

See Also:
Constant Field Values

ISEEDATE

public static final String ISEEDATE
83 019 JAN 19 11 45 30.234

See Also:
Constant Field Values

DFS

public static final String DFS
1989-JAN-19 11:45:30.234

See Also:
Constant Field Values

ABBRDFS

public static final String ABBRDFS
1989/01/19 11:45:30.234

See Also:
Constant Field Values

PDS

public static final String PDS
1989-01-19T11:45:30.234 or 1989-019T11:45:30.234 with omissions

See Also:
Constant Field Values

ISO

public static final String ISO
19890119T114530.234

See Also:
Constant Field Values

BINARY

public static final String BINARY
758979930.234

See Also:
Constant Field Values

CLUSTER

public static final String CLUSTER
19-01-1989 11:45:30.234

See Also:
Constant Field Values

CONVENTION

public static final String CONVENTION
1989-01-19 11:45:30.234

See Also:
Constant Field Values

ISO8601

public static final String ISO8601
1989-01-19T11:45:30.234 or 1989-019T11:45:30.234 with omissions

See Also:
Constant Field Values
Constructor Detail

Date3

public Date3()
Method Detail

main

public static void main(String[] args)
Command-line interface

Parameters:
args - the arguments passed on the command-line.
Since:
1.0

findTimePattern

public static String findTimePattern(String name)
Returns the time format specification that matches the given standard format name. If no match is found the passed string is returned.

Parameters:
name - the name of the standard format.
Returns:
a string containing the format specification that matches the passed name. If no match is found the passed string is returned.

now

public static String now()
Create a standard format time string for the current system time.

Returns:
the current date and time in the format yyyy-MM-dd HH:mm:ss.SSS

getDateString

public static String getDateString(long tick)
Create a standard format time string for a long (count of seconds).

Parameters:
tick - the number of milliseconds since January 1, 1970, 00:00:00 GMT not to exceed the milliseconds representation for the year 8099. A negative number indicates the number of milliseconds before January 1, 1970, 00:00:00 GMT.
Returns:
the date and time in the standard format (default: yyyy-MM-dd HH:mm:ss.SSS)

getDateString

public static String getDateString(Date date)
Create a standard format time string for a Date

Parameters:
date - a Date set with the date and time.
Returns:
the date and time in the standard format (default: yyyy-MM-dd HH:mm:ss.SSS)

getDateString

public static String getDateString(Calendar cal)
Create a standard format time string for a Calendar

Parameters:
cal - Calendar set with the date and time.
Returns:
the date and time in the standard format (default: yyyy-MM-dd HH:mm:ss.SSS)

getDateString

public static String getDateString(long tick,
                                   String form)
Create a formated time string for a long (count of seconds).

Parameters:
tick - the number of milliseconds since January 1, 1970, 00:00:00 GMT not to exceed the milliseconds representation for the year 8099. A negative number indicates the number of milliseconds before January 1, 1970, 00:00:00 GMT.
form - the pattern to format the date string. See SimpleDateFormat.
Returns:
the date and time in the format requested

getDateString

public static String getDateString(Date date,
                                   String form)
Create a formated time string for a Date.

Parameters:
date - a Date set with the date and time.
form - the pattern to format the date string. See SimpleDateFormat.
Returns:
the date and time in the format requested

getDateString

public static String getDateString(Calendar cal,
                                   String form)
Create a formated time string for a Calendar.

Parameters:
cal - Calendar set with the date and time.
form - the pattern to format the date string. See SimpleDateFormat.
Returns:
the date and time in the format requested

getDateString

public static String getDateString(String date,
                                   String form)
Parse a time string using parseISO8601() and create a formated time string.

Parameters:
date - the date and time string in the ISO8601 format.
form - the pattern to format the date string. See SimpleDateFormat.
Returns:
the date and time in the format requested

getCalendar

public static Calendar getCalendar(String date)
Parse a standard format time string into a Calendar object.

Parameters:
date - the date and time string in the format yyyy-MM-dd HH:mm:ss.SSS.
Returns:
A Calendar populated with the date and time.

getCalendar

public static Calendar getCalendar(long tick)
Create a Calendar based on a the number of milliseconds since the epoch (00:00:00 GMT, January 1, 1970).

Parameters:
tick - count of the number of milliseconds since the epoch (00:00:00 GMT, January 1, 1970).
Returns:
A Calendar populated with the date and time.

getNow

public static Calendar getNow()
Return a calendar object set to the current time.

Returns:
A Calendar populated with the current date and time.

getTomorrow

public static Calendar getTomorrow()
Return a calendar object set to the current time on tomorrow.

Returns:
A Calendar populated with the date and time 24 hours from the present.

getDawn

public static Calendar getDawn()
Sets the time to the earliest possible time.

Returns:
A Calendar set the earliest possible time.
Since:
1.0

getEternity

public static Calendar getEternity()
Sets the time to the latest possible time.

Returns:
A Calendar set the latest possible time.
Since:
1.0

elapsed

public static String elapsed(Calendar startTime)
Given a starting time calculated the elapsed time since and for as a string.

Parameters:
startTime - a Calendar containing a starting date and time.
Returns:
The number of seconds elapsed from the startTime to the present.

span

public static long span(Calendar startTime,
                        Calendar endTime)
Returns the number of milliseconds between a time and this time.

Parameters:
startTime - a Calendar containing a starting date and time.
endTime - a Calendar containing a ending date and time.

advance

public static void advance(Calendar time,
                           double minutes)
Advances the time by a specified number of minutes.

Parameters:
time - the Calendar containing the initial date and time.
minutes - the number of minutes to advance the time by. The value may include a fractional minute.

compareTo

public static int compareTo(Calendar aTime,
                            Calendar anotherTime)
Compare a time to this instance for ordering.

Parameters:
aTime - the Calendar to compare to the base time.
anotherTime - the Calendar to compare to the base time.
Returns:
the value 0 if the passed argument is equal to this instance; a value less than 0 if the this instance is before the passed argument; and a value greater than 0 if the this instance is after the passed argument.
Since:
1.0

getISO8601DateString

public static String getISO8601DateString(String date)
Create a standard ISO-8601 format time string from a string.

Parameters:
date - the date and time string in the ISO8601 format yyyy-MM-ddTHH:mm:ss.SSS.
Returns:
A String with the date and time formatted as an ISO-8601 time string of yyyy-MM-ddTHH:mm:ss.SSSZ.

getISO8601DateString

public static String getISO8601DateString(Calendar cal)
Create a standard ISO-8601 format time string for a Calendar.

Parameters:
cal - Calendar set with the date and time.
Returns:
A String with the date and time formatted as an ISO-8601 time string of yyyy-MM-ddTHH:mm:ss.SSSZ.

getISO8601DateString

public static String getISO8601DateString(Date date)
Create a standard ISO-8601 format time string for a Date.

Parameters:
date - a Date set with the date and time.
Returns:
A String with the date and time formatted as an ISO-8601 time string of yyyy-MM-ddTHH:mm:ss.SSSZ.

convert

public static String convert(String date,
                             String toFormat,
                             String fromFormat)
Convert a date string in one format into another format. Special format specification of "B" with return the count of seconds since 1966 (Cline Time) and "T" will return ISO8601 formatted time.

Parameters:
date - a Date set with the date and time.
toFormat - the desired output format.
fromFormat - the current format.
Returns:
A String with the date and time formatted as an ISO-8601 time string of yyyy-MM-ddTHH:mm:ss.SSSZ.

interpret

public static Calendar interpret(String value)
Convert a string into a Calendar by intepreting the passed value. The value can have the a standard time value form of YYYY-MM-DD HH:mm:sss or be a relative specification such as "X days". Supported relative units are: second, minute, day, month, year. Units can be singular (day) or plural (days) and retain the same meaning.

Parameters:
value - the text containing the string to parse.
Returns:
A Calendar set the parsed time value, null if unable to parse the string.
Since:
1.0

parse

public static Calendar parse(String value,
                             String pattern)
Parses a string into a Date using the given pattern. The pattern can be specified using one of the predefined formats or it can be specified using the syntax used by SimpleDateFormat. The following patterns are have special interpretation:

B
Binary time. Count of seconds from 1966 Jan 1. (aka Cline Time).
T
ISO8601 time. Format is YYYY-MM-DDTHH:mm:SS.sss

The following values have a special meaning (pattern is ignored):

EOM
End of Mission. Sets the date to the maximum possible.
LAUNCH
The beginning of time. Sets the date to the absolute minimum.

Parameters:
value - the text containing the string to parse.
pattern - the text containing the pattern to parse buffer with.
Returns:
A Calendar set the parsed time value, null if unable to parse the string.
Since:
1.0

parseISO8601Duration

public static Calendar parseISO8601Duration(String duration)
Parses an ISO-8601 formatted duration string. ISO-8601 durations have the format is P[n]Y[n]M[n]DT[n]H[n]M[n]S or P[n]W The duration is subtracted from the current date to determine a point in time.

Parameters:
duration - the string containing the ISO-8601 duration specfication.
Returns:
a Calendar set to the appropriate time.

translateISO8601Duration

public static String translateISO8601Duration(String duration)
Parses an ISO-8601 formatted duration string and describe it in human terms. ISO-8601 durations have the format is P[n]Y[n]M[n]DT[n]H[n]M[n]S or P[n]W

Parameters:
duration - the string containing the ISO-8601 duration specfication.
Returns:
a String that describes the duration in human terms.

parseISO8601

public static Calendar parseISO8601(String date)
Parses an ISO-8601 formatted time string. ISO-8601 time strings have the format YYYY-MM-DDTHH:MM:SS.sss The date/time seperator "T" may also be a space. The date may be abbreviated. Any unpsecfied values are set to the minimum allowed.

Parameters:
date - the ISO-8601 time stirng
Returns:
a Calendar with set the appropriate date and time.

parseISO8601

public static Calendar parseISO8601(String date,
                                    Boolean ceil)
Parses an ISO-8601 formatted time string. ISO-8601 time strings have the format YYYY-MM-DDTHH:MM:SS.sss The date/time seperator "T" may also be a space. The date may be abbreviated. Any unpsecfied values are set to the minimum allowed.

Parameters:
date - the ISO-8601 time stirng
ceil - indicate if maximum value is assumed for non-specified parts. If false minimum (floor) value is assumed.
Returns:
a Calendar with set the appropriate date and time.

setLimit

public static Calendar setLimit(Boolean ceil,
                                Calendar cal,
                                int field)
Set the maximum (ceil) or minimum (floor) value for a time field. The starting field is specified. All fields of lower order are also set.

Parameters:
ceil - indicate if maximum value is assumed for non-specified parts. If false minimum (floor) value is assumed. cal the Calendar with higher order fields already set. field the field to begin setting values.
Returns:
the Calendar arugment is altered.

getDaysInMonth

public static int getDaysInMonth(Calendar cal)
Determines the number of days in the month. The Calendar.GetMaximum(Calendar.DAY_OF_MONTH) always returns 31 which is not specific to the month defined in the instance of the Calendary. This method determines the month, sets the day to 28 and then advances the day until the month changes.

Parameters:
cal - the Calendar with at least the year and month set.
Returns:
the the count of the number of days in the month.

isEmpty

public static boolean isEmpty(String base)
Determines if a date string is "empty". An empty date string is one which is either "null", has a length of 0 or contains all zeros for values.

Parameters:
base - the time string to test.
Returns:
true if the time string is empty, otherwise false

isInSpan

public static boolean isInSpan(String compareStart,
                               String compareEnd,
                               String baseStart,
                               String baseEnd)
Checks if a start and end ISO-8601 time is within another start and end ISO-8601 time.

Parameters:
compareStart - the starting time of the first time range.
compareEnd - the ending time of the first time range.
baseStart - the starting time of the second time range.
baseEnd - the ending time of the second time range.
Returns:
true if there is overlap of the two time ranges, otherwise false.

isInSpan

public static boolean isInSpan(Calendar compare,
                               Calendar spanStart,
                               Calendar spanEnd)
Checks if a time is within a time span.

Parameters:
compare - the starting time of the first time range.
spanStart - the starting time of the second time range.
spanEnd - the ending time of the second time range.
Returns:
true if there is overlap of the two time ranges, otherwise false.

isOnOrAfter

public static boolean isOnOrAfter(String compareDate,
                                  String baseDate)
Checks if one ISO-8601 time is on or after another ISO-8601 time. If baseDate is empty it is considered the beginning of time and any time is a match. If the compareDate is empty it is considered to be any time and is a match.

Parameters:
compareDate - the date string to check.
baseDate - the reference date string.
Returns:
true if the compareDate is on or after the baseDate, otherwise false.

isOnOrAfter

public static boolean isOnOrAfter(Calendar compareDate,
                                  Calendar baseDate)
Checks if one time is on or after another time. If baseDate is empty it is considered the beginning of time and any time is a match. If the compareDate is empty it is considered to be any time and is a match.

Parameters:
compareDate - the date string to check.
baseDate - the reference date string.
Returns:
true if the compareDate is on or after the baseDate, otherwise false.

isAfter

public static boolean isAfter(String compareDate,
                              String baseDate)
Checks if one ISO8601 time is on or after another ISO8601 time. If baseDate is empty it is considered the beginning of time and any time is a match. If the compareDate is empty its considered to be any time and is a match.

Parameters:
compareDate - the date string to check.
baseDate - the reference date string.
Returns:
true if the compareDate is after the baseDate, otherwise false.

isAfter

public static boolean isAfter(Calendar compareDate,
                              Calendar baseDate)
Checks if one time is on or after another time. If baseDate is empty it is considered the beginning of time and any time is a match. If the compareDate is empty its considered to be any time and is a match.

Parameters:
compareDate - the date string to check.
baseDate - the reference date string.
Returns:
true if the compareDate is after the baseDate, otherwise false.

isOnOrBefore

public static boolean isOnOrBefore(String compareDate,
                                   String baseDate)
Checks if one ISO8601 time is on or before another ISO8601 time. If baseDate is empty it is considered the end of time and any time is a match. If the compareDate is empty its considered to be any time and is a match.

Parameters:
compareDate - the date string to check.
baseDate - the reference date string.
Returns:
true if the compareDate is on or before the baseDate, otherwise false.

isOnOrBefore

public static boolean isOnOrBefore(Calendar compareDate,
                                   Calendar baseDate)
Checks if one time is on or before another time. If baseDate is empty it is considered the end of time and any time is a match. If the compareDate is empty its considered to be any time and is a match.

Parameters:
compareDate - the date string to check.
baseDate - the reference date string.
Returns:
true if the compareDate is on or before the baseDate, otherwise false.

isBefore

public static boolean isBefore(String compareDate,
                               String baseDate)
Checks if one ISO8601 time is on or before another ISO8601 time. If baseDate is empty it is considered the end of time and any time is a match. If the compareDate is empty its considered to be any time and is a match.

Parameters:
compareDate - the date string to check.
baseDate - the reference date string.
Returns:
true if the compareDate is beforethe baseDate, otherwise false.

isBefore

public static boolean isBefore(Calendar compareDate,
                               Calendar baseDate)
Checks if one time is on or before another time. If baseDate is empty it is considered the end of time and any time is a match. If the compareDate is empty its considered to be any time and is a match.

Parameters:
compareDate - the date string to check.
baseDate - the reference date string.
Returns:
true if the compareDate is beforethe baseDate, otherwise false.

sanitizeDate

public static String sanitizeDate(String date)
Replaces any "T" which may appear in an ISO-8601 compliant date string with a space.

Parameters:
date - a ISO-8601 time string.
Returns:
the String with the first "T" replaced with a space.

setDateFormat

public static void setDateFormat(String dateFormat)
Sets the date format to use for all date manipulation.

Parameters:
dateFormat - the date format to use as the "standard" format. See SimpleDateFormat for how to specify the date format.

getDateFormat

public static String getDateFormat()
Get the current date format used for all date manipulation.

Returns:
the currently set "standard" format.


Copyright © 2008-2009 Regents University of California. All Rights Reserved.