hudson.plugins.dimensionsscm
Class DateUtils

java.lang.Object
  extended by hudson.plugins.dimensionsscm.DateUtils
All Implemented Interfaces:
java.io.Serializable

public class DateUtils
extends java.lang.Object
implements java.io.Serializable

A set of methods for converting Date objects to and from strings in a valid date format, and also validating that strings are in an Oracle date format. Note: this class uses only Locale.US at the moment - this may need changing.

Author:
Tim Payne
See Also:
Serialized Form

Constructor Summary
DateUtils()
           
 
Method Summary
static int compare(java.util.Date d1, java.util.Date d2, long toleranceMillis)
          Note that comparing dates that have been converted from one format into another should always be done with a tolerance (like comparing doubles or floats) to allow for the fact that some accuracy may be lost (for instance by rounding to the nearest second).
static java.lang.String format(java.util.Date date)
          Formats a string in known date-time form from a date object, using UTC time zone.
static java.lang.String format(java.util.Date date, java.util.TimeZone tz)
          Formats a string in known date-time form from a date object, using UTC time zone.
static java.lang.String getNowStrDate()
          Gets "now" in RFC format
static java.lang.String getNowStrDate(java.util.TimeZone tz)
          Gets "now" in RFC format
static java.lang.String getNowStrDateVerbose()
          Gets "now" in verbose format
static java.lang.String getStrDate(java.util.Calendar opDate)
          Gets a date in RFC format
static java.lang.String getStrDate(java.util.Calendar opDate, java.util.TimeZone tz)
          Gets a date in RFC format
static java.util.Date parse(java.lang.String dateStr)
          Parses a date from a string in known format, using UTC time zone.
static java.util.Date parse(java.lang.String dateStr, java.util.TimeZone tz)
          Parses a date from a string in known form.
static boolean validate(java.lang.String dateStr)
          Validates whether a given string is in correct known date format or date-time format.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DateUtils

public DateUtils()
Method Detail

parse

public static java.util.Date parse(java.lang.String dateStr)
Parses a date from a string in known format, using UTC time zone. NOTE: This should ONLY be used if the caller has no knowledge of the time zone to be used. Most of the time the overloaded method below should be used.

Parameters:
dateStr - a String containing a date in known form
Returns:
a Date object, or null

parse

public static java.util.Date parse(java.lang.String dateStr,
                                   java.util.TimeZone tz)
Parses a date from a string in known form.

Parameters:
dateStr - a String containing a date in known form
tz - the TimeZone to be used when parsing the date string
Returns:
a Date object, or null

validate

public static boolean validate(java.lang.String dateStr)
Validates whether a given string is in correct known date format or date-time format. Note that this is stricter than the parse(String) method is.

Parameters:
dateStr - the String containing the date to be validated
Returns:
true if the string is in a valid format, false otherwise

compare

public static int compare(java.util.Date d1,
                          java.util.Date d2,
                          long toleranceMillis)
Note that comparing dates that have been converted from one format into another should always be done with a tolerance (like comparing doubles or floats) to allow for the fact that some accuracy may be lost (for instance by rounding to the nearest second).

Parameters:
d1 - first date to compare.
d2 - second date to compare.
toleranceMillis - millisecond tolerance to allow.
Returns:
0 if the two dates are within toleranceMillis milliseconds of each other, negative if d1 < d2, positive if d1 > d2

format

public static java.lang.String format(java.util.Date date)
Formats a string in known date-time form from a date object, using UTC time zone. NOTE: This should ONLY be used if the caller has no knowledge of the time zone to be used. Most of the time the overloaded method below should be used.

Parameters:
date - the date to be formatted
Returns:
a String containing a date in known date-time form, or null

format

public static java.lang.String format(java.util.Date date,
                                      java.util.TimeZone tz)
Formats a string in known date-time form from a date object, using UTC time zone.

Parameters:
date - the date to be formatted
tz - the TimeZone to be used when parsing the date string
Returns:
a String containing a date in known date-time form, or null

getNowStrDate

public static java.lang.String getNowStrDate()
Gets "now" in RFC format

Returns:
a String containing a date in known RFC

getNowStrDate

public static java.lang.String getNowStrDate(java.util.TimeZone tz)
Gets "now" in RFC format

Parameters:
timezone - tz
Returns:
a String containing a date in known RFC

getNowStrDateVerbose

public static java.lang.String getNowStrDateVerbose()
Gets "now" in verbose format

Returns:
a String containing a date in verbose format

getStrDate

public static java.lang.String getStrDate(java.util.Calendar opDate)
Gets a date in RFC format

Parameters:
calendar - date
Returns:
a String containing a date in known RFC

getStrDate

public static java.lang.String getStrDate(java.util.Calendar opDate,
                                          java.util.TimeZone tz)
Gets a date in RFC format

Parameters:
calendar - date
timezone - tz
Returns:
a String containing a date in known RFC


Copyright © 2004-2011 Hudson. All Rights Reserved.