Skip to content

sinclairnick/dateformat-ts

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

DateFormat TS

Format date information at the type-level, according to the Unicode #35 standard


// Init date
type Date = FromIso<"2024-06-10T04:39:46.229Z">;

// Format date
type Formatted = Format<Date, "dd-MM-yy H:mm:ss aa">;
//   ^? 10-06-24 4:39:46 AM

This is just a toy project, it's probably not super useful in production

Usage

Given a DateObject

export type DateObject = {
    dayOfMonth: number;
    dayOfYear: number;
    dayOfWeek: number;
    monthOfYear: number;
    hourOfDay: number;
    minuteOfHour: number;
    secondOfMinute: number;
    year: number;
};

We can format the date information given a format string.

type FormattedDate = Format<SomeDateObject, "some-format-string">;

Limitations

  • Not all format parts implemented, like ISO and locale-stuff
  • No input validation is done
  • Escaping syntax is not respected (not implemented yet)
  • FromIso does not produce dayOfYear or dayOfWeek information

About

A type-level implementation of date.format()

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published