Package org.primefaces.util
Class CalendarUtils
- java.lang.Object
-
- org.primefaces.util.CalendarUtils
-
public class CalendarUtils extends Object
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static TimeZone
calculateTimeZone(Object usertimeZone)
static TimeZone
calculateTimeZone(Object usertimeZone, TimeZone defaultTimeZone)
static ZoneId
calculateZoneId(Object usertimeZone)
static ZoneId
calculateZoneId(Object usertimeZone, ZoneId defaultZoneId)
static ZoneOffset
calculateZoneOffset(Object usertimeZone)
static ZoneOffset
calculateZoneOffset(Object usertimeZone, ZoneId defaultZoneId)
static LocalDate
convertDate2LocalDate(Date date)
static LocalDate
convertDate2LocalDate(Date date, ZoneId zoneId)
static LocalDateTime
convertDate2LocalDateTime(Date date)
static LocalDateTime
convertDate2LocalDateTime(Date date, ZoneId zoneId)
static LocalTime
convertDate2LocalTime(Date date)
static LocalTime
convertDate2LocalTime(Date date, ZoneId zoneId)
static Date
convertLocalDate2Date(LocalDate localDate, ZoneId zoneId)
static Date
convertLocalDateTime2Date(LocalDateTime localDateTime)
static Date
convertLocalDateTime2Date(LocalDateTime localDateTime, ZoneId zoneId)
static Date
convertLocalTime2Date(LocalTime localTime, ZoneId zoneId)
static String
convertPattern(String pattern)
Converts a java date pattern to a jquery UI date picker pattern.static void
encodeListValue(javax.faces.context.FacesContext context, UICalendar uicalendar, String optionName, List<?> values, String pattern)
Write the value of Calendar optionsstatic Instant
getObjectAsInstant(javax.faces.context.FacesContext context, UICalendar calendar, Object value, String attributeName)
Try to convert the given value to anInstant
or returnnull
if there is no appropriate converter for doing so.static LocalDate
getObjectAsLocalDate(javax.faces.context.FacesContext context, UICalendar calendar, Object value)
Try to convert the given value toLocalDate
or returnnull
if there is no appropriate converter for doing so.static LocalTime
getObjectAsLocalTime(javax.faces.context.FacesContext context, UICalendar calendar, Object value)
Try to convert the given value toLocalTime
or returnnull
if there is no appropriate converter for doing so.static String
getTimeOnlyValueAsString(javax.faces.context.FacesContext context, UICalendar calendar)
static String
getValue(javax.faces.context.FacesContext context, UICalendar calendar, Object value, String pattern)
static String
getValueAsString(javax.faces.context.FacesContext context, UICalendar calendar)
static String
getValueAsString(javax.faces.context.FacesContext context, UICalendar calendar, Object value)
static String
getValueAsString(javax.faces.context.FacesContext context, UICalendar calendar, Object value, String pattern)
static boolean
hasTime(String pattern)
static Temporal
now(UICalendar uicalendar)
Calculates NOW based on the calendar's current timezone or will default to system timezone if none set.static Object
now(UICalendar uicalendar, Class<?> dateType)
Calculates NOW based on the calendar's current timezone or will default to system timezone if none set.static String
removeTime(String pattern)
static List<String>
splitRange(String dateRange, String pattern, String separator)
static LocalDateTime
toLocalDateTime(ZoneId zoneId, String isoDateString)
Convert ISO-String (@see https://developer.mozilla.org/de/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString) to LocalDateTime.
-
-
-
Method Detail
-
getValueAsString
public static final String getValueAsString(javax.faces.context.FacesContext context, UICalendar calendar)
-
getObjectAsLocalDate
public static LocalDate getObjectAsLocalDate(javax.faces.context.FacesContext context, UICalendar calendar, Object value)
Try to convert the given value toLocalDate
or returnnull
if there is no appropriate converter for doing so.- Parameters:
context
- the faces contextcalendar
- the calendar componentvalue
- the value to convert- Returns:
- the
LocalDate
object ornull
-
getObjectAsLocalTime
public static LocalTime getObjectAsLocalTime(javax.faces.context.FacesContext context, UICalendar calendar, Object value)
Try to convert the given value toLocalTime
or returnnull
if there is no appropriate converter for doing so.- Parameters:
context
- the faces contextcalendar
- the calendar componentvalue
- the value to convert- Returns:
- the
LocalTime
object ornull
-
getObjectAsInstant
public static Instant getObjectAsInstant(javax.faces.context.FacesContext context, UICalendar calendar, Object value, String attributeName)
Try to convert the given value to anInstant
or returnnull
if there is no appropriate converter for doing so. The type of the value must be one ofLocalDateTime
,LocalDate
,LocalTime
,Date
(deprecated), or a parsable date or timeString
. For any other this method throws aFacesException
.- Parameters:
context
- the faces contextcalendar
- the calendar componentvalue
- the value to convertattributeName
- the attribute name of the value (e.g. mindate, or maxdate)- Returns:
- the
Instant
object ornull
- Throws:
javax.faces.FacesException
- if value type is not supported
-
getValueAsString
public static final String getValueAsString(javax.faces.context.FacesContext context, UICalendar calendar, Object value)
-
getTimeOnlyValueAsString
public static final String getTimeOnlyValueAsString(javax.faces.context.FacesContext context, UICalendar calendar)
-
getValueAsString
public static final String getValueAsString(javax.faces.context.FacesContext context, UICalendar calendar, Object value, String pattern)
-
getValue
public static final String getValue(javax.faces.context.FacesContext context, UICalendar calendar, Object value, String pattern)
-
convertPattern
public static final String convertPattern(String pattern)
Converts a java date pattern to a jquery UI date picker pattern.- Parameters:
pattern
- Pattern to be converted- Returns:
- converted pattern
-
encodeListValue
public static void encodeListValue(javax.faces.context.FacesContext context, UICalendar uicalendar, String optionName, List<?> values, String pattern) throws IOException
Write the value of Calendar options- Parameters:
context
-uicalendar
- componentoptionName
- the name of an optionvalues
- the List values of an optionpattern
- the pattern for formatting- Throws:
IOException
- if writer is null
-
calculateTimeZone
public static TimeZone calculateTimeZone(Object usertimeZone, TimeZone defaultTimeZone)
-
calculateZoneOffset
public static ZoneOffset calculateZoneOffset(Object usertimeZone)
-
calculateZoneOffset
public static ZoneOffset calculateZoneOffset(Object usertimeZone, ZoneId defaultZoneId)
-
convertDate2LocalDateTime
public static LocalDateTime convertDate2LocalDateTime(Date date)
-
convertDate2LocalDateTime
public static LocalDateTime convertDate2LocalDateTime(Date date, ZoneId zoneId)
-
convertLocalDateTime2Date
public static Date convertLocalDateTime2Date(LocalDateTime localDateTime)
-
convertLocalDateTime2Date
public static Date convertLocalDateTime2Date(LocalDateTime localDateTime, ZoneId zoneId)
-
hasTime
public static final boolean hasTime(String pattern)
-
toLocalDateTime
public static LocalDateTime toLocalDateTime(ZoneId zoneId, String isoDateString)
Convert ISO-String (@see https://developer.mozilla.org/de/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString) to LocalDateTime.- Parameters:
zoneId
- Target-ZoneId of the LocalDateTime, the isoDateString is converted into.isoDateString
-- Returns:
-
now
public static Temporal now(UICalendar uicalendar)
Calculates NOW based on the calendar's current timezone or will default to system timezone if none set. It will return a LocalDateTime if time units needed else just a LocalDate if no time is needed.- Parameters:
uicalendar
- the base calendar to calculate NOW for- Returns:
- a Temporal representing either a Date or DateTime
-
now
public static Object now(UICalendar uicalendar, Class<?> dateType)
Calculates NOW based on the calendar's current timezone or will default to system timezone if none set.- Parameters:
uicalendar
- the base calendar to calculate NOW for- Returns:
- an Object representing either a Date or Temporal
-
-