Skip to content

Commit f466987

Browse files
committed
Use full ISOString for dynamic dates.
1 parent b6ec6cb commit f466987

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

test/10-verify.spec.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -780,7 +780,6 @@ for(const [version, mockCredential] of versionedCredentials) {
780780
if(version === 1.0) {
781781
// we submit with second precission,
782782
// but throw with millisecond precision
783-
const getISOString = stamp => new Date(stamp).toISOString();
784783
it('should reject if "now" is before "issuanceDate"', () => {
785784
const credential = jsonld.clone(mockCredential);
786785
credential.issuer = 'did:example:12345';
@@ -795,8 +794,8 @@ for(const [version, mockCredential] of versionedCredentials) {
795794
should.exist(error,
796795
'Should throw error when "now" is before "issuanceDate"');
797796
error.message.should.contain(
798-
`The current date time (${getISOString(now)}) is before the ` +
799-
`"issuanceDate" (${getISOString(credential.issuanceDate)}).`);
797+
`The current date time (${now}) is before the ` +
798+
`"issuanceDate" (${credential.issuanceDate}).`);
800799
});
801800
}
802801
if(version === 2.0) {

test/helpers.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1-
export function createTimeStamp({date}) {
2-
const isoString = date.toISOString();
3-
// remove the milliseconds from the iso time stamp
4-
return isoString.substr(0, isoString.length - 5) + 'Z';
5-
}
6-
1+
/**
2+
* Creates an ISO DateTime skewed by a number of years
3+
*
4+
* @param {object} options - Options to use.
5+
* @param {Date} [options.date = new Date()] - An optional date to use.
6+
* @param {number} options.skewYear - A number to skew the year.
7+
*
8+
* @returns {string} Returns an ISO DateTime String.
9+
*/
710
export function createSkewedTimeStamp({date = new Date(), skewYear}) {
811
date.setFullYear(date.getFullYear() + skewYear);
9-
return createTimeStamp({date});
12+
return date.toISOString();
1013
}

0 commit comments

Comments
 (0)