org.apache.tapestry.util
Class Strftime

java.lang.Object
  extended by org.apache.tapestry.util.Strftime

public class Strftime
extends Object

Converts dates to strings using the same format specifiers as strftime Note: This does not mimic strftime perfectly. Certain strftime commands, are not supported, and will convert as if they were literals. Certain complicated commands, like those dealing with the week of the year probably don't have exactly the same behavior as strftime. These limitations are due to use SimpleDateTime. If the conversion was done manually, all these limitations could be eliminated. The interface looks like a subset of DateFormat. Maybe someday someone will make this class extend DateFormat.

Added to tapestry in order to help with dojo/javascript date/time conversions.

Author:
Bip Thelin, Dan Sandberg
See Also:
"http://www.opengroup.org/onlinepubs/007908799/xsh/strftime.html"

Field Summary
protected static Properties pTranslate
           
protected  SimpleDateFormat simpleDateFormat
           
protected static Properties translate
           
 
Constructor Summary
Strftime(String origFormat)
          Create an instance of this date formatting class.
Strftime(String origFormat, Locale locale)
          Create an instance of this date formatting class.
 
Method Summary
static String convertDateFormat(String pattern)
          Search the provided pattern and get the C standard Date/Time formatting rules and convert them to the Java equivalent.
static String convertToPosixFormat(String pattern)
          Does the exact opposite of {convertDateFormat(String) by converting the incoming java date format string into a POSIX compliant format string.
 String format(Date date)
          Format the date according to the strftime-style string given in the constructor.
 TimeZone getTimeZone()
          Get the timezone used for formatting conversions.
 Date parse(String input)
          Parses the input.
 void setTimeZone(TimeZone timeZone)
          Change the timezone used to format dates.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

translate

protected static Properties translate

pTranslate

protected static Properties pTranslate

simpleDateFormat

protected SimpleDateFormat simpleDateFormat
Constructor Detail

Strftime

public Strftime(String origFormat)
Create an instance of this date formatting class.

See Also:
Strftime( String, Locale )

Strftime

public Strftime(String origFormat,
                Locale locale)
Create an instance of this date formatting class.

Parameters:
origFormat - the strftime-style formatting string
locale - the locale to use for locale-specific conversions
Method Detail

format

public String format(Date date)
Format the date according to the strftime-style string given in the constructor.

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

parse

public Date parse(String input)
           throws ParseException
Parses the input.

Parameters:
input - The string to parse.
Returns:
A parsed Date.
Throws:
ParseException - On input error.
See Also:
DateFormat.parse(String)

getTimeZone

public TimeZone getTimeZone()
Get the timezone used for formatting conversions.

Returns:
the timezone

setTimeZone

public void setTimeZone(TimeZone timeZone)
Change the timezone used to format dates.

See Also:
DateFormat.setTimeZone(TimeZone)

convertToPosixFormat

public static String convertToPosixFormat(String pattern)
Does the exact opposite of {convertDateFormat(String) by converting the incoming java date format string into a POSIX compliant format string.

Parameters:
pattern - The java date format style format
Returns:
The converted format into something usable by POSIX strftime style parser/formatters.

convertDateFormat

public static String convertDateFormat(String pattern)
Search the provided pattern and get the C standard Date/Time formatting rules and convert them to the Java equivalent.

Parameters:
pattern - The pattern to search
Returns:
The modified pattern


Copyright © 2006-2008 Apache Software Foundation. All Rights Reserved.