diff --git a/starsky/starsky/clientapp/src/shared/data.spec.ts b/starsky/starsky/clientapp/src/shared/data.spec.ts index 5de76fb9cb..c7009f7fdd 100644 --- a/starsky/starsky/clientapp/src/shared/data.spec.ts +++ b/starsky/starsky/clientapp/src/shared/data.spec.ts @@ -10,7 +10,7 @@ import { parseTimeHour, SecondsToHours } from "./date"; -import { SupportedLanguages } from "./language"; +import {SupportedLanguages} from "./language"; describe("date", () => { describe("parseDate", () => { @@ -24,6 +24,12 @@ describe("date", () => { // NOT Invalid! expect(result).not.toBe("Invalid Date"); }); + + it("Timezone time", () => { + const result = parseDate("2020-04-28T10:44:43.123456+01:00", SupportedLanguages.nl); + expect(result).not.toBe("Invalid Date"); + }); + it("wrong format", () => { const result = parseDate("2020-30", SupportedLanguages.nl); expect(result).toBe("Invalid Date"); @@ -219,11 +225,11 @@ describe("date", () => { let dayBeforeYesterday = `${dayBeforeYesterdayDate.getFullYear()}- ${leftPad(dayBeforeYesterdayDate.getMonth() + 1)}-${leftPad( - dayBeforeYesterdayDate.getDate() - )}T + dayBeforeYesterdayDate.getDate() + )}T ${leftPad(dayBeforeYesterdayDate.getHours())}:${leftPad( - dayBeforeYesterdayDate.getMinutes() - )}: + dayBeforeYesterdayDate.getMinutes() + )}: ${leftPad(dayBeforeYesterdayDate.getSeconds())}`; // remove space and newlines from prev variable diff --git a/starsky/starsky/clientapp/src/shared/date.ts b/starsky/starsky/clientapp/src/shared/date.ts index 1112cfd1a4..13718c104e 100644 --- a/starsky/starsky/clientapp/src/shared/date.ts +++ b/starsky/starsky/clientapp/src/shared/date.ts @@ -1,4 +1,4 @@ -import { SupportedLanguages } from "./language"; +import {SupportedLanguages} from "./language"; /** * Is the date Valid? @@ -77,8 +77,11 @@ const parseRelativeDate = ( */ const parseDate = (dateTime: string | undefined, locate: SupportedLanguages): string => { if (!dateTime) return ""; + const timeZoneRegex = /\+\d{2}:\d{2}/; + const isIncludeTimezone = timeZoneRegex.test(dateTime); + // UTC DateTime already ends with Z - const dateTimeObject = new Date(!dateTime.endsWith("Z") ? `${dateTime}Z` : dateTime); + const dateTimeObject = new Date(!dateTime.endsWith("Z") && !isIncludeTimezone ? `${dateTime}Z` : dateTime); // We prefer British English, uses day-month-year order const locateString = locate === SupportedLanguages.en ? "en-GB" : locate.toString(); if (dateTime.endsWith("Z")) {