JSFiddle - React, Tailwind, and code Playground

Expiry issue we faced yesterday May 31, 2017 around 8:00 pm

by Nalin Sajwan

JavaScript

// Possible login scenario date.
var currentDate = new Date("Wed May 31 2017 19:45:06 GMT+0530");

// Copy of currentDate.
var expiryDate = new Date(currentDate);

// License login expiry date.
var licenseExpiry = new Date("2017-12-31T14:12:50.585+0000");

// Expiry time assigned per token.
var tokenExpiryLimit = 120; // In Minutes

console.log("\ncurrentDate ==> ",currentDate.toString());
console.log("currentDate iso ==> ",currentDate.toISOString());

console.log("\nexpiryDate ==> ",expiryDate.toString());
console.log("expiryDate iso ==> ",expiryDate.toISOString());

console.log("\nlicenseExpiry ==> ",licenseExpiry.toString());
console.log("licenseExpiry iso ==> ",licenseExpiry.toISOString());

if(licenseExpiry !== undefined && licenseExpiry !== null) {

	// licenseExpiry = new Date(licenseExpiry);

	console.log("\nlicenseExpiry.getMinutes() ==> ", licenseExpiry.getMinutes());
	console.log("\ncurrentDate.getMinutes() ==> ", currentDate.getMinutes());

	var difference = licenseExpiry.getMinutes() - currentDate.getMinutes();

	console.log("\ndifference ==> ", difference);

	console.log("\nlicenseExpiry.getDate() ==> ", licenseExpiry.getDate());

	console.log("\ncurrentDate.getDate() ==> ", currentDate.getDate());

	console.log("\nMath.abs(licenseExpiry.getDate() - currentDate.getDate()) ==> ", Math.abs(licenseExpiry.getDate() - currentDate.getDate()));

	console.log("\ndifference < tokenExpiryLimit ==> ", difference, " --- ", tokenExpiryLimit, " \n\t--> ", difference < tokenExpiryLimit);

	if(Math.abs(licenseExpiry.getDate() - currentDate.getDate()) === 0 && difference < tokenExpiryLimit){

		console.log("\nlicenseExpiry.getHours() ==> ", licenseExpiry.getHours());

		console.log("\ncurrentDate.getHours() ==> ", currentDate.getHours());

		console.log("\nMath.abs(licenseExpiry.getHours() - currentDate.getHours()) ==> ", Math.abs(licenseExpiry.getHours() - currentDate.getHours()));

		console.log("\nMath.abs(licenseExpiry.getHours() - currentDate.getHours()) * 60...