UNPKG

zol-datetime

Version:

SQL Date/Time functionality for Zol

199 lines (160 loc) 6.3 kB
import { Col } from "zol"; import { Duration, Instant, LocalDate, LocalDateTime, LocalTime, Period } from "js-joda"; export declare function instantCol<s>(val: Instant): Col<s, Instant>; export declare function instantParser(val: string): Instant; export declare function localDateTimeCol<s>(val: LocalDateTime): Col<s, LocalDateTime>; export declare function localDateTimeParser(val: string): LocalDateTime; export declare function localDateCol<s>(val: LocalDate): Col<s, LocalDate>; export declare function localDateParser(val: string): LocalDate; export declare function localTimeCol<s>(val: LocalTime): Col<s, LocalTime>; export declare function localTimeParser(val: string): LocalTime; export declare function durationCol<s>(val: Duration): Col<s, Duration>; /** * This should be used with great care, or ideally avoided */ export declare function durationParser(interval: string): Duration; export declare function periodCol<s>(val: Period): Col<s, Period>; /** * Warning: This is lossy. Only use if you really know what you doing */ export declare function periodParser(interval: string): Period; /** * When instant occurred, what time did the clocks on the wall located in timezone show? * (Or what do we predict them to show, if instant is in the future?) * * SQL equivilent: `TIMEZONE` */ export declare function instantToLocalDateTime<s>(instant: Col<s, Instant>, timezone: Col<s, string>): Col<s, LocalDateTime>; /** * When the clocks in timezone showed the given time, what was the instant? * (Or what do we predict it to be, if the clocks haven't yet showed this time) * * Note: If due to daylight savings time, the clocks in timezone showed the given * time on two seperate instances, then PostgreSQL sill arbitrarily pick one. * Similarly, if the clocks in timezone never showed the given time, then PostgreSQL * will pick an appropriately close instant. * * SQL equivilent: `TIMEZONE` */ export declare function localDateTimeToInstant<s>(localDateTime: Col<s, LocalDateTime>, timezone: Col<s, string>): Col<s, Instant>; /** * The duration between two Instants. * * SQL equivilent: `-` */ export declare function durationBetween<s>(startInclusive: Col<s, Instant>, endExclusive: Col<s, Instant>): Col<s, Duration>; /** * SQL equivilent: `-` */ export declare function durationMinus<s>(lhs: Col<s, Duration>, rhs: Col<s, Duration>): Col<s, Duration>; /** * SQL equivilent: `*` */ export declare function durationMultiply<s>(lhs: Col<s, Duration>, rhs: Col<s, number>): Col<s, Duration>; /** * SQL equivilent: `/` */ export declare function durationDivide<s>(lhs: Col<s, Duration>, rhs: Col<s, number>): Col<s, Duration>; /** * SQL equivilent: `+` */ export declare function durationPlus<s>(lhs: Col<s, Duration>, rhs: Col<s, Duration>): Col<s, Duration>; /** * Add a Duration to an Instant * * SQL equivilent: `+` */ export declare function instantAdd<s>(instant: Col<s, Instant>, duration: Col<s, Duration>): Col<s, Instant>; /** * Subtract a Duration from an Instant * * SQL equivilent: `-` */ export declare function instantSubtract<s>(instant: Col<s, Instant>, duration: Col<s, Duration>): Col<s, Instant>; /** * Add a Duration to a LocalDateTime * * SQL equivilent: `+` */ export declare function localDateTimeAdd<s>(localDateTime: Col<s, LocalDateTime>, duration: Col<s, Duration>): Col<s, LocalDateTime>; /** * Add a Period to a LocalDateTime. * * SQL equivilent: `+` */ export declare function localDateTimeAdd<s>(localDateTime: Col<s, LocalDateTime>, period: Col<s, Period>): Col<s, LocalDateTime>; /** * Subtract a Duration from a LocalDateTime * * SQL equivilent: `-` */ export declare function localDateTimeSubtract<s>(localDateTime: Col<s, LocalDateTime>, duration: Col<s, Duration>): Col<s, LocalDateTime>; /** * Subtract a Period from a LocalDateTime * * SQL equivilent: `-` */ export declare function localDateTimeSubtract<s>(localDateTime: Col<s, LocalDateTime>, period: Col<s, Period>): Col<s, LocalDateTime>; /** * Convert a LocalDateTime to a LocalDate (discarding the time portion) * * SQL equivilent: `CAST` */ export declare function truncateToLocalDate<s>(localDateTime: Col<s, LocalDateTime>): Col<s, LocalDate>; /** * Convert a LocalDate to a LocalDateTime. The time will be set to "00:00:00" * * SQL equivilent: `CAST` */ export declare function expandTolocalDateTime<s>(localDate: Col<s, LocalDate>): Col<s, LocalDateTime>; /** * Add a Period to a LocalDate * * SQL equivilent: `+` */ export declare function localDateAdd<s>(localDate: Col<s, LocalDate>, period: Col<s, Period>): Col<s, LocalDate>; /** * Subtract a Period from a LocalDate * * SQL equivilent: `-` */ export declare function localDateSubtract<s>(localDate: Col<s, LocalDate>, period: Col<s, Period>): Col<s, LocalDate>; /** * Add n days to a LocalDate. * * This is similar to [[localDateAdd]], but can be more convenient when the * days you want to add is from some other column, or is a computed value. * * SQL equivilent: `+` (INTEGER) */ export declare function localDateAddDays<s>(localDate: Col<s, LocalDate>, days: Col<s, number>): Col<s, LocalDate>; /** * Subtract n days from a LocalDate. * * This is similar to [[localDateSubtract]], but can be more convenient when * the days you want to subtract is from some other column, or is a computed * value. * * SQL equivilent: `-` (INTEGER) */ export declare function localDateSubtractDays<s>(localDate: Col<s, LocalDate>, days: Col<s, number>): Col<s, LocalDate>; /** * Add a Duration to a LocalTime. If the LocalTime overflows (goes past * midnight) then the result will wrap around. * * SQL equivilent: `+` */ export declare function localTimeAdd<s>(localTime: Col<s, LocalTime>, duration: Col<s, Duration>): Col<s, LocalTime>; /** * Subtract a Duration from a LocalTime. If the LocalTime overflows (goes * before midnight) then the result will wrap around. * * SQL equivilent: `-` */ export declare function localTimeSubtract<s>(localTime: Col<s, LocalTime>, duration: Col<s, Duration>): Col<s, LocalTime>; /** * The Period between two LocalDates. * * SQL equivilent: `age` */ export declare function periodBetween<s>(startDate: Col<s, LocalDate>, endDate: Col<s, LocalDate>): Col<s, Period>;