1
0
Fork 0

[DEV-3514] Fix bug with expiration date calculation

See merge request floss/liza!55
master
Corey Vollmer 2019-05-30 14:30:48 -04:00
commit 8285fe629c
2 changed files with 44 additions and 43 deletions

View File

@ -285,7 +285,7 @@ module.exports = Class( 'BaseQuote' )
|| ( !post_rate && !this._program.lockTimeout.preRateExpiration )
|| ( post_rate && !this._program.lockTimeout.postRateExpiration ))
{
return Number.POSITIVE_INFINITY;
return Infinity;
}
var reference_date = ( post_rate ) ? this._initialRatedDate : this._startDate;
@ -294,8 +294,8 @@ module.exports = Class( 'BaseQuote' )
: this._program.lockTimeout.preRateExpiration;
// Use Date.setDate to accommodate leap seconds, leap years, DST, etc.
var expiration_date = new Date( reference_date );
expiration_date.setDate( expiration_date.getDate() + expiration_period );
var expiration_date = new Date( reference_date * 1000 );
expiration_date.setDate( expiration_date.getDate() + +( expiration_period ) );
return expiration_date.getTime();
},
@ -320,16 +320,16 @@ module.exports = Class( 'BaseQuote' )
var expiration_timestamp = this.getExpirationDate();
// If the timestamp is INFINITY, the quote will never expire
// NOTE: The Date constructor does not support INFINITY as the timestamp
if ( expiration_timestamp === Number.POSITIVE_INFINITY )
// If the timestamp is infinite, the quote will never expire
// NOTE: The Date constructor does not support `Infinity` as the timestamp
if ( expiration_timestamp === Infinity )
{
return false;
}
// Use Date.setDate to accommodate leap seconds, leap years, DST, etc.
var expiration_date = new Date( expiration_timestamp );
expiration_date.setDate( expiration_date.getDate() + grace_period );
expiration_date.setDate( expiration_date.getDate() + +( grace_period ));
return current_date.getTime() > expiration_date.getTime();
},

View File

@ -245,9 +245,9 @@ describe( 'BaseQuote', () =>
preRateExpiration: 90,
postRateExpiration: 30
},
startDate: 86400000,
expirationDate: 7862400000,
currentDate: 86400000,
startDate: 86400,
expirationDate: 7862400,
currentDate: 86400,
expired: false
},
{
@ -258,9 +258,9 @@ describe( 'BaseQuote', () =>
postRateExpiration: 30
},
startDate: 86400000,
initialRatedDate: 172800000,
expirationDate: 2764800000,
currentDate: 172800000,
initialRatedDate: 172800,
expirationDate: 2764800,
currentDate: 172800,
expired: false
},
{
@ -271,9 +271,9 @@ describe( 'BaseQuote', () =>
postRateExpiration: 30
},
startDate: 86400,
initialRatedDate: 172800000,
expirationDate: 2764800000,
currentDate: 2851200000,
initialRatedDate: 172800,
expirationDate: 2764800,
currentDate: 2851200,
expired: true
},
{
@ -286,9 +286,9 @@ describe( 'BaseQuote', () =>
postRateGracePeriod: 5
},
startDate: 86400,
initialRatedDate: 172800000,
expirationDate: 2764800000,
currentDate: 2851200000,
initialRatedDate: 172800,
expirationDate: 2764800,
currentDate: 2851200,
expired: false
},
{
@ -298,9 +298,9 @@ describe( 'BaseQuote', () =>
preRateExpiration: 90,
postRateExpiration: 30
},
startDate: 86400000,
expirationDate: 7862400000,
currentDate: 5356800000,
startDate: 86400,
expirationDate: 7862400,
currentDate: 5356800,
expired: false
},
{
@ -310,10 +310,10 @@ describe( 'BaseQuote', () =>
preRateExpiration: 90,
postRateExpiration: 30
},
startDate: 86400000,
initialRatedDate: 172800000,
expirationDate: 2764800000,
currentDate: 5356800000,
startDate: 86400,
initialRatedDate: 172800,
expirationDate: 2764800,
currentDate: 5356800,
expired: true
},
{
@ -323,9 +323,9 @@ describe( 'BaseQuote', () =>
preRateExpiration: 90,
postRateExpiration: 30
},
startDate: 86400000,
expirationDate: 7862400000,
currentDate: 7948800000,
startDate: 86400,
expirationDate: 7862400,
currentDate: 7948800,
expired: true
},
{
@ -337,9 +337,9 @@ describe( 'BaseQuote', () =>
postRateExpiration: 30,
postRateGracePeriod: 5
},
startDate: 86400000,
expirationDate: 7862400000,
currentDate: 7948800000,
startDate: 86400,
expirationDate: 7862400,
currentDate: 7948800,
expired: false
},
{
@ -349,9 +349,9 @@ describe( 'BaseQuote', () =>
preRateExpiration: 90,
postRateExpiration: 30
},
startDate: 86400000,
expirationDate: 7862400000,
currentDate: 10540800000,
startDate: 86400,
expirationDate: 7862400,
currentDate: 10540800,
expired: true
},
{
@ -361,10 +361,10 @@ describe( 'BaseQuote', () =>
preRateExpiration: 90,
postRateExpiration: 30
},
startDate: 86400000,
initialRatedDate: 172800000,
expirationDate: 2764800000,
currentDate: 10540800000,
startDate: 86400,
initialRatedDate: 172800,
expirationDate: 2764800,
currentDate: 10540800,
expired: true
}
@ -374,8 +374,9 @@ describe( 'BaseQuote', () =>
const description = "Expiration is correct for " + testCase.description;
const start_date = testCase.startDate;
const initial_rated_date = testCase.initialRatedDate;
const current_date = testCase.currentDate;
const expiration_date = testCase.expirationDate;
const current_date = testCase.currentDate * 1000;
const expiration_date = ( typeof testCase.expirationDate === "number" )
? testCase.expirationDate * 1000 : undefined;
const expired = testCase.expired;
quote.setProgram( createStubProgram( testCase.lockTimeout ) );
@ -394,10 +395,10 @@ describe( 'BaseQuote', () =>
if ( expiration_date !== undefined )
{
expect( quote.getExpirationDate() ).to.equal( +expiration_date );
expect( quote.getExpirationDate() ).to.equal( expiration_date );
}
expect( quote.hasExpired( new Date( current_date ) ) ).to.equal( !!expired );
expect( quote.hasExpired( new Date( current_date ) ) ).to.equal( expired );
} );
} );
} );