Skip to content

Commit

Permalink
feat: loosen date argument types
Browse files Browse the repository at this point in the history
  • Loading branch information
spawnia committed Oct 18, 2021
1 parent 424d2c0 commit bc0dd4c
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions src/date.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { differenceInCalendarDays, format, isValid, parse } from 'date-fns';
import de from 'date-fns/locale/de';

export function isToday(date: Date | number) {
export function isToday(date: Date | string | number) {
return differenceInCalendarDays(new Date(), date) === 0;
}

Expand All @@ -19,54 +19,54 @@ export const GERMAN_DATE_FORMAT: string = 'dd.MM.y';
export function parseGermanDate(value: string): Date | null {
return parseDate(value, GERMAN_DATE_FORMAT);
}
export function formatGerman(date: Date): string {
export function formatGerman(date: Date | string | number): string {
return format(date, GERMAN_DATE_FORMAT, { locale: de });
}

export const ISO_DATE_FORMAT: string = 'y-MM-dd';
export function parseIsoDate(value: string): Date | null {
return parseDate(value, ISO_DATE_FORMAT);
}
export function formatIsoDate(date: number | Date): string {
export function formatIsoDate(date: Date | string | number): string {
return format(date, ISO_DATE_FORMAT, { locale: de });
}

export const GERMAN_DOTLESS_DATE_FORMAT: string = 'ddMMy';
export function parseGermanDotlessDate(value: string): Date | null {
return parseDate(value, GERMAN_DOTLESS_DATE_FORMAT);
}
export function formatGermanDotlessDate(date: Date): string {
export function formatGermanDotlessDate(date: Date | string | number): string {
return format(date, GERMAN_DOTLESS_DATE_FORMAT, { locale: de });
}

export const SECONDLESS_DATE_TIME_FORMAT: string = 'y-MM-dd HH:mm';
export function parseSecondlessDateTime(value: string): Date | null {
return parseDate(value, SECONDLESS_DATE_TIME_FORMAT);
}
export function formatSecondlessDateTime(dateTime: number | Date): string {
return format(dateTime, SECONDLESS_DATE_TIME_FORMAT, { locale: de });
export function formatSecondlessDateTime(date: Date | string | number): string {
return format(date, SECONDLESS_DATE_TIME_FORMAT, { locale: de });
}

export const GERMAN_DATE_TIME_FORMAT: string = 'dd.MM.y HH:mm';
export function parseGermanDateTime(value: string): Date | null {
return parseDate(value, GERMAN_DATE_TIME_FORMAT);
}
export function formatGermanDateTime(date: Date): string {
export function formatGermanDateTime(date: Date | string | number): string {
return format(date, GERMAN_DATE_TIME_FORMAT, { locale: de });
}

export const ISO_DATE_TIME_FORMAT: string = 'y-MM-dd HH:mm:ss';
export function parseIsoDateTime(value: string): Date | null {
return parseDate(value, ISO_DATE_TIME_FORMAT);
}
export function formatIsoDateTime(dateTime: number | Date): string {
return format(dateTime, ISO_DATE_TIME_FORMAT, { locale: de });
export function formatIsoDateTime(date: Date | string | number): string {
return format(date, ISO_DATE_TIME_FORMAT, { locale: de });
}

export const DOTLESS_DATE_FORMAT: string = 'yMMdd';
export function parseDotlessDate(value: string): Date | null {
return parseDate(value, DOTLESS_DATE_FORMAT);
}
export function formatDotlessDate(dateTime: number | Date): string {
return format(dateTime, DOTLESS_DATE_FORMAT, { locale: de });
export function formatDotlessDate(date: Date | string | number): string {
return format(date, DOTLESS_DATE_FORMAT, { locale: de });
}

0 comments on commit bc0dd4c

Please sign in to comment.