Skip to content

Date functions

The luego.date package contains utility functions to work with dates.

luego.date

atTime

atTime(d: Date, h: Integer, m: Integer, s: Integer) => DateTime

Combines a date with hour, minutes and seconds to create a datetime

dateNow

dateNow() => Date

Obtains the current date from the system clock in the default time-zone. Be aware that logic that depends on the system environment is not testable so consider instead receiving the current date as an input parameter.

dateTimeNow

dateTimeNow() => DateTime

Obtains the current date-time from the system clock in the default time-zone. Be aware that logic that depends on the system environment is not testable so consider instead receiving the current date/time as an input parameter.

daysBetween

daysBetween(startDate: Date, endDate: Date) => Long

Returns the number of days between a start date and an end date. The result is positive when the start date is before the end date.

dtFormat

dtFormat(dt: DateTime, formatPattern: Text) => Text

Return a formatted string for the data time

HHmm

HHmm(dt: DateTime) => Text

Return a string concatenating the hours and the minutes of a datetime separated by a colon

HHmmss

HHmmss(dt: DateTime) => Text

Return a string concatenating hours, minutes and seconds of a datetime separated by colons

hour

hour(dt: DateTime) => Integer

Return the hour of a datetime

hoursBetween

hoursBetween(startDT: DateTime, endDT: DateTime) => Long

Returns the number of hours between a start datetime and an end datetime. The result is positive when the start datetime is before the end datetime.

isAfter

isAfter(d1: Date, d2: Date) => Boolean

Determines if the 1st date is after the 2nd date (strictly after)

isAfterOrEqual

isAfterOrEqual(d1: Date, d2: Date) => Boolean

Determines if the 1st date is after or equal to the 2nd date

isBefore

isBefore(d1: Date, d2: Date) => Boolean

Determines if the date d1 is before the date d2 (stricly before)

isBeforeOrEqual

isBeforeOrEqual(d1: Date, d2: Date) => Boolean

Determines if the date d1 is before or equal to the date d2

minusDays

minusDays(d: Date, n: Integer) => Date

Returns a copy of the date with the specified number of days subtracted

minusMonths

minusMonths(d: Date, n: Integer) => Date

Returns a copy of the date with the specified number of months subtracted

minusWeeks

minusWeeks(d: Date, n: Integer) => Date

Returns a copy of the date with the specified number of weeks subtracted

minusYears

minusYears(d: Date, n: Integer) => Date

Returns a copy of the date with the specified number of years subtracted

minute

minute(dt: DateTime) => Integer

Return the minute of a datetime

minutesBetween

minutesBetween(startDT: DateTime, endDT: DateTime) => Long

Returns the number of minutes between a start datetime and an end datetime. The result is positive when the start datetime is before the end datetime.

monthsBetween

monthsBetween(startDate: Date, endDate: Date) => Long

Returns the number of months between a start date and an end date. The result is positive when the start date is before the end date.

plusDays

plusDays(d: Date, n: Integer) => Date

Returns a copy of the date d with the specified number of days n added

plusHours

plusHours(dt: DateTime, n: Integer) => DateTime

Returns a copy of the datetime dt with the specified number of hours n added

plusMinutes

plusMinutes(dt: DateTime, n: Integer) => DateTime

Returns a copy of the datetime dt with the specified number of minutes n added

plusMonths

plusMonths(d: Date, n: Integer) => Date

Returns a copy of the date d with the specified number of months n added

plusWeeks

plusWeeks(d: Date, n: Integer) => Date

Returns a copy of the date with the specified number of weeks added

plusYears

plusYears(d: Date, n: Integer) => Date

Returns a copy of the date d with the specified number of years n added

second

second(dt: DateTime) => Integer

Return the second of a datetime

secondsBetween

secondsBetween(startDT: DateTime, endDT: DateTime) => Long

Returns the number of seconds between a start datetime and an end datetime. The result is positive when the start datetime is before the end datetime.

toDate

toDate(dt: DateTime) => Date

Extract a date from a datetime

weeksBetween

weeksBetween(startDate: Date, endDate: Date) => Long

Returns the number of weeks between a start date and an end date. The result is positive when the start date is before the end date.

yearsBetween

yearsBetween(startDate: Date, endDate: Date) => Long

Returns the number of years between a start date and an end date. The result is positive when the start date is before the end date.