You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
26 lines
878 B
TypeScript
26 lines
878 B
TypeScript
import { toIsoSqlUTC, ymdUTC, ymdInTZ as sharedYmdInTZ } from '../../src/utils/datetime';
|
|
|
|
export function toIsoSql(d: Date = new Date()): string {
|
|
return toIsoSqlUTC(d);
|
|
}
|
|
|
|
export { toIsoSqlUTC, ymdUTC };
|
|
|
|
/** Wraps shared ymdInTZ with a default timezone for tests. */
|
|
export function ymdInTZ(d: Date, tz: string = 'Europe/Madrid'): string {
|
|
return sharedYmdInTZ(d, tz);
|
|
}
|
|
|
|
export function addDaysToYMD(ymd: string, days: number, tz: string = 'Europe/Madrid'): string {
|
|
const [Y, M, D] = ymd.split('-').map(n => parseInt(n, 10));
|
|
const base = new Date(Date.UTC(Y, (M || 1) - 1, D || 1));
|
|
base.setUTCDate(base.getUTCDate() + days);
|
|
return ymdInTZ(base, tz);
|
|
}
|
|
|
|
export function addDays(date: Date, days: number): Date {
|
|
const d = new Date(Date.UTC(date.getUTCFullYear(), date.getUTCMonth(), date.getUTCDate()));
|
|
d.setUTCDate(d.getUTCDate() + days);
|
|
return d;
|
|
}
|