com.vaadin.terminal.gwt.client.
Class DateTimeService
java.lang.Object
com.vaadin.terminal.gwt.client.DateTimeService
- extends Object
public class DateTimeService
This class provides date/time parsing services to all components on the client side.
Author:
Vaadin Ltd.
Constructor Summary | |
---|---|
DateTimeService()
Creates a new date time service with the application default locale. |
|
DateTimeService(String locale)
Creates a new date time service with a given locale. |
Method Summary | |
---|---|
String |
formatDate(Date date,
String formatStr)
Check if format contains the month name. |
String[] |
getAmPmStrings()
|
String |
getClockDelimeter()
|
String |
getDay(int day)
|
int |
getFirstDayOfWeek()
|
static int |
getISOWeekNumber(Date date)
Returns the ISO-8601 week number of the given date. |
String |
getLocale()
|
static int |
getMilliseconds(Date date)
|
String |
getMonth(int month)
|
static int |
getNumberOfDaysInMonth(Date date)
|
String |
getShortDay(int day)
|
String |
getShortMonth(int month)
|
int |
getStartWeekDay(Date date)
|
static boolean |
isInRange(Date date,
Date rangeStart,
Date rangeEnd,
int resolution)
|
static boolean |
isLeapYear(Date date)
|
static boolean |
isSameDay(Date d1,
Date d2)
|
boolean |
isTwelveHourClock()
|
Date |
parseDate(String dateString,
String formatString,
boolean lenient)
Parses the given date string using the given format string and the locale set in this DateTimeService instance. |
void |
setLocale(String locale)
|
static void |
setMilliseconds(Date date,
int ms)
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
DateTimeService
public DateTimeService()
Creates a new date time service with the application default locale.
DateTimeService
public DateTimeService(String locale)
throws LocaleNotLoadedException
- Parameters:
locale
- e.g. fi, en etc.- Throws:
LocaleNotLoadedException
Creates a new date time service with a given locale.
Method Detail |
---|
setLocale
public void setLocale(String locale)
throws LocaleNotLoadedException
- Throws:
LocaleNotLoadedException
getLocale
public String getLocale()
getMonth
public String getMonth(int month)
getShortMonth
public String getShortMonth(int month)
getDay
public String getDay(int day)
getShortDay
public String getShortDay(int day)
getFirstDayOfWeek
public int getFirstDayOfWeek()
isTwelveHourClock
public boolean isTwelveHourClock()
getClockDelimeter
public String getClockDelimeter()
getAmPmStrings
public String[] getAmPmStrings()
getStartWeekDay
public int getStartWeekDay(Date date)
setMilliseconds
public static void setMilliseconds(Date date,
int ms)
getMilliseconds
public static int getMilliseconds(Date date)
getNumberOfDaysInMonth
public static int getNumberOfDaysInMonth(Date date)
isLeapYear
public static boolean isLeapYear(Date date)
isSameDay
public static boolean isSameDay(Date d1,
Date d2)
isInRange
public static boolean isInRange(Date date,
Date rangeStart,
Date rangeEnd,
int resolution)
getISOWeekNumber
public static int getISOWeekNumber(Date date)
- Parameters:
date
- The date for which the week number should be resolved- Returns:
- The ISO-8601 week number for date
Returns the ISO-8601 week number of the given date.
formatDate
public String formatDate(Date date,
String formatStr)
- Parameters:
date
- The date to convertformatStr
- The format string that might contain MMM or MMMMdateTimeService
- Reference to the Vaadin DateTimeService- Returns:
Check if format contains the month name. If it does we manually convert it to the month name since DateTimeFormat.format always uses the current locale and will replace the month name wrong if current locale is different from the locale set for the DateField. MMMM is converted into long month name, MMM is converted into short month name. '' are added around the name to avoid that DateTimeFormat parses the month name as a pattern.
parseDate
public Date parseDate(String dateString,
String formatString,
boolean lenient)
throws IllegalArgumentException
- Parameters:
dateString
- Date string e.g. "1 February 2010"formatString
- Format string e.g. "d MMMM yyyy"lenient
- true to use lenient parsing, false to use strict parsing- Returns:
- A Date object representing the dateString. Never returns null.
- Throws:
IllegalArgumentException
- if the parsing fails
Parses the given date string using the given format string and the locale set in this DateTimeService instance.