-
Notifications
You must be signed in to change notification settings - Fork 323
Expand file tree
/
Copy pathutils.ts
More file actions
23 lines (22 loc) · 929 Bytes
/
utils.ts
File metadata and controls
23 lines (22 loc) · 929 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
/**
* Helper, that is used to forcibly finalize all promises
* in thunk before running matcher against state.
*
* TODO: move this to setupTest or testUtils - it's only used in tests.
*/
export const executeThunk = async (thunk, dispatch, getState = undefined) => {
await thunk(dispatch, getState);
await new Promise(setImmediate);
};
/**
* Utility function for appending the browser timezone to the url
* Can be used on the backend when the user timezone is not set in the user account
*/
export const appendBrowserTimezoneToUrl = (url: string) => {
const browserTimezone = Intl.DateTimeFormat().resolvedOptions().timeZone;
const urlObject = new URL(url, url.startsWith('http') ? undefined : 'http://localhost');
if (browserTimezone) {
urlObject.searchParams.append('browser_timezone', browserTimezone);
}
return url.startsWith('http') ? urlObject.href : `${urlObject.pathname}${urlObject.search}`;
};