UNPKG

jsm-utilities

Version:
55 lines (54 loc) 2.69 kB
/** * @since 17-10-2023 12:39:25 * @description This function takes a time range string (e.g. "5 minutes") and returns a start date and end date for that time range * - The time range must be specified with a number followed by a unit of time (e.g. "5 minutes", "3 hours", "1 day") * - Valid units of time are "second", "minute", "hour", "day", "week", "month", and "year" * - Valid units of time can be abbreviated to "s", "m", "h", "d", "w", "M", and "y" * - If no unit of time is specified, the default unit is "day" * - If the unit of time is plural (e.g. "days"), it must be pluralized using an "s" * - If the unit of time is abbreviated, it must be followed by an "s" * - The time range string must be in the format "[number] [unit of time]s?" * - For example, "5 minutes" is valid, but "5 minute" is not valid, and "5 m" is not valid either * - If the unit of time is plural (e.g. "days"), it must be pluralized using an "s" * - This function return {false} if the time range string is not in the correct format * @param {string} timeRange */ export declare function transformTimeRangeToDates(timeRange: string, currentDate?: Date, rangeIn?: 'past' | 'future'): false | { start: Date; end: Date; }; export declare const isDateWithinLastNSeconds: (date: Date, seconds: number) => boolean; export declare const isDateWithinLastNMinutes: (date: Date, minutes: number) => boolean; export declare const isDateWithinLastNHours: (date: Date, hours: number) => boolean; export declare const isDateWithinLastNDays: (date: Date, days: number) => boolean; export declare const isDateWithinLastNWeeks: (date: Date, weeks: number) => boolean; export declare const isDateWithinLastNMonths: (date: Date, months: number) => boolean; export declare const isDateWithinLastNYears: (date: Date, years: number) => boolean; export declare const isDateWithinLastNTimeRange: (date: Date, timeRange: string) => boolean; /** * @generator Jsm * @author dr. Salmi <reevosolutions@gmail.com> * @since 26 July 2000 * @since 29-04-2024 23:01:17 */ export declare const isDateRangObject: (obj: any) => obj is { start: Date; end: Date; }; export declare function calculateTimePeriod(timePeriod: { granularity?: "minute" | "hour" | "day" | "week" | "month" | "quarter" | "year"; timezone?: string; } & ({ start: Date; end: Date; preset: "custom"; } | { preset: "today" | "yesterday" | "last_7_days" | "last_30_days" | "last_90_days" | "last_year"; })): { now: Date; startDate: Date; endDate: Date; granularity: "month" | "year" | "week" | "day" | "hour" | "minute" | "quarter"; timezone: string | undefined; preset: string | undefined; };