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

UTC client WIP #954

Open
wants to merge 1 commit 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
14 changes: 13 additions & 1 deletion starsky/starsky/clientapp/src/shared/date.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,18 @@ const IsEditedNow = (inputDateTime: undefined | string): boolean | null => {
return difference <= 0.2;
};

function ConvertUTCDateToLocalDate(date: Date): Date {
const newDate = new Date(
date.getTime() + date.getTimezoneOffset() * 60 * 1000
);

const offset = date.getTimezoneOffset() / 60;
const hours = date.getHours();

newDate.setHours(hours - offset);
return newDate;
}

/**
* Get the relative date, for example 6 hour ago
* @param inputDateTime 2018-09-11T11:23:19 or 2018-09-11T11:23:19Z
Expand All @@ -56,7 +68,7 @@ const parseRelativeDate = (
let date = "";

if (!inputDateTime) return date;
let input = new Date(`${inputDateTime}`).valueOf();
let input = ConvertUTCDateToLocalDate(new Date(`${inputDateTime}`)).valueOf();

if (!input) return date;

Expand Down