Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getDateObject no longer ignores "GMT" in datetime string #379

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,32 +9,27 @@ export default {
...DateFormatter
};

function getDateObject(text): Date {
function getDateObject(text: string): Date {
// TODO - cleanup formatters util functions as DX APIs are returning values per ISO std now.
const timeStamp = text.replace(/-/g, '');
const isDateTime = timeStamp.indexOf('GMT') !== -1;
const year = parseInt(timeStamp.substr(0, 4), 10);
const month = parseInt(timeStamp.substr(4, 2), 10) - 1;
const day = parseInt(timeStamp.substr(6, 2), 10);

const date = new Date();

date.setDate(day);
date.setMonth(month);
date.setFullYear(year);

if (isDateTime) {
const hours = parseInt(timeStamp.substr(9, 2), 10);
const minutes = parseInt(timeStamp.substr(11, 2), 10);
const seconds = parseInt(timeStamp.substr(13, 2), 10);
const ms = parseInt(timeStamp.substr(16, 3), 10);
date.setHours(hours);
date.setMinutes(minutes);
date.setSeconds(seconds);
date.setMilliseconds(ms);
const year = timeStamp.substr(0, 4);
const month = timeStamp.substr(4, 2);
const day = timeStamp.substr(6, 2);

if (timeStamp.includes('GMT')) {
const hours = timeStamp.substr(9, 2);
const minutes = timeStamp.substr(11, 2);
const seconds = timeStamp.substr(13, 2);
const ms = timeStamp.substr(16, 3);

return new Date(`${year}-${month}-${day}T${hours}:${minutes}:${seconds}.${ms}Z`);
}

return date;
return new Date(
parseInt(year, 10),
parseInt(month, 10) - 1,
parseInt(day, 10),
);
}

function isIsoDate(str) {
Expand Down
Loading