com.funambol.common.pim.model.utility
Class TimeUtils

java.lang.Object
  extended by com.funambol.common.pim.model.utility.TimeUtils

public class TimeUtils
extends java.lang.Object

Version:
$Id: TimeUtils.java,v 1.9 2008-09-03 09:49:19 mauro Exp $

Field Summary
static java.lang.String PATTERN_LOCALTIME
           
static int PATTERN_LOCALTIME_LENGTH
           
static java.lang.String PATTERN_LOCALTIME_WOT
           
static int PATTERN_LOCALTIME_WOT_LENGTH
           
static java.lang.String PATTERN_UTC
           
static int PATTERN_UTC_LENGTH
           
static java.lang.String PATTERN_UTC_WOZ
           
static int PATTERN_UTC_WOZ_LENGTH
           
static java.lang.String PATTERN_UTC_WSEP
           
static int PATTERN_UTC_WSEP_LENGTH
           
static java.lang.String PATTERN_YYYY_MM_DD
           
static java.lang.String PATTERN_YYYY_MM_DD_HH_MM_SS
           
static int PATTERN_YYYY_MM_DD_HH_MM_SS_LENGTH
           
static int PATTERN_YYYY_MM_DD_LENGTH
           
static java.lang.String PATTERN_YYYYMMDD
           
static int PATTERN_YYYYMMDD_LENGTH
           
static long SECOND_IN_A_DAY
           
static java.util.TimeZone TIMEZONE_UTC
           
 
Constructor Summary
TimeUtils()
           
 
Method Summary
static java.lang.String convertDateFromInDayFormat(java.lang.String stringDate, java.lang.String hhmmss)
          Convert date from yyyy-MM-dd format or from yyyyMMdd format into yyyyMMdd'T'HHmmss format.
static java.lang.String convertDateFromInDayFormat(java.lang.String stringDate, java.lang.String hhmmss, boolean inUtc)
          Convert date from yyyy-MM-dd or yyyyMMdd format into format yyyyMMdd'T'HHmmss.
static java.lang.String convertDateFromTo(java.lang.String stringDate, java.lang.String patternToUse)
          Convert date from the input date format into specificated format.
static java.lang.String convertDateFromTo(java.lang.String stringDate, java.lang.String patternToUse, java.util.TimeZone timezoneIn, java.util.TimeZone timezoneOut)
          Convert date from the input date format into specificated format.
static java.lang.String convertDateTo(java.util.Date date, java.lang.String patternToUse)
          Convert the given date in the given format.
static java.lang.String convertDateTo(java.util.Date date, java.util.TimeZone timeZone, java.lang.String patternToUse)
          Convert the given date in the given format.
static java.lang.String convertLocalDateToUTC(java.lang.String sDate, java.util.TimeZone timezone)
          Convert the given date following this roles: if the given date is in UTC no conversion is required if the given date is not in UTC and the given timezone isn't null, the date is localizated with the timezone and then it's converted in UTC. the returned string is always in UTC if the given timezone is null and the date isn't in UTC, the date is localizated with the default timezone the given date can be in one beetwen the following formats: yyyyMMdd'T'HHmmss'Z', yyyyMMdd'T'HHmmss
static java.lang.String convertUTCDateToLocal(java.lang.String sDate, java.util.TimeZone timezone)
          Convert the given date following this roles: if the given timezone isn't null, the date is localizated with the timezone and then reformatted in yyyyMMdd'T'HHmmss'Z'. the returned string is always in this format yyyyMMdd'T'HHmmss'Z' if the given timezone is null the date is not changed
static java.lang.String getAlarmInterval(int minutes)
          Converts a signed number of minutes into an ISO 8601 interval.
static int getAlarmInterval(java.lang.String interval)
          Calculate the minutes into int format in the case in which the input is into ISO 8601 format; else return the interval
static int getAlarmMinutes(java.lang.String dtStart, java.lang.String dtAlarm, java.util.logging.Logger logger)
          If dtStart and date into Alarm aren't empty, computes the minutes before to start the reminder as dtStart - date alarm = minutes and return it.
static java.lang.String getDateFormat(java.lang.String date)
          Get the date pattern
static java.lang.String getDTEnd(java.lang.String dtStart, java.lang.String duration, java.lang.String dtEnd, java.util.logging.Logger logger)
          If dtStart and duration aren't empty, computes the dtEnd as dtStart + duration and return it.
static java.lang.String getIso8601Duration(java.lang.String minutes)
          Returns the given minutes in iso 8601 duration format
static long getMidnightTime(java.lang.String dateTime)
          Gets the timestamp of the midnight at a given date (i.e., the midnight at the beginning of that day).
static int getMinutes(java.lang.String iso8601Duration)
          Returns the given Iso 8601 duration in minutes
static boolean isAllDayEvent(java.lang.String dateStart, java.lang.String dateEnd)
          Checks if the given dates are relative to an all day event.
static boolean isInAllDayFormat(java.lang.String date)
          Check if the date is into format yyyyMMdd or yyyy-MM-dd.
static java.lang.String localTimeToUTC(java.lang.String actualTime, java.util.logging.Logger logger)
          Set a string date from dd/MM/yyyy HH:mm:ss according to default local timezone into a UTC date pattern yyyyMMdd'T'HHmmss'Z'
static java.lang.String normalizeToISO8601(java.lang.String sDate, java.util.TimeZone tz)
          Convert the given sDate in iso 8601 format.
static java.lang.String rollOneDay(java.lang.String ymd, boolean after)
          Gets the day before or after a given argument.
static java.lang.String UTCToLocalTime(java.lang.String UTCFormat, java.util.logging.Logger logger)
          Set a string date from UTC format (yyyyMMdd'T'HHmmss'Z') into a format dd/MM/yyyy HH:mm:ss according to default local timezone.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PATTERN_YYYYMMDD

public static final java.lang.String PATTERN_YYYYMMDD
See Also:
Constant Field Values

PATTERN_YYYYMMDD_LENGTH

public static final int PATTERN_YYYYMMDD_LENGTH
See Also:
Constant Field Values

PATTERN_YYYY_MM_DD

public static final java.lang.String PATTERN_YYYY_MM_DD
See Also:
Constant Field Values

PATTERN_YYYY_MM_DD_LENGTH

public static final int PATTERN_YYYY_MM_DD_LENGTH
See Also:
Constant Field Values

PATTERN_UTC

public static final java.lang.String PATTERN_UTC
See Also:
Constant Field Values

PATTERN_UTC_LENGTH

public static final int PATTERN_UTC_LENGTH
See Also:
Constant Field Values

PATTERN_UTC_WOZ

public static final java.lang.String PATTERN_UTC_WOZ
See Also:
Constant Field Values

PATTERN_UTC_WOZ_LENGTH

public static final int PATTERN_UTC_WOZ_LENGTH
See Also:
Constant Field Values

PATTERN_UTC_WSEP

public static final java.lang.String PATTERN_UTC_WSEP
See Also:
Constant Field Values

PATTERN_UTC_WSEP_LENGTH

public static final int PATTERN_UTC_WSEP_LENGTH
See Also:
Constant Field Values

PATTERN_LOCALTIME

public static final java.lang.String PATTERN_LOCALTIME
See Also:
Constant Field Values

PATTERN_LOCALTIME_LENGTH

public static final int PATTERN_LOCALTIME_LENGTH
See Also:
Constant Field Values

PATTERN_LOCALTIME_WOT

public static final java.lang.String PATTERN_LOCALTIME_WOT
See Also:
Constant Field Values

PATTERN_LOCALTIME_WOT_LENGTH

public static final int PATTERN_LOCALTIME_WOT_LENGTH
See Also:
Constant Field Values

PATTERN_YYYY_MM_DD_HH_MM_SS

public static final java.lang.String PATTERN_YYYY_MM_DD_HH_MM_SS
See Also:
Constant Field Values

PATTERN_YYYY_MM_DD_HH_MM_SS_LENGTH

public static final int PATTERN_YYYY_MM_DD_HH_MM_SS_LENGTH
See Also:
Constant Field Values

SECOND_IN_A_DAY

public static final long SECOND_IN_A_DAY
See Also:
Constant Field Values

TIMEZONE_UTC

public static final java.util.TimeZone TIMEZONE_UTC
Constructor Detail

TimeUtils

public TimeUtils()
Method Detail

UTCToLocalTime

public static java.lang.String UTCToLocalTime(java.lang.String UTCFormat,
                                              java.util.logging.Logger logger)
Set a string date from UTC format (yyyyMMdd'T'HHmmss'Z') into a format dd/MM/yyyy HH:mm:ss according to default local timezone.

Parameters:
UTCFormat - the input date in UTC format
Returns:
actualTime the date into default local timezone

rollOneDay

public static java.lang.String rollOneDay(java.lang.String ymd,
                                          boolean after)
Gets the day before or after a given argument. Both the argument and the result are in the "yyyyMMdd" format (the argument can also have dashes).

Parameters:
ymd - a String representing a date in an all-day format
after - true if the day after is needed, false if it's the day before
Returns:
a String representing the day before ymd in an all-day format, or null if ymd was not as expected

localTimeToUTC

public static java.lang.String localTimeToUTC(java.lang.String actualTime,
                                              java.util.logging.Logger logger)
Set a string date from dd/MM/yyyy HH:mm:ss according to default local timezone into a UTC date pattern yyyyMMdd'T'HHmmss'Z'

Parameters:
actualTime - the date into default local timezone
Returns:
UTCFormat the date into UTC format

convertLocalDateToUTC

public static java.lang.String convertLocalDateToUTC(java.lang.String sDate,
                                                     java.util.TimeZone timezone)
                                              throws java.lang.Exception
Convert the given date following this roles:

Parameters:
sDate - the given string date to convert
timezone - TimeZone
Returns:
String
Throws:
java.lang.Exception

convertUTCDateToLocal

public static java.lang.String convertUTCDateToLocal(java.lang.String sDate,
                                                     java.util.TimeZone timezone)
                                              throws java.lang.Exception
Convert the given date following this roles:

Parameters:
sDate - the given string date to convert
timezone - TimeZone
Returns:
String
Throws:
java.lang.Exception

normalizeToISO8601

public static java.lang.String normalizeToISO8601(java.lang.String sDate,
                                                  java.util.TimeZone tz)
Convert the given sDate in iso 8601 format.

The formats accepted are:

Parameters:
sDate - String
Returns:
the sDate in iso 8601 format

getMinutes

public static int getMinutes(java.lang.String iso8601Duration)
Returns the given Iso 8601 duration in minutes

Parameters:
iso8601Duration - String
Returns:
int

getIso8601Duration

public static java.lang.String getIso8601Duration(java.lang.String minutes)
Returns the given minutes in iso 8601 duration format

Parameters:
minutes - String
Returns:
String

getDTEnd

public static java.lang.String getDTEnd(java.lang.String dtStart,
                                        java.lang.String duration,
                                        java.lang.String dtEnd,
                                        java.util.logging.Logger logger)
If dtStart and duration aren't empty, computes the dtEnd as dtStart + duration and return it. If dtStart or duration are empty, return the given dtEnd unchanges it. The format of the return dtEnd is the same of the dtStart. The format accepted are the following:
  • "yyyyMMdd'T'HHmmss'Z'"
  • "yyyyMMdd'T'HHmmss"
  • "yyyyMMdd"
  • "yyyy-MM-dd"
  • Parameters:
    dtStart - String Date to start the event
    duration - String
    dtEnd - String
    Returns:
    String

    getAlarmMinutes

    public static int getAlarmMinutes(java.lang.String dtStart,
                                      java.lang.String dtAlarm,
                                      java.util.logging.Logger logger)
    If dtStart and date into Alarm aren't empty, computes the minutes before to start the reminder as dtStart - date alarm = minutes and return it. The format of the return dtEnd is the same of the dtStart. The format accepted are the following:
  • "yyyyMMdd'T'HHmmss'Z'"
  • "yyyyMMdd'T'HHmmss"
  • "yyyyMMdd"
  • "yyyy-MM-dd"
  • However, all times and dates will be interpreted as UTC.

    Parameters:
    dtStart - String
    dtAlarm - String
    Returns:
    int minutes before to start reminder

    getAlarmInterval

    public static int getAlarmInterval(java.lang.String interval)
    Calculate the minutes into int format in the case in which the input is into ISO 8601 format; else return the interval

    Parameters:
    interval - the interval in which the reminder has to be repeated
    Returns:
    int the interval in minutes format

    getAlarmInterval

    public static java.lang.String getAlarmInterval(int minutes)
    Converts a signed number of minutes into an ISO 8601 interval.

    Parameters:
    minutes -
    Returns:
    a string like "-PT15M"

    isInAllDayFormat

    public static boolean isInAllDayFormat(java.lang.String date)
    Check if the date is into format yyyyMMdd or yyyy-MM-dd. If the date is in one of this format then the event is an AllDay event

    Parameters:
    date - The date to check (Usually this is the start date event)
    Returns:
    boolean true if the format is right, otherwise false

    convertDateFromInDayFormat

    public static java.lang.String convertDateFromInDayFormat(java.lang.String stringDate,
                                                              java.lang.String hhmmss)
                                                       throws java.text.ParseException
    Convert date from yyyy-MM-dd format or from yyyyMMdd format into yyyyMMdd'T'HHmmss format.

    Parameters:
    stringDate - the date to convert
    hhmmss - the hours, minutes, seconds to add
    Returns:
    String the date into proper format
    Throws:
    java.text.ParseException

    convertDateFromInDayFormat

    public static java.lang.String convertDateFromInDayFormat(java.lang.String stringDate,
                                                              java.lang.String hhmmss,
                                                              boolean inUtc)
                                                       throws java.text.ParseException
    Convert date from yyyy-MM-dd or yyyyMMdd format into format yyyyMMdd'T'HHmmss. If inUtc is true the date is converted in yyyyMMdd'T'HHmmss'Z'

    Parameters:
    stringDate - the date to convert
    hhmmss - the hours, minutes, seconds to add
    Returns:
    String the date into proper format
    Throws:
    java.text.ParseException

    convertDateFromTo

    public static java.lang.String convertDateFromTo(java.lang.String stringDate,
                                                     java.lang.String patternToUse)
                                              throws java.text.ParseException
    Convert date from the input date format into specificated format.

    Parameters:
    patternToUse - the pattern to use
    stringDate - the date to convert
    Returns:
    String the date into proper format
    Throws:
    java.text.ParseException

    convertDateFromTo

    public static java.lang.String convertDateFromTo(java.lang.String stringDate,
                                                     java.lang.String patternToUse,
                                                     java.util.TimeZone timezoneIn,
                                                     java.util.TimeZone timezoneOut)
                                              throws java.text.ParseException
    Convert date from the input date format into specificated format.
    In the conversion the following rules are applied:

    Parameters:
    stringDate - the date to convert
    patternToUse - the required pattern for the output date
    timezoneIn - the timezone to apply to the given date
    timezoneOut - the timezone to apply on the output date
    Returns:
    String the date into proper format
    Throws:
    java.text.ParseException - if an error occurs

    convertDateTo

    public static java.lang.String convertDateTo(java.util.Date date,
                                                 java.lang.String patternToUse)
                                          throws java.text.ParseException
    Convert the given date in the given format.

    Parameters:
    patternToUse - the pattern of the output date
    date - the date to convert
    Returns:
    String the date into proper format
    Throws:
    java.text.ParseException - if an error occurs

    convertDateTo

    public static java.lang.String convertDateTo(java.util.Date date,
                                                 java.util.TimeZone timeZone,
                                                 java.lang.String patternToUse)
                                          throws java.text.ParseException
    Convert the given date in the given format.

    Parameters:
    timeZone - the time zone to use
    patternToUse - the pattern of the output date
    date - the date to convert
    Returns:
    String the date into proper format
    Throws:
    java.text.ParseException

    getDateFormat

    public static java.lang.String getDateFormat(java.lang.String date)
    Get the date pattern

    Parameters:
    date - the date to get the format
    Returns:
    String the pattern

    isAllDayEvent

    public static boolean isAllDayEvent(java.lang.String dateStart,
                                        java.lang.String dateEnd)
    Checks if the given dates are relative to an all day event. The dates are relative to an all day event if the start date ends with T000000Z and the end date ends with T235959Z or T235900Z or T240000Z

    Parameters:
    dateStart - String
    dateEnd - String
    Returns:
    true if the given dates are relative to an all day event, false otherwise

    getMidnightTime

    public static long getMidnightTime(java.lang.String dateTime)
                                throws java.text.ParseException
    Gets the timestamp of the midnight at a given date (i.e., the midnight at the beginning of that day). The moment corresponds to midnight in UTC.

    Parameters:
    dateTime - a date (and, optionally, a time) in the ISO 8601 format
    Returns:
    the timestamp as a long
    Throws:
    java.text.ParseException - if dateTime has a wrong format


    Copyright © 2001-2009 Funambol.