Skip to content

Commit 4891a32

Browse files
GettyOrawonchevobbe
authored andcommitted
Display Date object using toString instead of toISOString (firefox-devtools#8125)
* change isoString date to localeString * Make date format use toString() instead * change test timezone to EA time * fix linting suggestions * Fix code formating * fix failing lint * throw if date is invalid * modify tests for invalid date * fix lint issues * run yarn lint to check failing lints * add comment * Update date-time.js
1 parent 973a45d commit 4891a32

File tree

4 files changed

+11
-7
lines changed

4 files changed

+11
-7
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"mochir": "yarn mochi -- --repeat 10 --",
3030
"mochih": "yarn mochi -- --headless --",
3131
"mochici": "mochii --mc ./firefox --ci --default-test-path devtools/client/debugger/new --headless --",
32-
"test": "jest",
32+
"test": "TZ=Africa/Nairobi jest",
3333
"test:watch": "jest --watch",
3434
"test:coverage": "yarn test --coverage",
3535
"test:all": "yarn test; yarn lint; yarn flow",

packages/devtools-reps/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"firefox": "./node_modules/.bin/start-firefox --start --location https://firefox-devtools.github.io/debugger-examples/",
1010
"chrome": "./node_modules/.bin/start-chrome",
1111
"license-check": "devtools-license-check",
12-
"test": "jest --projects jest.config.js"
12+
"test": "TZ=Africa/Nairobi jest --projects jest.config.js"
1313
},
1414
"author": "",
1515
"license": "MPL-2.0",

packages/devtools-reps/src/reps/date-time.js

+6-4
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,18 @@ function DateTime(props) {
2222
const grip = props.object;
2323
let date;
2424
try {
25+
const dateObject = new Date(grip.preview.timestamp);
26+
// Calling `toISOString` will throw if the date is invalid,
27+
// so we can render an `Invalid Date` element.
28+
dateObject.toISOString();
29+
2530
date = span(
2631
{
2732
"data-link-actor-id": grip.actor,
2833
className: "objectBox"
2934
},
3035
getTitle(grip),
31-
span(
32-
{ className: "Date" },
33-
new Date(grip.preview.timestamp).toISOString()
34-
)
36+
span({ className: "Date" }, dateObject.toString())
3537
);
3638
} catch (e) {
3739
date = span({ className: "objectBox" }, "Invalid Date");

packages/devtools-reps/src/reps/tests/date-time.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ describe("test DateTime", () => {
2626
})
2727
);
2828

29-
expect(renderedComponent.text()).toEqual("Date 2016-03-30T21:17:24.859Z");
29+
expect(renderedComponent.text()).toEqual(
30+
"Date Thu Mar 31 2016 00:17:24 GMT+0300 (East Africa Time)"
31+
);
3032
expectActorAttribute(renderedComponent, stub.actor);
3133
});
3234
});

0 commit comments

Comments
 (0)