|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.apache.myfaces.dateformat.SimpleDateFormatter
public class SimpleDateFormatter
A reimplementation of the java.text.SimpleDateFormat class.
This class has been created for use with the tomahawk InputCalendar component. It exists for the following reasons:
This implementation does extend the SimpleDateFormat class by adding the JODA "xxxx" yearOfWeekYear format option, as this is missing in the standard SimpleDateFormat class.
The parse methods also return null on error rather than throw an exception.
The code here was originally written in javascript (date.js), and has been ported to java.
At the current time, the following format options are NOT supported:
DFkKSzZ
.
ISO standard ISO-8601 defines a calendaring system based not upon year/month/day_in_month but instead year/week/day_in_week. This is particularly popular in embedded systems as date arithmetic is much simpler; there are no irregular month lengths to handle.
The only tricky part is mapping to and from year/month/day formats. Unfortunately, while java.text.SimpleDateFormat does support a "ww" week format character, it has a number of flaws.
Weeks are always complete and discrete, ie week yyyy-ww always has 7 days in it, and never "shares" days with yyyy-(ww+1). However to achieve this, the last week of a year might include a few days of the next year, or the last few days of a year might be counted as part of the first week of the following year. The decision is made depending on which year the "majority" of days in that week belong to.
With ISO-8601, a week always starts on a monday. However many countries use a different convention, starting weeks on saturday, sunday or monday. This class supports setting the firstDayOfWeek.
Constructor Summary | |
---|---|
SimpleDateFormatter(String pattern,
DateFormatSymbols symbols)
Constructor that sets the firstDayOfWeek to the ISO standard (1=monday). |
|
SimpleDateFormatter(String pattern,
DateFormatSymbols symbols,
int firstDayOfWeek)
Constructor. |
Method Summary | |
---|---|
String |
format(Date date)
|
Date |
getDateForWeekDate(WeekDate wdate)
|
static WeekDate |
getIsoWeekDate(Date date)
Return the ISO week# represented by the specified date (1..53). |
WeekDate |
getWeekDate(Date date)
|
static WeekDate |
getWeekDate(Date date,
int firstDayOfWeek)
Return the (year, week) representation of the given date. |
Date |
parse(String dateStr)
|
void |
setFirstDayOfWeek(int dow)
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public SimpleDateFormatter(String pattern, DateFormatSymbols symbols, int firstDayOfWeek)
firstDayOfWeek
- uses java.util.Date convention, ie 0=sun, 1=mon, 6=sat.public SimpleDateFormatter(String pattern, DateFormatSymbols symbols)
Method Detail |
---|
public static WeekDate getIsoWeekDate(Date date)
public static WeekDate getWeekDate(Date date, int firstDayOfWeek)
This is exactly like getIsoWeekNumber, except that a firstDayOfWeek can be specified; ISO-8601 hard-wires "monday" as first day of week.
TODO: support minimumDaysInWeek property. Currently, assumes this is set to 4 (the ISO standard).
firstDayOfWeek
- is: 0=sunday, 1=monday, 6=sat. This is the
convention used by java.util.Date. NOTE: java.util.Calendar uses
1=sunday, 2=monday, 7=saturday.public void setFirstDayOfWeek(int dow)
public Date parse(String dateStr)
public String format(Date date)
public WeekDate getWeekDate(Date date)
public Date getDateForWeekDate(WeekDate wdate)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |