Class CmsDateConverter
java.lang.Object
org.opencms.gwt.client.ui.input.datebox.CmsDateConverter
This class is an Helper with mostly static methods that convert a given date object
or that convert a given String.
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic StringCuts the suffix (am or pm) from a given time String.static StringdateToString(Date date) Formats the provided date to a date only representation.static DategetDateWithTime(Date date, String time) Merges a given Date object with a given time String.static DategetDateWithTime(Date date, String time, com.google.gwt.i18n.client.DateTimeFormat timeFormat) Changes the time portion of date to another value.static StringReturns the short time format of a given date as String.static booleanReturnstrueif the current date format is in the 12 hour representation modefalseotherwise.static booleanReturnstrueif an am is in the given date objectfalseotherwise.static DateParses the provided String as a date.static StringtoDateString(Date date) Formats the provided date as only a date format (dd/mm/yyyy).static DateParses the provided String as a date.static StringFormats the provided date.static booleanvalidateDate(Date date) Validates a time String if it matches one of the two regular expressions.static booleanvalidateTime(String time) Validates a time String if it matches the regular expressions.
-
Field Details
-
AM
A constant for am.- See Also:
-
PM
A constant for pm.- See Also:
-
-
Method Details
-
cutSuffix
Cuts the suffix (am or pm) from a given time String.If the given String has less than 5 characters an dosen't contains an am or pm in it the original String is returned.
- Parameters:
time- the time String to cut the suffix from- Returns:
- the time String without the suffix or the original String if the format of the String is incorrect
-
dateToString
Formats the provided date to a date only representation.- Parameters:
date- the date to format- Returns:
- the formatted date as a string
-
getDateWithTime
Merges a given Date object with a given time String.Returns a
nullif the given time format coudn't be parsed.The expected time String should include the am pm information if the time format is in 12 hour presentation.
- Parameters:
date- the given Date object which time has to be settime- the given time String which should be inserted into the Date Object- Returns:
- the merged date Object
-
getDateWithTime
public static Date getDateWithTime(Date date, String time, com.google.gwt.i18n.client.DateTimeFormat timeFormat) Changes the time portion of date to another value.- Parameters:
date- the original datetime- the string representing the time to be set in the resulttimeFormat- the format to use for parsing the time- Returns:
- a new Date with the date from the date parameter and the time from the time parameter.
-
getTime
Returns the short time format of a given date as String.- Parameters:
date- the date to get the short time format from- Returns:
- the short time format of a given date
-
is12HourPresentation
Returnstrueif the current date format is in the 12 hour representation modefalseotherwise.- Returns:
trueif an am or a pm is in a new Date objectfalseotherwise
-
isAm
Returnstrueif an am is in the given date objectfalseotherwise.- Parameters:
date- the date to check- Returns:
trueif an am is in the given Date objectfalseotherwise
-
toDate
Parses the provided String as a date.First try to parse the String with the given time format.
If that fails try to parse the date with the browser settings.
- Parameters:
dateText- the string representing a date- Returns:
- the date created, or null if there was a parse error
- Throws:
Exception- in case the text can not be parsed to a date
-
toDateString
Formats the provided date as only a date format (dd/mm/yyyy). Note, a null date is a possible input.- Parameters:
date- the date to format- Returns:
- the formatted date as a string
-
toDayDate
Parses the provided String as a date.First try to parse the String with the given time format.
If that fails try to parse the date with the browser settings.
- Parameters:
dateText- the string representing a date- Returns:
- the date created, or null if there was a parse error
- Throws:
Exception- in case the text can not be parsed to a date
-
toString
Formats the provided date. Note, a null date is a possible input.- Parameters:
date- the date to format- Returns:
- the formatted date as a string
-
validateDate
Validates a time String if it matches one of the two regular expressions.Returns
trueif the given date matches to one of the regular expressions,falseotherwise.- Parameters:
date- the date String to check- Returns:
trueif the given time matches to one of the regular expressions,falseotherwise
-
validateTime
Validates a time String if it matches the regular expressions.Returns
trueif the given time matches the regular expressions,falseotherwise.- Parameters:
time- the time String to check- Returns:
trueif the given time matches the regular expressions,falseotherwise
-