Skip to content

Commit

Permalink
fix(dateformatting): addressed code review comment
Browse files Browse the repository at this point in the history
  • Loading branch information
Reuben Evans committed Oct 1, 2020
1 parent 73a305d commit 236d716
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions src/js/common/browserInfoHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,12 @@ const validateAndGetScreenDetail = (value) => {
};

const getFormattedOffset = () => {
const nowUTC = new Date().toString();
// nowUTC is in format like "Wed Sep 30 2020 23:11:02 GMT+0100 (British Summer Time)"
// To format the offset, we pick the relevant characters based on their position
// and reformat with a ":"
const signCharIndex = 28;
const hourOffset = `${nowUTC.charAt(signCharIndex)}${nowUTC.charAt(29)}${nowUTC.charAt(30)}`;
const minuteOffset = `${nowUTC.charAt(31)}${nowUTC.charAt(32)}`;
// Date().toString() is in format like "Wed Sep 30 2020 23:11:02 GMT+0100 (British Summer Time)"
// To format the offset, we split on "GMT"
// and then pick the relevant characters based on their position and reformat with a ":"
const offset = new Date().toString().split("GMT")[1];
const hourOffset = `${offset[0]}${offset[1]}${offset[2]}`;
const minuteOffset = `${offset[3]}${offset[4]}`;
const formattedUTC = `${hourOffset}:${minuteOffset}`;
return formattedUTC;
}
Expand Down

0 comments on commit 236d716

Please sign in to comment.