Functions: FnCalendar

1. Overview

FnCalendar is a function hub class containing a lot of static methods to work with Calendar objects. Those static methods return functions that take a Calendar object as its input or output (depending on the function). It includes conversions to String, to Calendar and adding days to a Calendar among others.

2. Functions

Function nameTypeParamsDescription
addFunction<Calendar,Calendar>int calendarField
int amount

Modifies a Calendar by adding a positive or negative amount to one of its fields.

Fields are specified by means of java.util.Calendar constants, like FnCalendar.add(Calendar.DAY_OF_MONTH, 1).

addDaysFunction<Calendar,Calendar>int amount

Modifies a Calendar by adding a positive or negative amount to one the "day" property (java.util.Calendar.DATE).

addHoursFunction<Calendar,Calendar>int amount

Modifies a Calendar by adding a positive or negative amount to one the "hour" property (java.util.Calendar.HOUR).

addMillisecondsFunction<Calendar,Calendar>int amount

Modifies a Calendar by adding a positive or negative amount to one the "millisecond" property (java.util.Calendar.MILLISECOND).

addMinutesFunction<Calendar,Calendar>int amount

Modifies a Calendar by adding a positive or negative amount to one the "minute" property (java.util.Calendar.MINUTE).

addMonthsFunction<Calendar,Calendar>int amount

Modifies a Calendar by adding a positive or negative amount to one the "month" property (java.util.Calendar.MONTH).

addWeeksFunction<Calendar,Calendar>int amount

Modifies a Calendar by adding a positive or negative amount to one the "week" property (java.util.Calendar.WEEK_OF_YEAR).

addYearsFunction<Calendar,Calendar>int amount

Modifies a Calendar by adding a positive or negative amount to one the "year" property (java.util.Calendar.YEAR).

afterFunction<Calendar,Boolean>Calendar calendar

Determines whether the target Calendar represents a moment in time after the Calendar specified as a parameter.

beforeFunction<Calendar,Boolean>Calendar calendar

Determines whether the target Calendar represents a moment in time before the Calendar specified as a parameter.

eqFunction<Object,Boolean>Calendar object

Determines whether the target object and the specified object are equal by calling the equals method on the target object.

fieldIntegerArrayToCalendarFunction<Integer[], Calendar>

Converts an Integer[] containing the components of a date to a java.util.Calendar object.

The target array can contain the following combinations of elements, in the specified order:

  • year, month, day
  • year, month, day, hour, minute
  • year, month, day, hour, minute, second
  • year, month, day, hour, minute, second, millisecond
fieldIntegerListToCalendarFunction<List<Integer>, Calendar>

Converts a List<Integer> containing the components of a date to a java.util.Calendar object.

The target list can contain the following combinations of elements, in the specified order:

  • year, month, day
  • year, month, day, hour, minute
  • year, month, day, hour, minute, second
  • year, month, day, hour, minute, second, millisecond
fieldStringArrayToCalendarFunction<String[], Calendar>

Converts a String[] containing the components of a date to a java.util.Calendar object.

The target array can contain the following combinations of elements, all of them in numeric format, in the specified order:

  • year, month, day
  • year, month, day, hour, minute
  • year, month, day, hour, minute, second
  • year, month, day, hour, minute, second, millisecond
fieldStringListToCalendarFunction<List<String>, Calendar>

Converts a List<String> containing the components of a date to a java.util.Calendar object.

The target list can contain the following combinations of elements, all of them in numeric format, in the specified order:

  • year, month, day
  • year, month, day, hour, minute
  • year, month, day, hour, minute, second
  • year, month, day, hour, minute, second, millisecond
isNotNullFunction<Object,Boolean>

Determines whether the target object is null or not.

isNullFunction<Object,Boolean>

Determines whether the target object is null or not.

notEqFunction<Object,Boolean>Calendar object

Determines whether the target object and the specified object are NOT equal by calling the equals method on the target object.

roundFunction<Calendar,Calendar>int calendarField

Rounds the target Calendar, setting the specified field as the most significant field.

Based on org.apache.commons.lang.time.DateUtils.round().

setFunction<Calendar,Calendar>int calendarField
int value

Modifies a Calendar by setting one of its to the specified value.

Fields are specified by means of java.util.Calendar constants, like FnCalendar.set(Calendar.DAY_OF_MONTH, 12).

setDayFunction<Calendar,Calendar>int value

Modifies a Calendar by setting the "day" property (java.util.Calendar.DATE) to the specified value.

setHourFunction<Calendar,Calendar>int value

Modifies a Calendar by setting the "hour" property (java.util.Calendar.HOUR) to the specified value.

setMillisecondFunction<Calendar,Calendar>int value

Modifies a Calendar by setting the "millisecond" property (java.util.Calendar.MILLISECOND) to the specified value.

setMinuteFunction<Calendar,Calendar>int value

Modifies a Calendar by setting the "minute" property (java.util.Calendar.MINUTE) to the specified value.

setMonthFunction<Calendar,Calendar>int value

Modifies a Calendar by setting the "month" property (java.util.Calendar.MONTH) to the specified value.

setWeekFunction<Calendar,Calendar>int value

Modifies a Calendar by setting the "week" property (java.util.Calendar.WEEK_OF_YEAR) to the specified value.

setYearFunction<Calendar,Calendar>int value

Modifies a Calendar by setting the "year" property (java.util.Calendar.YEAR) to the specified value.

timeInMillisToCalendarFunction<Long,Calendar>

Converts the target Long (representing a time in milliseconds) into a Calendar.

timeInMillisToCalendarFunction<Long,Calendar>int truncateField

Converts the target Long (representing a time in milliseconds) into a Calendar, truncating by the specified field (java.util.Calendar constant field).

timestampToCalendarFunction<Timestamp,Calendar>

Converts the target java.sql.Timestamp into a Calendar.

timestampToCalendarFunction<Timestamp,Calendar>int truncateField

Converts the target java.sql.Timestamp into a Calendar, truncating by the specified field (java.util.Calendar constant field).

toStrFunction<Calendar,String>String pattern

Converts the target Calendar into a String using the specified pattern. The pattern has to be written in the java.text.SimpleDateFormat format.

As no locale is specified, if pattern includes locale-dependent texts like month names (MMM) or week days (EEE), the default locale will be used for resolving these components.

toStrFunction<Calendar,String>String pattern
Locale locale

Converts the target Calendar into a String using the specified pattern. The pattern has to be written in the java.text.SimpleDateFormat format, and the specified locale will be used for text-based pattern components (like month names or week days).

toStrFunction<Calendar,String>String pattern
String locale

Converts the target Calendar into a String using the specified pattern. The pattern has to be written in the java.text.SimpleDateFormat format, and the specified locale will be used for text-based pattern components (like month names or week days).

toStrFunction<Calendar,String>DateStyle dateStyle
TimeStyle timeStyle

Converts the target Calendar into a String using the specified date ( DateStyle) and time ( TimeStyle) styles.

toStrFunction<Calendar,String>DateStyle dateStyle
TimeStyle timeStyle
Locale locale

Converts the target Calendar into a String using the specified date ( DateStyle) and time ( TimeStyle) styles, and resolving text-based components like month names using the specified locale.

toStrFunction<Calendar,String>DateStyle dateStyle
TimeStyle timeStyle
String locale

Converts the target Calendar into a String using the specified date ( DateStyle) and time ( TimeStyle) styles, and resolving text-based components like month names using the specified locale.

truncateFunction<Calendar,Calendar>int calendarField

Truncates the target Calendar, setting the specified field as the most significant field.

Based on org.apache.commons.lang.time.DateUtils.truncate().