Context API reference
The API property of the context object provides number of convenience methods for generating and manipulating values.
List of methods:
API.timestamp(shift: int, unit: str, base: str = Current_Time) -> str - returns a date in relation to now variable based on the shift and unit values. The function moves the returned value away from now by the shift number of specified units. Supported units: days, weeks, months, years. The value of now defaults to current time if not specified. An example of generating a date referring the same day last week: {context.API.timestamp(-1, 'weeks')}.
API.range(begin: str, end: str, unit: str = 'days') -> [str,str...] - returns list of temporal identifiers based on two dates. Supported units: days, weeks, months, years. Unspecified unit defaults to 'days'. The function returns a list of temporal identifiers based on the unit: 'YYYY-MM-DD' for days, 'YYYY-MM' for months, and 'YYYY-00-WW' for weeks. The result can be used with in expression filter in scenarios where more specific definition of filter is desired:
{context.API.range(context.API.timestamp(-30,'days'),context.API.timestamp(), 'days')}. This example generates list of dates between today and the date 30 days ago.
API.asdate(value: str, format: str = 'YYYY-MM-DD') -> str - interprets input value as datetime and returns string representation specified by format. Returns error if the input cannot be coerced to a valid datetime.
API.unixtime(base: str = Current_Time) -> int - return UNIX timestamp seconds. If base value can be coerced to datetime the return value corresponds to that time; default value
API.isoweek(shift: int = 0, unit: str = 'days', base: str = Current_Time) -> str - returns isoweek-formatted string (YYYY-00-WW) using the base, shift, and unit values. Base value default to current time.
API.look(path: str, row: lookable, default: any = None) -> any - returns a value from lookable according to specified JSON path or default value is the path is not found in lookable; lookable can be any data structure which support JSONPath lookup such as map or list.
API.dt(self, datelike, tz: str = None, format: str = None, default=None) -> datetime - returns datetime-like object exposing the following methods and properties:
.shift(days=-1, weeks=-1, months=1, years=1, minutes=-1, seconds=1) - modify the datetime by specified units such as days, weeks, months, years, minutes, or seconds
.replace(year=2022, month=11, day=23) - substitute specific components of a given datetime with new values. Whether it's the year, month, or any other aspect
.format(formatstring) - offers a comprehensive set of formatting tokens for versatile datetime representation. These include options for:
1. year in both 4-digit and 2-digit formats (YYYY and YY),
2. month representations (MMMM, MMM, MM, M),
3. day configurations (DDDD, DDD, DD, D, Do),
4. day of the week indications (dddd, ddd, d),
5. ISO week dates (W),
6. hours in 24-hour and 12-hour formats (HH, H, hh, h),
7. AM/PM indicators (A, a),
8. minutes (mm, m),
9. seconds (ss, s),
10. sub-seconds (S...),
11. timezone information (ZZZ, ZZ, Z)
12. timestamps in both seconds (X) and milliseconds/microseconds (x).
.isoformat() - formats your datetime as YYYY-MM-DD HH:mm:ss, ensuring consistency and compatibility.
.int_timestamp - Retrieve an integer timestamp effortlessly with this property.
.datetime - property grants access to the unadulterated datetime object.