Skip to content

Commit

Permalink
Use locale formatting for all tooltip types (including dates)
Browse files Browse the repository at this point in the history
The `{style: "decimal"}` option is ignored for non-float types.
This gives us a more locale suitable formatting of the date.
The test uses the same function to format the date so that it matches.
  • Loading branch information
andy-lee-eng committed Apr 4, 2019
1 parent 8e125b3 commit 7fabfb1
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ function addDataValues(tooltipDiv, values) {
});
}

const formatNumber = value => (typeof value === "number" ? value.toLocaleString(undefined, {style: "decimal"}) : value);
const formatNumber = value => value.toLocaleString(undefined, {style: "decimal"});
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,12 @@ describe("tooltip should", () => {

test("format mainValue as date", () => {
settings.mainValues[0].type = "datetime";
const testDate = new Date("2019-04-03T15:15Z");
const data = {
mainValue: new Date("2019-04-03T15:15Z").getTime()
mainValue: testDate.getTime()
};
generateHtml(tooltip, data, settings);
expect(getContent()).toEqual(["main-1: Wed Apr 03 2019 16:15:00 GMT+0100 (GMT Summer Time)"]);
expect(getContent()).toEqual([`main-1: ${testDate.toLocaleString()}`]);
});

test("format mainValue as integer", () => {
Expand Down

0 comments on commit 7fabfb1

Please sign in to comment.