Skip to content

Commit

Permalink
Fixed verifyTime not working with local time (#194)
Browse files Browse the repository at this point in the history
* Fixed verifyTime not working with local time

The `notBefore` and `notOnOrAfterLocal` are UTC while `now` is the local date. This way the comparison can not work.
The added variables should fix this.

(ref: https://praveenlobo.com/blog/how-to-convert-javascript-local-date-to-utc-and-utc-to-local-date/)

* Updated for TypeScript
  • Loading branch information
fabianloewe authored and tngan committed Jul 25, 2018
1 parent 8103695 commit 031cafd
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,12 +146,17 @@ export default class Entity {
return true; // throw exception todo
}
if (!isUndefined(notBefore) && isUndefined(notOnOrAfter)) {
return +notBefore <= +now;
const notBeforeLocal = new Date(notBefore.toUTCString());
return +notBeforeLocal <= +now;
}
if (isUndefined(notBefore) && !isUndefined(notOnOrAfter)) {
return now < notOnOrAfter;
const notOnOrAfterLocal = new Date(notOnOrAfter.toUTCString());
return now < notOnOrAfterLocal;
} else {
const notBeforeLocal = new Date(notBefore.toUTCString());
const notOnOrAfterLocal = new Date(notOnOrAfter.toUTCString());
return +notBeforeLocal <= +now && now < notOnOrAfterLocal;
}
return +notBefore <= +now && now < notOnOrAfter;
}
/**
* @desc Validate and parse the request/response with different bindings
Expand Down

0 comments on commit 031cafd

Please sign in to comment.