Skip to content

Commit

Permalink
Merge pull request flatpickr#1531 from tmbeihl/master
Browse files Browse the repository at this point in the history
Add support for timestamps expressed in milliseconds
  • Loading branch information
chmln authored Oct 16, 2018
2 parents 5bde31b + 1314d02 commit 144194b
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/utils/formatting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export type token =
| "m"
| "n"
| "s"
| "u"
| "w"
| "y";

Expand Down Expand Up @@ -107,6 +108,7 @@ export const revFormat: RevFormat = {
s: (dateObj: Date, seconds: string) => {
dateObj.setSeconds(parseFloat(seconds));
},
u: (_: Date, unixMillSeconds: string) => new Date(parseFloat(unixMillSeconds)),
w: do_nothing,
y: (dateObj: Date, year: string) => {
dateObj.setFullYear(2000 + parseFloat(year));
Expand Down Expand Up @@ -135,6 +137,7 @@ export const tokenRegex: TokenRegex = {
m: "(\\d\\d|\\d)",
n: "(\\d\\d|\\d)",
s: "(\\d\\d|\\d)",
u: "(.+)",
w: "(\\d\\d|\\d)",
y: "(\\d{2})",
};
Expand Down Expand Up @@ -224,6 +227,9 @@ export const formats: Formats = {

// seconds 0-59
s: (date: Date) => date.getSeconds(),

// Unix Milliseconds
u: (date: Date) => date.getTime(),

// number of the day of the week
w: (date: Date) => date.getDay(),
Expand Down

0 comments on commit 144194b

Please sign in to comment.