UNPKG

@helpscout/hsds-react

Version:

React component library for Help Scout's Design System

33 lines (25 loc) 784 B
"use strict"; exports.__esModule = true; exports.calculateTimeoutPeriod = void 0; var MINUTE = 60; var HOUR = MINUTE * 60; var DAY = HOUR * 24; var calculateTimeoutPeriod = function calculateTimeoutPeriod(timestamp) { // Calculate the time passed since the timestamp in seconds var diff = Math.round(Math.abs(Date.now() - new Date(timestamp).valueOf()) / 1000); if (diff < MINUTE) { // Once every second return 1000; } if (diff < HOUR) { // Once every 15 seconds // NB: Not every minute as we had problems with multiple timestamp components updating on different intervals return 1000 * 15; } if (diff < DAY) { // Once every hour return 1000 * HOUR; } // Never return 0; }; exports.calculateTimeoutPeriod = calculateTimeoutPeriod;