UNPKG

@smart-consulting/lattice-services

Version:

Collection of common types and functions for connecting to Lattice services

34 lines (33 loc) 1.27 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getLastLogin = void 0; /** * Find the time difference between current and/or given dates * @param lastLoginDate - string: Last login date value * @param otherDate - string: Optional second date value */ function getLastLogin(lastLoginDate, otherDate) { var secondDate = otherDate ? new Date(otherDate) : new Date(); var lastDate = new Date(lastLoginDate); var timeDiff = (secondDate.getTime() - lastDate.getTime()) / (60 * 1000); if (timeDiff < 0 || isNaN(lastDate.getTime())) { return 'N/A'; } else if (timeDiff < 60) { var min = Math.ceil(timeDiff); return min > 1 ? min + " min" + (min > 1 ? 's' : '') + " ago" : Math.ceil(timeDiff * 60) + " secs ago"; } else if (timeDiff / 60 < 24) { var hour = Math.ceil(timeDiff / 60); return hour + " hour" + (hour > 1 ? 's' : '') + " ago"; } else if (timeDiff / 1440 < 7) { var day = Math.ceil(timeDiff / 1440); return day + " day" + (day > 1 ? 's' : '') + " ago"; } else { var week = Math.ceil(timeDiff / 10080); return week + " week" + (week > 1 ? 's' : '') + " ago"; } } exports.getLastLogin = getLastLogin;