Functions: FnDate

1. Overview

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

2. Functions

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

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

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

addDaysFunction<Date,Date>int amount

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

addHoursFunction<Date,Date>int amount

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

addMillisecondsFunction<Date,Date>int amount

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

addMinutesFunction<Date,Date>int amount

Modifies a Date by adding a positive or negative amount to one the "minutes" property (java.util.Calendar.MINUTES).

addMonthsFunction<Date,Date>int amount

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

addWeeksFunction<Date,Date>int amount

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

addYearsFunction<Date,Date>int amount

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

afterFunction<Date,Boolean>Date date

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

beforeFunction<Date,Boolean>Date date

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

eqFunction<Object,Boolean>Date object

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

fieldIntegerArrayToDateFunction<Integer[], Date>

Converts an Integer[] containing the components of a date to a java.util.Date 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
fieldIntegerListToDateFunction<List<Integer>, Date>

Converts a List<Integer> containing the components of a date to a java.util.Date 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
fieldStringArrayToDateFunction<String[], Date>

Converts a String[] containing the components of a date to a java.util.Date 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
fieldStringListToDateFunction<List<String>, Date>

Converts a List<String> containing the components of a date to a java.util.Date 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>Date object

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

roundFunction<Date,Date>int calendarField

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

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

setFunction<Date,Date>int calendarField
int value

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

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

setDayFunction<Date,Date>int value

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

setHourFunction<Date,Date>int value

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

setMillisecondFunction<Date,Date>int value

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

setMinuteFunction<Date,Date>int value

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

setMonthFunction<Date,Date>int value

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

setWeekFunction<Date,Date>int value

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

setYearFunction<Date,Date>int value

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

timeInMillisToDateFunction<Long,Date>

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

timeInMillisToDateFunction<Long,Date>int truncateField

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

timestampToDateFunction<Timestamp,Date>

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

timestampToDateFunction<Timestamp,Date>int truncateField

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

toCalendarFunction<Date,Calendar>
toCalendarFunction<Date,Calendar>int truncateField
toStrFunction<Date,String>String pattern

Converts the target Date 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<Date,String>String pattern
Locale locale

Converts the target Date 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<Date,String>String pattern
String locale

Converts the target Date 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<Date,String>DateStyle dateStyle
TimeStyle timeStyle

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

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

Converts the target Date 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<Date,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<Date,Date>int calendarField

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

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