smarttime/ts/smarttime.classes.date.ts

31 lines
999 B
TypeScript
Raw Normal View History

2018-06-10 12:00:18 +00:00
import * as plugins from './smarttime.plugins';
2018-10-21 10:12:44 +00:00
export type TAvailableZone = 'Europe/Berlin';
export class ExtendedDate extends Date {
public static fromEuropeanDate(europeanDate: string) {
const dateArray = /(.*)\.(.*)\.(.*)/.exec(europeanDate);
const luxonDate = plugins.luxon.DateTime.utc(
parseFloat(dateArray[3]), // year
parseFloat(dateArray[2]), // month
parseFloat(dateArray[1]) // day
);
const unixMilli = luxonDate.toMillis();
return new ExtendedDate(unixMilli);
}
2018-10-21 10:12:44 +00:00
/** */
public static fromEuropeanDateAndTime(europeanDateArg: string, timeArg: string, zoneArg: TAvailableZone) {
const dateArray = /(.*)\.(.*)\.(.*)/.exec(europeanDateArg);
const luxonDate = plugins.luxon.DateTime.fromISO(`${dateArray[3]}-${dateArray[2]}-${dateArray[1]}T${timeArg}`, {
zone: zoneArg
});
const unixMilli = luxonDate.toMillis();
return new ExtendedDate(unixMilli);
}
constructor(unixMilli: number) {
super(unixMilli);
}
}