date.ts 625 B

12345678910111213141516171819202122232425
  1. import { format, parse, differenceInCalendarDays, addDays } from 'date-fns';
  2. const ISO_FORMAT = 'yyyy-MM-dd';
  3. function formatIso(date: Date): string {
  4. return format(date, ISO_FORMAT)
  5. }
  6. function today(): Date {
  7. return new Date()
  8. }
  9. function todayIso(): string {
  10. return formatIso(today())
  11. }
  12. function formatIsoDate(date: string, fmt: string): string {
  13. return format(parse(date, ISO_FORMAT, new Date()), fmt);
  14. }
  15. function reformatDate(date: string, fromFormat: string, toFormat: string): string {
  16. return format(parse(date, fromFormat, new Date()), toFormat);
  17. }
  18. export { today, formatIso, todayIso, formatIsoDate }