UNPKG

@odoo/o-spreadsheet

Version:
95 lines (94 loc) 4.68 kB
import { CellValue } from "../types/cells"; import { Format } from "../types/format"; import { Locale } from "../types/locale"; /** * All Spreadsheet dates are internally stored as an object with two values: * - value (number), which represent the number of day till 30/12/1899 * - format (string), which keep the information on how the date was defined */ export interface InternalDate { readonly value: number; readonly format: Format; readonly jsDate?: ReadonlyDateTime; } /** * A DateTime object that can be used to manipulate spreadsheet dates. * Conceptually, a spreadsheet date is simply a number with a date format, * and it is timezone-agnostic. * This DateTime object consistently uses UTC time to represent a naive date and time. */ export declare class DateTime { private jsDate; constructor(year: number, month: number, day: number, hours?: number, minutes?: number, seconds?: number); static fromTimestamp(timestamp: number): DateTime; static now(): DateTime; toString(): string; toLocaleDateString(): string; getTime(): number; getFullYear(): number; getMonth(): number; getQuarter(): number; getDate(): number; getDay(): number; getHours(): number; getMinutes(): number; getSeconds(): number; getIsoWeek(): number; setFullYear(year: number): number; setMonth(month: number): number; setDate(date: number): number; setHours(hours: number): number; setMinutes(minutes: number): number; setSeconds(seconds: number): number; } type ReadonlyDateTime = Readonly<Omit<DateTime, "setSeconds" | "setMinutes" | "setHours" | "setDate" | "setMonth" | "setFullYear">>; export declare const INITIAL_1900_DAY: DateTime; export declare const MS_PER_DAY: number; export declare const mdyDateRegexp: RegExp; export declare const ymdDateRegexp: RegExp; export declare const timeRegexp: RegExp; /** Convert a value number representing a date, or return undefined if it isn't possible */ export declare function valueToDateNumber(value: CellValue, locale: Locale): number | undefined; export declare function isDateTime(str: string, locale: Locale): boolean; export declare function parseDateTime(str: string, locale: Locale): InternalDate | null; export declare function numberToJsDate(value: number): DateTime; export declare function jsDateToRoundNumber(date: DateTime): number; export declare function jsDateToNumber(date: DateTime): number; /** Return the number of days in the current month of the given date */ export declare function getDaysInMonth(date: DateTime): number; export declare function isLastDayOfMonth(date: DateTime): boolean; /** * Add a certain number of months to a date. This will adapt the month number, and possibly adapt * the day of the month to keep it in the month. * * For example "31/12/2020" minus one month will be "30/11/2020", and not "31/11/2020" * * @param keepEndOfMonth if true, if the given date was the last day of a month, the returned date will * also always be the last day of a month. */ export declare function addMonthsToDate(date: DateTime, months: number, keepEndOfMonth: boolean): DateTime; export declare function getYearFrac(startDate: number, endDate: number, _dayCountConvention: number): number; /** * Get the number of whole months between two dates. * e.g. * 2002/01/01 -> 2002/02/01 = 1 month, * 2002/01/01 -> 2003/02/01 = 13 months * @param startDate * @param endDate * @returns */ export declare function getTimeDifferenceInWholeMonths(startDate: DateTime, endDate: DateTime): number; export declare function getTimeDifferenceInWholeDays(startDate: DateTime, endDate: DateTime): number; export declare function getTimeDifferenceInWholeYears(startDate: DateTime, endDate: DateTime): number; export declare function areTwoDatesWithinOneYear(startDate: number, endDate: number): boolean; export declare function areDatesSameDay(startDate: number, endDate: number): boolean; export declare function isDateBetween(date: number, startDate: number, endDate: number): boolean; /** Check if the first date is strictly before the second date */ export declare function isDateStrictlyBefore(date: number, dateBefore: number): boolean; /** Check if the first date is before or equal to the second date */ export declare function isDateBefore(date: number, dateBefore: number): boolean; /** Check if the first date is strictly after the second date */ export declare function isDateStrictlyAfter(date: number, dateAfter: number): boolean; /** Check if the first date is after or equal to the second date */ export declare function isDateAfter(date: number, dateAfter: number): boolean; export {};