test('should handle dates', t => { const smartClone = new SmartClone(); const date = new Date('1/1/2001'); t.is(smartClone.isCloning, false); smartClone.start(date.valueOf()); t.is(smartClone.isCloning, true); t.is(date.valueOf(), smartClone.clone); smartClone.done(); t.is(smartClone.isCloning, false); });
it('can get expiration time in string format', done => { // Make mock request const timeStr = '2015-03-19T22:05:08Z'; const body = { expiration_time: timeStr, }; const time = PushController.getExpirationTime(body); expect(time).toEqual(new Date(timeStr).valueOf()); done(); });
initialize (workpath, data) { data = data || {}; data[CONFIG_VAR_WORKSPACE] = workpath; data[CONFIG_VAR_TIMESTAMP] = Math.floor(new Date().valueOf() / 1000); this.write(data); }
let formatDate = function(str) { let date = new Date(str); let months = 'January February March April May June July August September October November December'.split(' '); let ends = ['th', 'st', 'nd', 'rd', 'th']; let y = chalk.bold(date.getFullYear()); let m = chalk.bold(months[date.getMonth()]); let d = chalk.bold(date.getDate()); let e = chalk.bold(ends[d] || 'th'); let hh = chalk.bold(formatDigits(date.getHours(), 2)); let mm = chalk.bold(formatDigits(date.getMinutes(), 2)); let ss = chalk.bold(formatDigits(date.getSeconds(), 2)); let ms = chalk.bold(formatDigits(date.valueOf() % 1000, 3)); return `${m} ${d}${e}, ${y} at ${hh}:${mm}:${ss}.${ms}`; }
tarball.on('close', () => { let buffer = fs.readFileSync(tmpPath); fs.unlinkSync(tmpPath); progress.log(`Package size: ${formatSize(buffer.byteLength)}`); progress.log(`Compressing ...`); zlib.gzip(buffer, (err, result) => { if (err) { return reject(err); } let t = new Date().valueOf() - start; progress.log(`Compressed size: ${formatSize(result.byteLength)}`); progress.log(`Compression: ${((result.byteLength / buffer.byteLength) * 100).toFixed(2)}%`); progress.log(`Pack complete, took ${t}ms!`); resolve(result); }); });
expect(pushStatus.get('expiry')).toBeDefined('expiry must be set'); expect(pushStatus.get('expiry')).toEqual( new Date('2017-09-25T13:50:10.452Z').valueOf() );
var exp = convertToDate(oauth['not-after']); assert(iat < new Date(), 'not-before is not correct'); assert(exp.valueOf() - Date.now() < 36000000, 'exp is not correct'); done(err);
it("should generate a valid date above minimum", () => { let min = new Date(); min.setUTCMilliseconds(0); let schema = new JsonSchema({ type: "string", format: "date-time", minimum: min }); for (let i = 0; i < iterations; i++) { let date = schema.sample(); expect(date).to.be.an.instanceOf(Date); expect(date.valueOf()).to.be.at.least(min.valueOf()); } });
it("should generate a valid date within min/max", () => { let min = new Date(2008, 5, 27, 15, 32, 17, 100); let max = new Date(2008, 5, 27, 15, 32, 17, 200); let schema = new JsonSchema({ type: "string", format: "date-time", minimum: min, maximum: max }); for (let i = 0; i < iterations; i++) { let date = schema.sample(); expect(date).to.be.an.instanceOf(Date); expect(date.valueOf()).to.be.at.least(min.valueOf()); expect(date.valueOf()).to.be.at.most(max.valueOf()); } });
let formatDate = function(str) { let date = new Date(str); let months = 'January February March April May June July August September October November December'.split(' '); let ends = ['th', 'st', 'nd', 'rd', 'th']; let y = chalk.bold(date.getFullYear()); let m = chalk.bold(months[date.getMonth()]); let d = chalk.bold(date.getDate()); let e = chalk.bold(ends[d] || 'th'); let hh = chalk.bold(formatDigits(date.getHours(), 2)); let mm = chalk.bold(formatDigits(date.getMinutes(), 2)); let ss = chalk.bold(formatDigits(date.getSeconds(), 2)); let ms = chalk.bold(formatDigits(date.valueOf() % 1000, 3)); return `${m} ${d}${e}, ${y} at ${hh}:${mm}:${ss}.${ms}`; }