gristlabs_grist-core/app/common/getCurrentTime.ts
Jarosław Sadziński b59829d57e (core) Updating dependencies for moment package
Summary:
moment.js version in yarn.lock file was outdated and contained
a set of typings that are diffrent from the one visible from grist-core.

Test Plan: Existing tests

Reviewers: paulfitz

Reviewed By: paulfitz

Subscribers: paulfitz

Differential Revision: https://phab.getgrist.com/D3760
2023-01-09 18:20:01 +01:00

14 lines
499 B
TypeScript

import moment from "moment-timezone";
/**
* Returns the current local time. Allows overriding via a "currentTime" URL parameter, for the sake
* of tests.
*/
export default function getCurrentTime(): moment.Moment {
const getDefault = () => moment();
if (typeof window === 'undefined' || !window) { return getDefault(); }
const searchParams = new URLSearchParams(window.location.search);
return searchParams.has('currentTime') ? moment(searchParams.get('currentTime')) : getDefault();
}