ch.elca.el4j.util.codingsupport
Class JodaTimeUtils

java.lang.Object
  extended by ch.elca.el4j.util.codingsupport.JodaTimeUtils

public class JodaTimeUtils
extends Object

This class is a class providing static mehtods for conversion between JodaTime formats and strings.

Author:
Daniel Thomas (DTH)
File-location:
JodaTimeUtils
Last check-in date:
2009-10-22 09:07:47 +0200 (Do, 22. Okt 2009) by dajamesthomas for revision 3966

Field Summary
static String DEFAULT_DATE_WITH_COLON
          dd:MM:YYYY
static String DEFAULT_DATE_WITH_PERIOD
          dd.MM.YYYY
static String DEFAULT_DATE_WITH_WHITESPACE
          dd MM YYYY
static String DEFAULT_DATETIME
          dd.MM.YY HH:mm:ss
static String TIME_WITH_COLON
          HH:mm:ss
static String TIME_WITH_PERIOD
          HH.mm.ss
static String TIME_WITH_WHITESPACE
          HH mm ss
 
Constructor Summary
protected JodaTimeUtils()
          Hide default constructor.
 
Method Summary
static String getDateTimeString(org.joda.time.DateTime date, String pattern)
          Returns a string containing the date and/or time from the DateTime.
static String getLocalDateString(org.joda.time.LocalDate date, String pattern)
          Returns a string containing the date in a LocalDate.
static String getLocalTimeString(org.joda.time.LocalTime time, String pattern)
          Returns a string containing the time in a LocalTime.
static org.joda.time.DateTime mergeLocalDateAndLocalTime(org.joda.time.LocalDate date, org.joda.time.LocalTime time)
          Creates a DateTime out of a LocalDate and a LocalTime.
static org.joda.time.DateTime parseDateTime(String dateTime, String pattern)
          Returns a DateTime containing the date/time in the string.
static org.joda.time.DateTime parseDateTime(String dateTime, String pattern, Locale locale)
          Returns a localized DateTime containing the time in the string.
static org.joda.time.LocalDate parseLocalDate(String date, String pattern)
          Returns a LocalDate containing the date in the string.
static org.joda.time.LocalTime parseLocalTime(String time, String pattern)
          Returns a LocalTime containing the time in the string.
static org.joda.time.DateTime setDateOfDateTime(org.joda.time.DateTime dateTime, org.joda.time.LocalDate date)
          Sets the Date (but not the time) of a DateTime to the value in date.
static org.joda.time.DateTime setTimeOfDateTime(org.joda.time.DateTime dateTime, org.joda.time.LocalTime time)
          Changes the time (but not the date) of a DateTime to the time in a LocalTime.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_DATE_WITH_PERIOD

public static final String DEFAULT_DATE_WITH_PERIOD
dd.MM.YYYY

See Also:
Constant Field Values

DEFAULT_DATE_WITH_COLON

public static final String DEFAULT_DATE_WITH_COLON
dd:MM:YYYY

See Also:
Constant Field Values

DEFAULT_DATE_WITH_WHITESPACE

public static final String DEFAULT_DATE_WITH_WHITESPACE
dd MM YYYY

See Also:
Constant Field Values

TIME_WITH_PERIOD

public static final String TIME_WITH_PERIOD
HH.mm.ss

See Also:
Constant Field Values

TIME_WITH_COLON

public static final String TIME_WITH_COLON
HH:mm:ss

See Also:
Constant Field Values

TIME_WITH_WHITESPACE

public static final String TIME_WITH_WHITESPACE
HH mm ss

See Also:
Constant Field Values

DEFAULT_DATETIME

public static final String DEFAULT_DATETIME
dd.MM.YY HH:mm:ss

See Also:
Constant Field Values
Constructor Detail

JodaTimeUtils

protected JodaTimeUtils()
Hide default constructor.

Method Detail

getDateTimeString

public static String getDateTimeString(org.joda.time.DateTime date,
                                       String pattern)
Returns a string containing the date and/or time from the DateTime. The format of the returned string is defined by the pattern. (e.g. "dd.MM.YYYY hh.mm.ss" for "26.8.2009 08.26.52")

Parameters:
date - is the DateTime to process
pattern - is the pattern to apply
Returns:
a string with the date/time in the specified format

getLocalDateString

public static String getLocalDateString(org.joda.time.LocalDate date,
                                        String pattern)
Returns a string containing the date in a LocalDate. The format of the returned string is defined by the pattern. Attention: any time related characters in the pattern will be set to 0. (e.g. 'mm' in the pattern will result in a '00' as there is no time in a LocalDate.

Parameters:
date - is the LocalDate to process
pattern - is the pattern to apply
Returns:
a string with the date in the format specified by pattern

getLocalTimeString

public static String getLocalTimeString(org.joda.time.LocalTime time,
                                        String pattern)
Returns a string containing the time in a LocalTime. The format of the returned string is defined by the pattern. Attention: any date related characters will be set to 0. (e.g. 'MM' in the pattern will result in a '00').

Parameters:
time - is the LocalTime to process
pattern - is the pattern to apply
Returns:
a string with the time in the format specified by pattern

parseDateTime

public static org.joda.time.DateTime parseDateTime(String dateTime,
                                                   String pattern)
Returns a DateTime containing the date/time in the string. The dateTime string must match the pattern so that all values can be set.

Parameters:
dateTime - is the string to process
pattern - is the pattern to apply
Returns:
a DateTime object that contains all values that could be matched

parseLocalDate

public static org.joda.time.LocalDate parseLocalDate(String date,
                                                     String pattern)
Returns a LocalDate containing the date in the string. The date string must match the pattern so that all values can be set.

Parameters:
date - is the string to process
pattern - is the pattern to apply
Returns:
a LocalDate object that contains all values that could be matched

parseLocalTime

public static org.joda.time.LocalTime parseLocalTime(String time,
                                                     String pattern)
Returns a LocalTime containing the time in the string. The date string must match the pattern so that all values can be set.

Parameters:
time - is the string to process
pattern - is the pattern to apply
Returns:
a LocalTime object that contains all values that could be matched

parseDateTime

public static org.joda.time.DateTime parseDateTime(String dateTime,
                                                   String pattern,
                                                   Locale locale)
Returns a localized DateTime containing the time in the string. The dateTime string must match the pattern so that all values can be set.

Parameters:
dateTime - is the string to process
locale - is the local which is applied to the returned DateTime object
pattern - is the pattern to apply
Returns:
a DateTime object that contains all values that could be matched

mergeLocalDateAndLocalTime

public static org.joda.time.DateTime mergeLocalDateAndLocalTime(org.joda.time.LocalDate date,
                                                                org.joda.time.LocalTime time)
Creates a DateTime out of a LocalDate and a LocalTime.

Parameters:
date - is the LocalDate containing the desired date
time - is the LocalTime containing the desired time
Returns:
a new DateTime which is created out of the two arguments

setTimeOfDateTime

public static org.joda.time.DateTime setTimeOfDateTime(org.joda.time.DateTime dateTime,
                                                       org.joda.time.LocalTime time)
Changes the time (but not the date) of a DateTime to the time in a LocalTime.

Parameters:
dateTime - is the DateTime to set
time - is the time time to set to
Returns:
a DateTime object with the date of dateTime and the time of time

setDateOfDateTime

public static org.joda.time.DateTime setDateOfDateTime(org.joda.time.DateTime dateTime,
                                                       org.joda.time.LocalDate date)
Sets the Date (but not the time) of a DateTime to the value in date.

Parameters:
dateTime - is the DateTime for which we set the date
date - is the LocalDate to set the date to
Returns:
a DateTime object with the date of date and the time of dateTime


Copyright © 2005-2011 ELCA. All Rights Reserved.