ucar.visad
Class UtcDate

java.lang.Object
  extended by ucar.visad.UtcDate

public final class UtcDate
extends Object

A set of utility functions for UTC DateTimes

Author:
Unidata Development Team

Field Summary
static String DEFAULT_PATTERN
          Default time format
static TimeZone GMT
          GMT Timezone
static String HH_FORMAT
          hour format string (HH)
static String HH_MM_FORMAT
          hour:minute format string (HH:mm)
static String HMS_FORMAT
          hour:minute:second format string (HH:mm:ss)
static String IYD_FORMAT
          Year-Day format string
static String JDAY_FORMAT
          Julian day format string
static String MACRO_TIMESTAMP
          timestamp macro identifier
static String TEMPLATE_TIMEFORMAT
          timestamp macro identifier
static String YMD_FORMAT
          Year-Month-Day format string
 
Constructor Summary
UtcDate()
          default constructor
 
Method Summary
static String applyTimeMacro(String template, DateTime dttm)
          Apply the timestamp macro to the string
static String applyTimeMacro(String template, DateTime dttm, String noTimeLabel)
          Apply the timestamp macro to the string
static String applyTimeMacro(String template, DateTime dttm, String noTimeLabel, String prefix, String suffix)
          Apply the timestamp macro to the string
static String applyTimeMacro(String template, DateTime dttm, String noTimeLabel, String prefix, String suffix, TimeZone tz)
          Apply the timestamp macro to the string
static String applyTimeMacro(String template, DateTime dttm, TimeZone tz)
          Apply the timestamp macro to the string
static boolean containsTimeMacro(String s)
          See if the string contains a timestamp macro
static boolean containsTimeMacro(String s, String prefix)
          Does this string contain a time macro
static int[] convertDateTimeToJulianDay(DateTime[] dates)
          Convert an array of DateTime objects to an array of the Julian day of each date
static int[] convertDateTimeToJulianDay(Gridded1DSet timeSet)
          Convert the time set to an array of the Julian days of each date in the set
static DateTime createDateTime(String dateString)
          Create a DateTime object.
static DateTime createDateTime(String dateString, String pattern)
          Create a DateTime object.
static DateTime createDateTime(String dateString, String pattern, TimeZone tz)
          Create a DateTime object.
static DateTime createDateTime(String dateString, String pattern, TimeZone tz, ucar.nc2.time.Calendar cal)
          Create a DateTime object.
static String formatUtcDate(DateTime dt, String pattern)
          Return a formated date in UTC time.
static String formatUtcDate(DateTime dt, String pattern, TimeZone tz)
          Return a formated date in UTC time.
static String getHH(DateTime dt)
          Get the hour as a String.
static String getHH(DateTime dt, TimeZone tz)
          Get the hour as a String.
static String getHHMM(DateTime dt)
          Get the hour:minute as a String.
static String getHHMM(DateTime dt, TimeZone tz)
          Get the hour:minute as a String.
static String getHMS(DateTime dt)
          Get the hour/minute/second as a String
static String getHMS(DateTime dt, TimeZone tz)
          Get the hour/minute/second as a String
static String getIYD(DateTime dt)
          Get the year.jday (IYD_FORMAT) as a String
static String getIYD(DateTime dt, TimeZone tz)
          Get the year.jday (IYD_FORMAT) as a String
static String getUtcDate(DateTime dt)
          Get the full datetime using the DEFAULT_PATTERN
static String getYMD(DateTime dt)
          Get the year-month-day as a String
static String getYMD(DateTime dt, TimeZone tz)
          Get the year-month-day as a String
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MACRO_TIMESTAMP

public static final String MACRO_TIMESTAMP
timestamp macro identifier

See Also:
Constant Field Values

TEMPLATE_TIMEFORMAT

public static final String TEMPLATE_TIMEFORMAT
timestamp macro identifier

See Also:
Constant Field Values

YMD_FORMAT

public static final String YMD_FORMAT
Year-Month-Day format string

See Also:
Constant Field Values

HMS_FORMAT

public static final String HMS_FORMAT
hour:minute:second format string (HH:mm:ss)

See Also:
Constant Field Values

HH_MM_FORMAT

public static final String HH_MM_FORMAT
hour:minute format string (HH:mm)

See Also:
Constant Field Values

HH_FORMAT

public static final String HH_FORMAT
hour format string (HH)

See Also:
Constant Field Values

IYD_FORMAT

public static final String IYD_FORMAT
Year-Day format string

See Also:
Constant Field Values

JDAY_FORMAT

public static final String JDAY_FORMAT
Julian day format string

See Also:
Constant Field Values

GMT

public static final TimeZone GMT
GMT Timezone


DEFAULT_PATTERN

public static final String DEFAULT_PATTERN
Default time format

See Also:
Constant Field Values
Constructor Detail

UtcDate

public UtcDate()
default constructor

Method Detail

getHH

public static String getHH(DateTime dt)
Get the hour as a String.

Parameters:
dt - DateTime to use
Returns:
hour as a String (HH)

getHH

public static String getHH(DateTime dt,
                           TimeZone tz)
Get the hour as a String.

Parameters:
dt - DateTime to use
tz - the TimeZone to use
Returns:
hour as a String (HH)

containsTimeMacro

public static boolean containsTimeMacro(String s)
See if the string contains a timestamp macro

Parameters:
s - the string
Returns:
true if it contains the macro

containsTimeMacro

public static boolean containsTimeMacro(String s,
                                        String prefix)
Does this string contain a time macro

Parameters:
s - the string
prefix - the prefix
Returns:
true if it contains a time macro

applyTimeMacro

public static String applyTimeMacro(String template,
                                    DateTime dttm)
Apply the timestamp macro to the string

Parameters:
template - the timestamp template
dttm - the DateTime
Returns:
a formatted string of form template

applyTimeMacro

public static String applyTimeMacro(String template,
                                    DateTime dttm,
                                    TimeZone tz)
Apply the timestamp macro to the string

Parameters:
template - the timestamp template
dttm - the DateTime
tz - the TimeZone to use
Returns:
a formatted string of form template

applyTimeMacro

public static String applyTimeMacro(String template,
                                    DateTime dttm,
                                    String noTimeLabel)
Apply the timestamp macro to the string

Parameters:
template - the timestamp template
dttm - the DateTime
noTimeLabel - the label if dttm is null;
Returns:
a formatted string of form template

applyTimeMacro

public static String applyTimeMacro(String template,
                                    DateTime dttm,
                                    String noTimeLabel,
                                    String prefix,
                                    String suffix)
Apply the timestamp macro to the string

Parameters:
template - the timestamp template
dttm - the DateTime
noTimeLabel - the label if dttm is null;
prefix - macro prefix
suffix - macro suffix
Returns:
the String with the macro applied

applyTimeMacro

public static String applyTimeMacro(String template,
                                    DateTime dttm,
                                    String noTimeLabel,
                                    String prefix,
                                    String suffix,
                                    TimeZone tz)
Apply the timestamp macro to the string

Parameters:
template - the timestamp template
dttm - the DateTime
noTimeLabel - the label if dttm is null;
prefix - macro prefix
suffix - macro suffix
tz - TimeZone
Returns:
the String with the macro applied

getHHMM

public static String getHHMM(DateTime dt)
Get the hour:minute as a String.

Parameters:
dt - DateTime to use
Returns:
hour:minute as a String (HH:mm);

getHHMM

public static String getHHMM(DateTime dt,
                             TimeZone tz)
Get the hour:minute as a String.

Parameters:
dt - DateTime to use
tz - the TimeZone to use
Returns:
hour:minute as a String (HH:mm);

getYMD

public static String getYMD(DateTime dt)
Get the year-month-day as a String

Parameters:
dt - DateTime to use
Returns:
year-month-day as a String (yyyy-MM-dd);

getYMD

public static String getYMD(DateTime dt,
                            TimeZone tz)
Get the year-month-day as a String

Parameters:
dt - DateTime to use
tz - the TimeZone to use
Returns:
year-month-day as a String (yyyy-MM-dd);

getHMS

public static String getHMS(DateTime dt)
Get the hour/minute/second as a String

Parameters:
dt - DateTime to use
Returns:
the hour/minute/second as a String (HH:mm:ss)

getHMS

public static String getHMS(DateTime dt,
                            TimeZone tz)
Get the hour/minute/second as a String

Parameters:
dt - DateTime to use
tz - the TimeZone to use
Returns:
the hour/minute/second as a String (HH:mm:ss)

getUtcDate

public static String getUtcDate(DateTime dt)
Get the full datetime using the DEFAULT_PATTERN

Parameters:
dt - DateTime to use
Returns:
the formatted UTC date

getIYD

public static String getIYD(DateTime dt)
Get the year.jday (IYD_FORMAT) as a String

Parameters:
dt - DateTime to use
Returns:
year.jday as a String (yyyyDDD);

getIYD

public static String getIYD(DateTime dt,
                            TimeZone tz)
Get the year.jday (IYD_FORMAT) as a String

Parameters:
dt - DateTime to use
tz - the TimeZone to use
Returns:
year.jday as a String (yyyyDDD);

formatUtcDate

public static String formatUtcDate(DateTime dt,
                                   String pattern)
Return a formated date in UTC time. Uses DateTime.formatString() with the UTC (GMT) time zone.

Parameters:
dt - DateTime object
pattern - format pattern
Returns:
formatted date.

formatUtcDate

public static String formatUtcDate(DateTime dt,
                                   String pattern,
                                   TimeZone tz)
Return a formated date in UTC time. Uses DateTime.formatString() with the UTC (GMT) time zone.

Parameters:
dt - DateTime object
pattern - format pattern
tz - the TimeZone to use
Returns:
formatted date.

convertDateTimeToJulianDay

public static int[] convertDateTimeToJulianDay(DateTime[] dates)
Convert an array of DateTime objects to an array of the Julian day of each date

Parameters:
dates - array of dates
Returns:
the corresponding Julian Days

convertDateTimeToJulianDay

public static int[] convertDateTimeToJulianDay(Gridded1DSet timeSet)
                                        throws VisADException
Convert the time set to an array of the Julian days of each date in the set

Parameters:
timeSet - set of dates
Returns:
the corresponding Julian Days
Throws:
VisADException - set must have type of RealType.Time

createDateTime

public static DateTime createDateTime(String dateString)
                               throws VisADException
Create a DateTime object.

Parameters:
dateString - the string specifying the date
Returns:
the DateTime object
Throws:
VisADException - problem decoding string or creating Data object

createDateTime

public static DateTime createDateTime(String dateString,
                                      String pattern)
                               throws VisADException
Create a DateTime object.

Parameters:
dateString - the string specifying the date
tz - the associated time zone
pattern - the format pattern
Returns:
the DateTime object
Throws:
VisADException - problem decoding string or creating Data object

createDateTime

public static DateTime createDateTime(String dateString,
                                      String pattern,
                                      TimeZone tz)
                               throws VisADException
Create a DateTime object.

Parameters:
dateString - the string specifying the date
pattern - the format pattern
tz - the associated time zone
Returns:
the DateTime object
Throws:
VisADException - problem decoding string or creating Data object

createDateTime

public static DateTime createDateTime(String dateString,
                                      String pattern,
                                      TimeZone tz,
                                      ucar.nc2.time.Calendar cal)
                               throws VisADException
Create a DateTime object.

Parameters:
dateString - the string specifying the date
pattern - the format pattern
tz - the associated time zone
cal - the associated Calendar
Returns:
the DateTime object
Throws:
VisADException - problem decoding string or creating Data object