UNPKG

delphirtl

Version:
184 lines (183 loc) 6.67 kB
import { ethers } from "ethers"; declare global { interface Date { ToBlockchainTimestamp(): number; /** * Adds the given number of seconds to a new instance of Date, with the starting value from this instance * * @param {number} seconds The number of seconds to add * @returns {Date} */ addSeconds(seconds: number): Date; /** * Adds the given number of minutes to a new instance of Date, with the starting value from this instance * @param minutes The number of minutes to add * @returns {Date} */ addMinutes(minutes: number): Date; /** * Adds the given number of hours to a new instance of Date, with the starting value from this instance * @param hours The number of hours to add * @returns {Date} */ addHours(hours: number): Date; /** * * Adds the given number of days to a new instance of Date, with the starting value from this instance * @param days The number of days to add * @returns {Date} */ addDays(days: number): Date; /** * * Adds the given number of weeks to a new instance of Date, with the starting value from this instance * @param weeks The number of weeks to add * @returns {Date} */ addWeeks(weeks: number): Date; /** * * Adds the given number of months (30 days) to a new instance of Date, with the starting value from this instance * @param months The number of months (30 days) to add * @returns {Date} */ addMonths(months: number): Date; /** * * Adds the given number of years (365 days) to a new instance of Date, with the starting value from this instance * @param years The number of years (365 days per year) to add * @returns {Date} */ addYears(years: number): Date; /** * Checks if this date instance is a valid date * * @returns {boolean} */ isValidDate(): boolean; /** * Formats this date instance into the given format and returns it\ 'YYYY': Full year (e.g., 2024)\ 'YY': Last two digits of year (e.g., 24)\ 'MMMM': January to December\ 'MMM': Jan to Dec\ 'MM': Month with leading zero (e.g., 01 - 12)\ 'M': Month without leading zero (e.g., 1 - 12)\ 'DD': Day with leading zero (e.g., 01 - 31)\ 'D': Day without leading zero (e.g., 1 - 31)\ 'HH': Hour in 24-hour format with leading zero (e.g., 00 - 23)\ 'H': Hour in 24-hour format without leading zero (e.g., 0 - 23)\ 'hh': Hour in 12-hour format with leading zero (e.g., 01 - 12)\ 'h': Hour in 12-hour format without leading zero (e.g., 1 - 12)\ 'nn': Minute with leading zero (e.g., 00 - 59)\ 'n': Minute without leading zero (e.g., 0 - 59)\ 'ss': Second with leading zero (e.g., 00 - 59)\ 's': Second without leading zero (e.g., 0 - 59)\ * * @param {string} format * @returns {string} */ toFormat(format: string): string; } } /** * Converts the given time into Javascript Date * @param time * @returns */ declare function fromBlockchainTimestamp(time: number): Date; /** * @param {Date} date * @param {number} years * @returns Date */ declare function JSDateAddYears(date: Date, years: number): Date; declare function JSDateAddMonths(date: Date, months: number): Date; declare function JSDateAddWeeks(date: Date, weeks: number): Date; /** * @param {Date} time * @param {number} days * @returns Date */ declare function JSDateAddDays(time: Date, days: number): Date; /** * @param {Date} time * @param {number} hours * @returns Date */ declare function JSDateAddHours(time: Date, hours: number): Date; /** * @param {Date} time * @param {number} mins * @returns Date */ declare function JSDateAddMins(time: Date, mins: number): Date; declare function JSDateAddSecs(time: Date, secs: number): Date; /** * @param {number|Date} time * @returns number */ declare function JSDateToBlockchainTimestamp(time: number | Date): number; /** * @param {number} time * @returns number */ declare function JSTimeToUTC(time: number): number; declare function getEstimatedBlockNumberForDuration(Block1: ethers.providers.Block, Block2: ethers.providers.Block, timestampInMS: number): number; /** * The difference / duration between 2 dates */ export interface TDiffDuration { /** * 365 days in a year */ years: number; /** * 30 days in a month */ months: number; days: number; hours: number; minutes: number; seconds: number; } /** * Calculates the difference between 2 dates * @param d1 * @param d2 * @returns */ declare function DiffDuration(d1: Date, d2: Date): TDiffDuration; /** * Checks if a date is valid * * @param {Date} date * @returns {boolean} */ declare function isValidDate(date: Date): boolean; /** * Returns a string for the date in the given format\ 'YYYY': Full year (e.g., 2024)\ 'YY': Last two digits of year (e.g., 24)\ 'MMMM': January to December\ 'MMM': Jan to Dec\ 'MM': Month with leading zero (e.g., 01 - 12)\ 'M': Month without leading zero (e.g., 1 - 12)\ 'DD': Day with leading zero (e.g., 01 - 31)\ 'D': Day without leading zero (e.g., 1 - 31)\ 'HH': Hour in 24-hour format with leading zero (e.g., 00 - 23)\ 'H': Hour in 24-hour format without leading zero (e.g., 0 - 23)\ 'hh': Hour in 12-hour format with leading zero (e.g., 01 - 12)\ 'h': Hour in 12-hour format without leading zero (e.g., 1 - 12)\ 'nn': Minute with leading zero (e.g., 00 - 59)\ 'n': Minute without leading zero (e.g., 0 - 59)\ 'ss': Second with leading zero (e.g., 00 - 59)\ 's': Second without leading zero (e.g., 0 - 59)\ * * * @param {Date} d date instance * @param {string} format string format * @returns {string} */ declare function toFormat(format: string, d: Date): string; export { fromBlockchainTimestamp, getEstimatedBlockNumberForDuration, JSDateAddYears, JSDateAddMonths, JSDateAddWeeks, JSDateAddDays, JSDateAddHours, JSDateAddMins, JSDateAddSecs, JSTimeToUTC, JSDateToBlockchainTimestamp, DiffDuration, isValidDate, toFormat, toFormat as FormatDateTime };