This site has been deprecated. Do not edit pages here. Please visit the new Pico Labs documentation.


Skip to end of metadata
Go to start of metadata

The time library provides functions for determining the time and manipulating time values. KRE tries to determine the user's location and creates a time object that is localized for the user (i.e., in the user's time zone). The following functions are available:

  • time:now() – returns the current date and time based upon the user's location data.
  • time:new() – returns a new RFC 3339 datetime string from a string formatted as described in ISO8601 (v2000).
  • time:add() – adds (or subtracts) a specific number of time units to a source string.

  • time:strftime() – returns a datetime string in a specified format following POSIX strftime conventions.
  • time:atom() – converts a datetime string to an ATOM compatible form.
  • time:compare() – takes two datetime strings (ISO8601) and returns 1, 0, or -1, depending on whether the first is before, the same, or after the second.

time:now()

time:now() - returns the current date based upon the user's location data

time:new()

time:new() - returns a new RFC 3339 datetime string from a string formatted as described in ISO8601 (v2000).

Valid formats for the datetime source string can be found in ISO8601 (v2000).

time:add()

time:add() - adds (or subtracts) a specific number of time units to a source string.

time:strftime()

time:strftime() - returns a datetime string in a specified format following POSIX strftime conventions.

Valid format arguments to strftime follow the POSIX strftime conventions.

time:strftime() takes an optional third argument that is used to specify the timezone of the resulting formatted string. This can be used, among other things, to simply convert the timezone by returning an ISO formatted datetime string. For example, the following function uses time:strftime() to convert an incoming datetime string to UTC:

time:atom()

time:atom() - converts a datetime string to an ATOM compatible form.

Time Predicates

These predicates depend on knowing timezone context for the event or query that causes them to run. The timezone context can be specified via a reserved event attribute, _timezone. If _timezone is not specified for an event UTC is used. 

All times are 24-hour clock. 

All predicates must be preceded by the modules name, for example:

time:weekend()

timezone

timezone(<arg>) - takes a timezone abbreviation as the argument and checks the user's geo-location (based on IP address) and returns true or false

morning

time:morning() - returns true if it is between 0600 and 1200 hours, otherwise returns false.

afternoon

time:afternoon() - returns true if it is between 1200 and 1700 hours, otherwise returns false.

evening

time:evening() - returns true if it is bewteen 1700 and 2000 hours, otherwise returns false.

night

time:night() - returns true if it is between 2000 and 2400 hours, otherwise returns false.

lunch_time

time:lunch_time() - returns true if it is between 1130 and 1300 hours, otherwise returns false.

late_morning

time:late_morning - returns true if it is between 1000 and 1200 hours, otherwise returns false.

early_afternoon

time:early_afternoon - returns true if it is between 1200 and 1500 hours, otherwise returns false.

late_afternoon

time:late_afternoon - returns true if it is between 1500 and 1700 hours, otherwise returns false.

time_between

time:time_between(<start hour>, <start minute>, <end hour>, <end minute>) - returns true if local time is between the time specified, otherwise returns false.

date_between

time:date_between(<start month>, <start day>, <start year>, <end month>, <end day>, <end year>) - returns true if the local time is between the specified dates (midnight), otherwise returns false.

date_start

time:date_start(<start month>, <start day>, <start year>) - returns true if the local time is on (or after) the specified date, otherwise returns false.

day_of_week

time:day_of_week(<day name>) - returns true if the current day of the week matches the name (capitalized) given as an argument, otherwise returns false.

today_is

time:today_is(<sun>, <mon>,<tue>, <wed>, <thur>, <fri>, <sat>) - returns true if it is the current day of the week, otherwise returns false. Note: Each argument must be either a 1 or 0 to indiate whether to check if today is the day of the week.

weekday

time:weekday() - returns true if today is a weekday, otherwise returns false.

weekend

time:weekend() - returns true if today is the weekend, otherwise returns false.

Labels: