mirror of
https://github.com/MeowLynxSea/Proksea.git
synced 2025-07-10 19:34:41 +00:00
49 lines
1.4 KiB
JavaScript
49 lines
1.4 KiB
JavaScript
/*! @azure/msal-common v14.12.0 2024-06-10 */
|
|
'use strict';
|
|
/*
|
|
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
* Licensed under the MIT License.
|
|
*/
|
|
/**
|
|
* Utility functions for managing date and time operations.
|
|
*/
|
|
/**
|
|
* return the current time in Unix time (seconds).
|
|
*/
|
|
function nowSeconds() {
|
|
// Date.getTime() returns in milliseconds.
|
|
return Math.round(new Date().getTime() / 1000.0);
|
|
}
|
|
/**
|
|
* check if a token is expired based on given UTC time in seconds.
|
|
* @param expiresOn
|
|
*/
|
|
function isTokenExpired(expiresOn, offset) {
|
|
// check for access token expiry
|
|
const expirationSec = Number(expiresOn) || 0;
|
|
const offsetCurrentTimeSec = nowSeconds() + offset;
|
|
// If current time + offset is greater than token expiration time, then token is expired.
|
|
return offsetCurrentTimeSec > expirationSec;
|
|
}
|
|
/**
|
|
* If the current time is earlier than the time that a token was cached at, we must discard the token
|
|
* i.e. The system clock was turned back after acquiring the cached token
|
|
* @param cachedAt
|
|
* @param offset
|
|
*/
|
|
function wasClockTurnedBack(cachedAt) {
|
|
const cachedAtSec = Number(cachedAt);
|
|
return cachedAtSec > nowSeconds();
|
|
}
|
|
/**
|
|
* Waits for t number of milliseconds
|
|
* @param t number
|
|
* @param value T
|
|
*/
|
|
function delay(t, value) {
|
|
return new Promise((resolve) => setTimeout(() => resolve(value), t));
|
|
}
|
|
|
|
export { delay, isTokenExpired, nowSeconds, wasClockTurnedBack };
|
|
//# sourceMappingURL=TimeUtils.mjs.map
|