function createCert(publicKey, serialNumber, isShortPeriod) { var cert = pki.createCertificate(); cert.publicKey = publicKey; cert.serialNumber = serialNumber || '01'; var curYear = new Date().getFullYear(); cert.validity.notBefore = new Date(); cert.validity.notAfter = new Date(); cert.validity.notBefore.setFullYear(curYear - 1); // https://chromium.googlesource.com/chromium/src/+/refs/heads/master/net/cert/cert_verify_proc.cc#900 cert.validity.notAfter.setFullYear(curYear + (isShortPeriod ? 1 : 10)); return cert; }
function formatDate() { var date = new Date(); var result = []; result.push(date.getFullYear()); result.push(padding(date.getMonth() + 1)); result.push(padding(date.getDate())); result.push(padding(date.getHours())); result.push(padding(date.getMinutes())); result.push(padding(date.getSeconds())); result.push(paddingMS(date.getMilliseconds())); return result.join(''); }
/** * 生成订单的编号order_sn * @returns {string} */ generateOrderNumber() { const date = new Date(); return date.getFullYear() + _.padStart(date.getMonth(), 2, '0') + _.padStart(date.getDay(), 2, '0') + _.padStart(date.getHours(), 2, '0') + _.padStart(date.getMinutes(), 2, '0') + _.padStart(date.getSeconds(), 2, '0') + _.random(100000, 999999); }
it('should collect a yesterday\'s datapoint if it does not exist', async () => { const getMetricDataStub = sinon.stub(MockService.prototype, 'getMetricData').returns([]) const params = generateConstructorParams() const metric = new Metric(params) metric.calculateUncollectedDates = () => 1 await metric.collect() assert(getMetricDataStub.calledTwice) const argsAtSecondCall = getMetricDataStub.args[1] const actualBegin = argsAtSecondCall[2] const actualEnd = argsAtSecondCall[3] const now = new Date() assert(actualBegin.getTime() === new Date(now.getFullYear(), now.getMonth(), now.getDate() - 1).getTime()) assert(actualEnd.getTime() === new Date(now.getFullYear(), now.getMonth(), now.getDate()).getTime()) })
render() { const year = new Date().getFullYear(); return ( <div className="footer"> <div className="container"> <span className="copyright pull-right"> © {year} Acme, Inc. </span> <ul className="links"> <li><a href="/">Home</a></li> <li><a href="/login/logout">Sign out</a></li> </ul> </div> </div> ); }
describe(`for Date override`, () => { beforeEach(() => { Date.prototype.toPostgres = () => { function subLevel() { return this.getFullYear(); } return subLevel; }; }); const today = new Date(); it(`must covert correctly`, () => { expect(pgp.as.format(`$1`, today)).toBe(today.getFullYear().toString()); }); afterEach(() => { delete Date.prototype.toPostgres; }); });
it('should collect a datapoint and insert it', async () => { const date = getBeginningOfToday() const newDatapoints = [{timestamp: date.toISOString(), value: 1}] const getMetricDataStub = sinon.stub(MockService.prototype, 'getMetricData').returns(newDatapoints) const params = generateConstructorParams() const metric = new Metric(params) metric.calculateUncollectedDates = () => 0 await metric.collect() const actual = await metric.getDatapoints(new Date()) assert(actual.length === newDatapoints.length) assert(actual[0].timestamp === newDatapoints[0].timestamp.substr(0, 16) + ':00.000Z') assert(actual[0].value === newDatapoints[0].value) const actualBegin = getMetricDataStub.args[0][2] const actualEnd = getMetricDataStub.args[0][3] const now = new Date() assert(actualBegin.getTime() === new Date(now.getFullYear(), now.getMonth(), now.getDate()).getTime()) assert(actualEnd.getTime() === new Date(now.getFullYear(), now.getMonth(), now.getDate() + 1).getTime()) })
get date() { const _ = new Date(); return [_.getFullYear(), _.getMonth() + 1, _.getDate()].join('-'); }
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}`; }
render() { const year = new Date().getFullYear(); return ( <div className="footer"> <div className="container"> <span className="copyright pull-right"> © {year} Acme, Inc. </span> <ul className="links"> <li><Link to="/">Home</Link></li> <li><Link to="/contact">Contact</Link></li> </ul> <div className="clearfix"></div> </div> </div> ); }
function formatDate() { var date = new Date(); var result = []; result.push(date.getFullYear()); result.push(padding(date.getMonth() + 1)); result.push(padding(date.getDate())); result.push(padding(date.getHours())); result.push(padding(date.getMinutes())); result.push(padding(date.getSeconds())); result.push(paddingMS(date.getMilliseconds())); return result.join(''); }
/** * 生成订单的编号order_sn * @returns {string} */ generateOrderNumber() { const date = new Date(); return date.getFullYear() + _.padStart(date.getMonth(), 2, '0') + _.padStart(date.getDay(), 2, '0') + _.padStart(date.getHours(), 2, '0') + _.padStart(date.getMinutes(), 2, '0') + _.padStart(date.getSeconds(), 2, '0') + _.random(100000, 999999); }
it('should collect a yesterday\'s datapoint if it does not exist', async () => { const getMetricDataStub = sinon.stub(MockService.prototype, 'getMetricData').returns([]) const params = generateConstructorParams() const metric = new Metric(params) metric.calculateUncollectedDates = () => 1 await metric.collect() assert(getMetricDataStub.calledTwice) const argsAtSecondCall = getMetricDataStub.args[1] const actualBegin = argsAtSecondCall[2] const actualEnd = argsAtSecondCall[3] const now = new Date() assert(actualBegin.getTime() === new Date(now.getFullYear(), now.getMonth(), now.getDate() - 1).getTime()) assert(actualEnd.getTime() === new Date(now.getFullYear(), now.getMonth(), now.getDate()).getTime()) })
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}`; }
render() { const year = new Date().getFullYear(); return ( <div className="footer"> <div className="container"> <span className="copyright pull-right"> © {year} Acme, Inc. </span> <ul className="links"> <li><a href="/">Home</a></li> <li><a href="/login/logout">Sign out</a></li> </ul> </div> </div> ); }