Skip to content

Commit

Permalink
Update date.ts
Browse files Browse the repository at this point in the history
use `as const` instead of enum
  • Loading branch information
fengmk2 authored Jan 14, 2025
1 parent 9df3ab4 commit 70010bd
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/date.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,12 +202,14 @@ export function dateToUnixTimestamp(date: Date): number {
return Math.round(date.getTime() / 1000);
}

export enum DateFormat {
DateTimeWithTimeZone,
DateTimeWithMilliSeconds,
DateTimeWithSeconds,
UnixTimestamp
}
// use `as const` instead of enum
// https://www.totaltypescript.com/books/total-typescript-essentials/deriving-types#using-as-const-for-javascript-style-enums
export const DateFormat {
DateTimeWithTimeZone: 'DateTimeWithTimeZone',
DateTimeWithMilliSeconds: 'DateTimeWithMilliSeconds',
DateTimeWithSeconds: 'DateTimeWithSeconds',
UnixTimestamp: 'UnixTimestamp',
} as const;

/**
* Provide milliseconds, return a formatted string.
Expand Down

0 comments on commit 70010bd

Please sign in to comment.