com.funambol.util
Class MailDateFormatter

java.lang.Object
  extended by com.funambol.util.MailDateFormatter

public class MailDateFormatter
extends java.lang.Object

A utility class providing methods to convert date information contained in Date objects into RFC2822 and UTC ('Zulu') strings, and to build Date objects starting from string representations of dates in RFC2822 and UTC format. This class does not handle corretly TimeZone in the Java SE env, but it works fine on ME. Therefore it is currently only included in ME based versions.


Field Summary
static int FORMAT_DAY_MONTH
          Format date as: DD/MM
static int FORMAT_DAY_MONTH_YEAR
          Format date as: DD/MM/YYYY
static int FORMAT_HOURS_MINUTES
          Format date as: hh:mm
static int FORMAT_HOURS_MINUTES_SECONDS
          Format date as: hh:mm:ss
static int FORMAT_MONTH_DAY
          Format date as: MM/DD
static int FORMAT_MONTH_DAY_YEAR
          Format date as: MM/DD/YYYY
 
Constructor Summary
MailDateFormatter()
           
 
Method Summary
static java.lang.String dateToRfc2822(java.util.Date date)
          Transforms data contained in a Date object (expressed in UTC) in a string formatted as per RFC2822 in local time (par.
static java.lang.String dateToUTC(java.util.Date d)
          Converts a Date object into a string in 'Zulu' format
static java.lang.String formatLocalTime(java.util.Date d)
          Returns a localized string representation of Date.
static java.util.Date getDeviceLocalDate(java.util.Date gmtDate)
          Convert the given date (GMT) into the local date.
static java.lang.String getFormattedStringFromDate(java.util.Date date, int format, java.lang.String separator)
          A method that returns a string rapresenting a date.
static java.lang.String getReplyDateString(java.lang.String date)
          returns a date with string representation of the month
static java.util.Date parseRfc2822Date(java.lang.String stringDate)
          Parses the string in RFC 2822 format and return a Date object.
static java.util.Date parseUTCDate(java.lang.String utc)
          Gets a Date object from a string representing a date in 'Zulu' format (yyyyMMddTHHmmssZ)
static void setTimeZone(java.lang.String timeZone)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FORMAT_MONTH_DAY

public static final int FORMAT_MONTH_DAY
Format date as: MM/DD

See Also:
Constant Field Values

FORMAT_MONTH_DAY_YEAR

public static final int FORMAT_MONTH_DAY_YEAR
Format date as: MM/DD/YYYY

See Also:
Constant Field Values

FORMAT_HOURS_MINUTES

public static final int FORMAT_HOURS_MINUTES
Format date as: hh:mm

See Also:
Constant Field Values

FORMAT_HOURS_MINUTES_SECONDS

public static final int FORMAT_HOURS_MINUTES_SECONDS
Format date as: hh:mm:ss

See Also:
Constant Field Values

FORMAT_DAY_MONTH

public static final int FORMAT_DAY_MONTH
Format date as: DD/MM

See Also:
Constant Field Values

FORMAT_DAY_MONTH_YEAR

public static final int FORMAT_DAY_MONTH_YEAR
Format date as: DD/MM/YYYY

See Also:
Constant Field Values
Constructor Detail

MailDateFormatter

public MailDateFormatter()
Method Detail

dateToRfc2822

public static java.lang.String dateToRfc2822(java.util.Date date)
Transforms data contained in a Date object (expressed in UTC) in a string formatted as per RFC2822 in local time (par. 3.3)

Returns:
A string representing the date contained in the passed Date object formatted as per RFC 2822 and in local time

dateToUTC

public static java.lang.String dateToUTC(java.util.Date d)
Converts a Date object into a string in 'Zulu' format

Parameters:
d - A Date object to be converted into a string in 'Zulu' format
Returns:
A string representing the date contained in the passed Date object in 'Zulu' format (e.g. yyyyMMDDThhmmssZ)

getFormattedStringFromDate

public static java.lang.String getFormattedStringFromDate(java.util.Date date,
                                                          int format,
                                                          java.lang.String separator)
A method that returns a string rapresenting a date.

Parameters:
date - the date
format - the format as one of FORMAT_MONTH_DAY, FORMAT_MONTH_DAY_YEAR, FORMAT_HOURS_MINUTES, FORMAT_HOURS_MINUTES_SECONDS FORMAT_DAY_MONTH FORMAT_DAY_MONTH_YEAR constants
separator - the separator to be used

formatLocalTime

public static java.lang.String formatLocalTime(java.util.Date d)
Returns a localized string representation of Date.


parseRfc2822Date

public static java.util.Date parseRfc2822Date(java.lang.String stringDate)
Parses the string in RFC 2822 format and return a Date object.

Parse strings like: Thu, 03 May 2007 14:45:38 GMT Thu, 03 May 2007 14:45:38 GMT+0200 Thu, 1 Feb 2007 03:57:01 -0800 Fri, 04 May 2007 13:40:17 PDT

Parameters:
d - the date representation to parse
Returns:
a date, if valid, or null on error

getDeviceLocalDate

public static java.util.Date getDeviceLocalDate(java.util.Date gmtDate)
Convert the given date (GMT) into the local date. NOTE: changes the original date too! Should we change it to a void toLocalDate(Date) that changes the input date only?


parseUTCDate

public static java.util.Date parseUTCDate(java.lang.String utc)
Gets a Date object from a string representing a date in 'Zulu' format (yyyyMMddTHHmmssZ)

Parameters:
utc - date in 'Zulu' format (yyyyMMddTHHmmssZ)
Returns:
A Date object obtained starting from a time in milliseconds from the Epoch

setTimeZone

public static void setTimeZone(java.lang.String timeZone)

getReplyDateString

public static java.lang.String getReplyDateString(java.lang.String date)
returns a date with string representation of the month

Parameters:
date - input date in the format MM/DD/YYYY HH:MMp/a
Returns:
a representation of the date in the format DD, YYYY HH:MM


Copyright © 2001-2009 Funambol.