biweekly.util
Class ICalDateFormatter

java.lang.Object
  extended by biweekly.util.ICalDateFormatter

public class ICalDateFormatter
extends Object

Helper class that formats and parses iCalendar dates. iCalendar dates adhere to the ISO8601 date format standard.

Author:
Michael Angstadt

Method Summary
static boolean dateHasTime(String dateStr)
          Determines whether a date string has a time component.
static boolean dateHasTimezone(String dateStr)
          Determines whether a date string is in UTC time or has a timezone offset.
static String format(Date date, ISOFormat format)
          Formats a date for inclusion in an iCalendar object.
static String format(Date date, ISOFormat format, TimeZone timeZone)
          Formats a date for inclusion in an iCalendar object.
static Date parse(String dateStr)
          Parses an iCalendar date.
static Date parse(String dateStr, TimeZone timezone)
          Parses an iCalendar date.
static TimeZone parseTimeZoneId(String timezoneId)
          Gets the TimeZone object that corresponds to the given ID.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

format

public static String format(Date date,
                            ISOFormat format)
Formats a date for inclusion in an iCalendar object.

Parameters:
date - the date to format
format - the format to use
Returns:
the formatted date

format

public static String format(Date date,
                            ISOFormat format,
                            TimeZone timeZone)
Formats a date for inclusion in an iCalendar object.

Parameters:
date - the date to format
format - the format to use
timeZone - the timezone to format the date in or null to use the JVM's default timezone (ignored with "UTC" formats)
Returns:
the formatted date

parse

public static Date parse(String dateStr)
Parses an iCalendar date.

Parameters:
dateStr - the date string to parse (e.g. "20130609T181023Z")
Returns:
the parsed date
Throws:
IllegalArgumentException - if the date string isn't in one of the accepted ISO8601 formats

parse

public static Date parse(String dateStr,
                         TimeZone timezone)
Parses an iCalendar date.

Parameters:
dateStr - the date string to parse (e.g. "20130609T181023Z")
timezone - the timezone to parse the date as or null to use the JVM's default timezone (if the date string contains its own timezone, then that timezone will be used instead)
Returns:
the parsed date
Throws:
IllegalArgumentException - if the date string isn't in one of the accepted ISO8601 formats

dateHasTime

public static boolean dateHasTime(String dateStr)
Determines whether a date string has a time component.

Parameters:
dateStr - the date string (e.g. "20130601T120000")
Returns:
true if it has a time component, false if not

dateHasTimezone

public static boolean dateHasTimezone(String dateStr)
Determines whether a date string is in UTC time or has a timezone offset.

Parameters:
dateStr - the date string (e.g. "20130601T120000Z", "20130601T120000-0400")
Returns:
true if it has a timezone, false if not

parseTimeZoneId

public static TimeZone parseTimeZoneId(String timezoneId)
Gets the TimeZone object that corresponds to the given ID.

Parameters:
timezoneId - the timezone ID (e.g. "America/New_York")
Returns:
the timezone object or null if not found


Copyright © 2013 Michael Angstadt. All Rights Reserved.