NB5 Docs► Reference Section► Binding Functions▼ datetime functions 🖺

Functions in this category know about times and dates, datetimes, seconds or millisecond epoch times, and so forth.

Some of the functions in this category are designed to allow testing of UUID types which are usually designed to avoid determinism. This makes it possible to test systems which depend on UUIDs but which require determinism in test data. This is strictly for testing use. Breaking the universally-unique properties of UUIDs in production systems is a bad idea. Yet, in testing, this determinism is quite useful.

CqlDurationFunctions

Map a long value into a CQL Duration object based on a set of field functions.

CurrentEpochMillis

Provide the millisecond epoch time as given by

{@code System.currentTimeMillis()}

CAUTION: This does not produce deterministic test data.

CurrentTimeMillis

DateRangeDuring

Takes an input as a reference point in epoch time, and converts it to a DateRange, with the bounds set to the lower and upper timestamps which align to the specified precision. You can use any of these precisions to control the bounds around the provided timestamp: millisecond, second, minute, hour, day, month, or year. If the zoneid is not specified, it defaults to "GMT". If the zoneid is set to "default", then the zoneid is set to the default for the JVM. Otherwise, the specified zone is used.

DateRangeFunc

Uses the precision and the two functions provided to create a DateRange. You can use any of these precisions to control the bounds around the provided timestamp: millisecond, second, minute, hour, day, month, or year. If the zoneid is not specified, it defaults to "GMT". If the zoneid is set to "default", then the zoneid is set to the default for the JVM. Otherwise, the specified zone is used.

DateRangeOnOrAfter

Takes an input as a reference point in epoch time, and converts it to a DateRange, with the lower bounds set to the lower bound of the precision and millisecond provided, and with no upper bound. You can use any of these precisions to control the bounds around the provided timestamp: millisecond, second, minute, hour, day, month, or year. If the zoneid is not specified, it defaults to "GMT". If the zoneid is set to "default", then the zoneid is set to the default for the JVM. Otherwise, the specified zone is used.

DateRangeOnOrBefore

Takes an input as a reference point in epoch time, and converts it to a DateRange, with the upper bound set to the upper bound of the precision and millisecond provided, and with no lower bound. You can use any of these precisions to control the bounds around the provided timestamp: millisecond, second, minute, hour, day, month, or year. If the zoneid is not specified, it defaults to "GMT". If the zoneid is set to "default", then the zoneid is set to the default for the JVM. Otherwise, the specified zone is used.

DateRangeParser

Parses the DateRange format according to [Date Range Formatting](https://lucene.apache.org/solr/guide/6_6/working-with-dates .html#WorkingwithDates-DateRangeFormatting). When possible it is more efficient to use the other DateRange methods since they do not require parsing.

DateTimeParser

This function will parse a String containing a formatted date time, yielding a DateTime object. If no arguments are provided, then the format is set to "yyyy-MM-dd HH:mm:ss.SSSZ". For details on formatting options, see @see DateTimeFormat

EpochMillisToCqlLocalDate

Converts epoch millis to a java.time.LocalDate, which takes the place of the previous CQL-specific LocalDate. if a zoneid of 'default' is provided, then the time zone is set by the default for the JVM. If not, then a valid ZoneId is looked up. The no-args version uses GMT.

EpochMillisToJavaLocalDate

Converts epoch millis to a java.time.{@link LocalDate} object, using either the system default timezone or the timezone provided. If the specified ZoneId is not the same as the time base of the epoch millis instant, then conversion errors will occur. Short form ZoneId values like 'CST' can be used, although US Domestic names which specify the daylight savings hours are not supported. The full list of short Ids at @see JavaSE ZoneId Ids Any timezone specifier may be used which can be read by {@link ZoneId#of(String)}

EpochMillisToJavaLocalDateTime

Converts epoch millis to a java.time.{@link LocalDateTime} object, using either the system default timezone or the timezone provided. If the specified ZoneId is not the same as the time base of the epoch millis instant, then conversion errors will occur. Short form ZoneId values like 'CST' can be used, although US Domestic names which specify the daylight savings hours are not supported. The full list of short Ids at @see JavaSE ZoneId Ids Any timezone specifier may be used which can be read by {@link ZoneId#of(String)}

LongToLocalDateDays

Days since Jan 1st 1970

StartingEpochMillis

This function sets the minimum long value to the equivalent unix epoch time in milliseconds. It simply adds the input value to this base value as determined by the provided time specifier. It wraps any overflow within this range as well.

StringDateWrapper

This function wraps an epoch time in milliseconds into a String as specified in the format. The valid formatters are documented at @see DateTimeFormat API Docs

ToCqlDuration

Convert the input double value into a CQL {@link CqlDuration} object, by setting months to zero, and using the fractional part as part of a day, assuming 24-hour days.

ToCqlDurationNanos

Convert the input value into a {@link CqlDuration} by reading the input as total nanoseconds, assuming 30-month days.

ToDate

Convert the input value to a {@code Date}, by multiplying and then dividing the input by the provided parameters.

ToDateTime

Convert the input value to a {@code org.joda.time.DateTime}

ToEpochTimeUUID

Converts a long UTC timestamp in epoch millis form into a Version 1 TimeUUID according to RFC 4122. This means that only one unique value for a timeuuid can be generated for each epoch milli value, even though version 1 TimeUUIDs can normally represent up to 10000 distinct values per millisecond. If you need to access this level of resolution for testing purposes, use {@link ToFinestTimeUUID} instead. This method is to support simple mapping to natural timestamps as we often find in the real world.

For the variants that have a String argument in the constructor, this is a parsable datetime that is used as the base time for all produced values. Setting this allows you to set the start of the time range for all timeuuid values produced. All times are parsed for UTC. All time use ISO date ordering, meaning that the most significant fields always go before the others.

The valid formats, in joda specifier form are:

  1. yyyy-MM-dd HH:mm:ss.SSSZ, for example: 2015-02-28 23:30:15.223
  2. yyyy-MM-dd HH:mm:ss, for example 2015-02-28 23:30:15
  3. yyyyMMdd'T'HHmmss.SSSZ, for example: 20150228T233015.223
  4. yyyyMMdd'T'HHmmssZ, for example: 20150228T233015
  5. yyyy-MM-dd, for example: 2015-02-28
  6. yyyyMMdd, for example: 20150228
  7. yyyyMM, for example: 201502
  8. yyyy, for example: 2015

@param node a fixture value for testing that replaces node and clock bits

@param node a fixture value for testing that replaces node bits @param clock a fixture value for testing that replaces clock bits

@param baseSpec - a string specification for the base time value

@param baseSpec - a string specification for the base time value @param node a fixture value for testing that replaces node and clock bits

@param baseSpec - a string specification for the base time value @param node a fixture value for testing that replaces node bits @param clock a fixture value for testing that replaces clock bits

ToFinestTimeUUID

Converts a count of 100ns intervals from 1582 Julian to a Type1 TimeUUID according to RFC 4122. This allows you to access the finest unit of resolution for the purposes of simulating a large set of unique timeuuid values. This offers 10000 times more unique values per ms than {@link ToEpochTimeUUID}. For the variants that have a String argument in the constructor, this is a parsable datetime that is used as the base time for all produced values. Setting this allows you to set the start of the time range for all timeuuid values produced. All times are parsed for UTC. All time use ISO date ordering, meaning that the most significant fields always go before the others. The valid formats, in joda specifier form are:

  1. yyyy-MM-dd HH:mm:ss.SSSZ, for example: 2015-02-28 23:30:15.223
  2. yyyy-MM-dd HH:mm:ss, for example 2015-02-28 23:30:15
  3. yyyyMMdd'T'HHmmss.SSSZ, for example: 20150228T233015.223
  4. yyyyMMdd'T'HHmmssZ, for example: 20150228T233015
  5. yyyy-MM-dd, for example: 2015-02-28
  6. yyyyMMdd, for example: 20150228
  7. yyyyMM, for example: 201502
  8. yyyy, for example: 2015

@param node a fixture value for testing that replaces node and clock bits

@param node a fixture value for testing that replaces node bits @param clock a fixture value for testing that replaces clock bits

@param baseTimeSpec - a string specification for the base time value

@param baseTimeSpec - a string specification for the base time value @param node a fixture value for testing that replaces node and clock bits

@param node a fixture value for testing that replaces node bits @param clock a fixture value for testing that replaces clock bits @param baseTimeSpec - a string specification for the base time value

ToJavaInstant

Convert the input epoch millisecond to a {@code Java Instant}, by multiplying and then dividing by the provided parameters. This is in contrast to the ToJodaInstant function which does the same thing using the Joda API Type.

ToJodaDateTime

Convert the input value to a {@code org.joda.time.DateTime}

ToJodaInstant

Convert the input epoch millisecond to a {@code JodaTime Instant}, by multiplying and then dividing by the provided parameters. This is in contrast to the ToJavaInstant function which does the same thing, only using the Java API type.

ToLocalTime

Convert the input epoch millisecond to a {@code Java Instant}, by multiplying and then dividing by the provided parameters, then convert the result to a java {@link LocalTime}.

ToMillisAtStartOfDay

Return the epoch milliseconds at the start of the day for the given epoch milliseconds.

ToMillisAtStartOfHour

Return the epoch milliseconds at the start of the hour for the given epoch milliseconds.

ToMillisAtStartOfMinute

Return the epoch milliseconds at the start of the minute for the given epoch milliseconds.

ToMillisAtStartOfMonth

Return the epoch milliseconds at the start of the month for the given epoch milliseconds.

ToMillisAtStartOfNamedWeekDay

Return the epoch milliseconds at the start of the most recent day that falls on the given weekday for the given epoch milliseconds, including the current day if valid.

ToMillisAtStartOfNextDay

Return the epoch milliseconds at the start of the day after the day for the given epoch milliseconds.

ToMillisAtStartOfNextNamedWeekDay

Return the epoch milliseconds at the start of the next day that falls on the given weekday for the given epoch milliseconds, not including the current day.

ToMillisAtStartOfSecond

Return the epoch milliseconds at the start of the second for the given epoch milliseconds.

ToMillisAtStartOfYear

Return the epoch milliseconds at the start of the year for the given epoch milliseconds.

ToTimeUUIDMax

Converts a long timestamp in epoch millis form into a Version 1 TimeUUID according to RFC 4122. This form uses {@link Uuids#endOf(long)} (long)}

ToTimeUUIDMin

Converts a long timestamp in epoch millis form into a Version 1 TimeUUID according to RFC 4122. This form uses {@link Uuids#startOf(long)}

ToUUID

Convert the incoming String value to the equivalent UUID with {@link UUID#fromString(String)}

Back to top