Skip to content

Commit

Permalink
use Intl.DateTimeFormat
Browse files Browse the repository at this point in the history
  • Loading branch information
mbostock committed Mar 30, 2021
1 parent acbb45b commit fa65611
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/format.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
export function formatMonth(locale, month = "short") {
const format = {timeZone: "UTC", month};
const format = new Intl.DateTimeFormat(locale, {timeZone: "UTC", month});
return i => {
if (i != null && !isNaN(i = new Date(Date.UTC(2000, +i)))) {
return i.toLocaleString(locale, format);
return format.format(i);
}
};
}

export function formatWeekday(locale, weekday = "short") {
const format = {timeZone: "UTC", weekday};
const format = new Intl.DateTimeFormat(locale, {timeZone: "UTC", weekday});
return i => {
if (i != null && !isNaN(i = new Date(Date.UTC(2001, 0, +i)))) {
return i.toLocaleString(locale, format);
return format.format(i);
}
};
}

0 comments on commit fa65611

Please sign in to comment.