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(''); }
lock (tableName, key) { const curr = new Date() const expiryDate = new Date(curr.getTime()) expiryDate.setMilliseconds(expiryDate.getMilliseconds() + this.lifetime) return new Promise((resolve, reject) => { const params = { Key: key, UpdateExpression: `set locked = :t, expiryDate = :e`, ConditionExpression: '(locked <> :t) or (expiryDate < :c)', ExpressionAttributeValues: { ':t': true, ':c': curr.toISOString(), ':e': expiryDate.toISOString() }, TableName: tableName } const { AWS_REGION: region } = process.env const awsDynamoDb = new AWS.DynamoDB.DocumentClient({ region }) awsDynamoDb.update(params, (err, data) => { if (err && err.code === 'ConditionalCheckFailedException') { return reject(new MutexLockedError('mutex locked')) } else if (err) { return reject(new VError(err, 'DynamoDB')) } resolve() }) }) }
const filePath = path.join( this.gladys.config.tempFolder, `camera-${device.id}-${now.getMilliseconds()}-${now.getSeconds()}-${now.getMinutes()}-${now.getHours()}.jpg`, );
minutes: date.getMinutes(), seconds: date.getSeconds(), milliseconds: date.getMilliseconds() }); expect(dateParser('from 1 hour ago to now', 'America/Los_Angeles')).toStrictEqual(
const lifetime = 1000 await new Mutex({lifetime}).lock('table', key) curr.setMilliseconds(curr.getMilliseconds() + lifetime) assert(actual.ExpressionAttributeValues[':e'] === curr.toISOString())
log(...args) { const dt = new Date(); const dtf = `${dt.getHours()}:${dt.getMinutes()}:${dt.getSeconds()}.${dt.getMilliseconds()}`; let cons; args.unshift(dtf); if (this.gui && global.window) { cons = global.window.console; } else { cons = console; } if (this.logToFile) { this.debug(args); } args.unshift('\n'); if (this.logToConsole) { // eslint-disable-next-line prefer-spread cons.log.apply(cons, args); } }
/* * Date format */ export function format(date: Date, format ?: string) { format = format || 'MMddhhmm'; let o = { 'M+': date.getMonth() + 1, // month 'd+': date.getDate(), // day 'h+': date.getHours(), // hour 'm+': date.getMinutes(), // minute 's+': date.getSeconds(), // second 'q+': Math.floor((date.getMonth() + 3) / 3), // quarter 'S': date.getMilliseconds() // millisecond }; if (/(y+)/.test(format)) { format = format.replace(RegExp.$1, (date.getFullYear() + '').substr(4 - RegExp.$1.length)); } for (let k in o) { if (new RegExp('(' + k + ')').test(format)) { format = format.replace(RegExp.$1, RegExp.$1.length === 1 ? (o as any)[k] : ('00' + (o as any)[k]).substr(('' + (o as any)[k]).length)); } } return format; }
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(''); }
lock (tableName, key) { const curr = new Date() const expiryDate = new Date(curr.getTime()) expiryDate.setMilliseconds(expiryDate.getMilliseconds() + this.lifetime) return new Promise((resolve, reject) => { const params = { Key: key, UpdateExpression: `set locked = :t, expiryDate = :e`, ConditionExpression: '(locked <> :t) or (expiryDate < :c)', ExpressionAttributeValues: { ':t': true, ':c': curr.toISOString(), ':e': expiryDate.toISOString() }, TableName: tableName } const { AWS_REGION: region } = process.env const awsDynamoDb = new AWS.DynamoDB.DocumentClient({ region }) awsDynamoDb.update(params, (err, data) => { if (err && err.code === 'ConditionalCheckFailedException') { return reject(new MutexLockedError('mutex locked')) } else if (err) { return reject(new VError(err, 'DynamoDB')) } resolve() }) }) }
const filePath = path.join( this.gladys.config.tempFolder, `camera-${device.id}-${now.getMilliseconds()}-${now.getSeconds()}-${now.getMinutes()}-${now.getHours()}.jpg`, );
const filePath = path.join( this.gladys.config.tempFolder, `camera-${device.id}-${now.getMilliseconds()}-${now.getSeconds()}-${now.getMinutes()}-${now.getHours()}.jpg`, );
const lifetime = 1000 await new Mutex({lifetime}).lock('table', key) curr.setMilliseconds(curr.getMilliseconds() + lifetime) assert(actual.ExpressionAttributeValues[':e'] === curr.toISOString())
/* * Date format */ export function format(date: Date, format ?: string) { format = format || 'MM-dd-hhmm'; let o: any = { 'M+': date.getMonth() + 1, // month 'd+': date.getDate(), // day 'h+': date.getHours(), // hour 'm+': date.getMinutes(), // minute 's+': date.getSeconds(), // second 'q+': Math.floor((date.getMonth() + 3) / 3), // quarter 'S': date.getMilliseconds() // millisecond }; if (/(y+)/.test(format)) { format = format.replace(RegExp.$1, (date.getFullYear() + '').substr(4 - RegExp.$1.length)); } for (let k in o) { if (new RegExp('(' + k + ')').test(format)) { format = format.replace(RegExp.$1, RegExp.$1.length === 1 ? o[k] : ('00' + o[k]).substr(('' + o[k]).length)); } } return format; }
/* * Date format */ export function format(date: Date, format ?: string) { format = format || 'MMddhhmm'; let o = { 'M+': date.getMonth() + 1, // month 'd+': date.getDate(), // day 'h+': date.getHours(), // hour 'm+': date.getMinutes(), // minute 's+': date.getSeconds(), // second 'q+': Math.floor((date.getMonth() + 3) / 3), // quarter 'S': date.getMilliseconds() // millisecond }; if (/(y+)/.test(format)) { format = format.replace(RegExp.$1, (date.getFullYear() + '').substr(4 - RegExp.$1.length)); } for (let k in o) { if (new RegExp('(' + k + ')').test(format)) { format = format.replace(RegExp.$1, RegExp.$1.length === 1 ? (o as any)[k] : ('00' + (o as any)[k]).substr(('' + (o as any)[k]).length)); } } return format; }
/* * Date format */ export function format(date: Date, format ?: string) { format = format || 'MM-dd-hhmm'; let o: any = { 'M+': date.getMonth() + 1, // month 'd+': date.getDate(), // day 'h+': date.getHours(), // hour 'm+': date.getMinutes(), // minute 's+': date.getSeconds(), // second 'q+': Math.floor((date.getMonth() + 3) / 3), // quarter 'S': date.getMilliseconds() // millisecond }; if (/(y+)/.test(format)) { format = format.replace(RegExp.$1, (date.getFullYear() + '').substr(4 - RegExp.$1.length)); } for (let k in o) { if (new RegExp('(' + k + ')').test(format)) { format = format.replace(RegExp.$1, RegExp.$1.length === 1 ? o[k] : ('00' + o[k]).substr(('' + o[k]).length)); } } return format; }