convertTz(field) { const targetTZ = moment().tz(this.timezone).format('Z'); return `CONVERT_TIMEZONE('${targetTZ}', ${field})`; }
db.Channel.update({ comments_crawled_at: moment().subtract(2, 'h').tz('utc') }, { where: { id: uncrawledChannel.id }, }).catch((e) => log.error('Comments Crawler update channel crawl time error', e))
function getCurrentTime(location) { const currentTime = Moment.utc().tz(location); return currentTime; }
Promise.all([fetchTZ(locationFrom, utz), fetchTZ(locationTo, utz)]) .then(([tzFrom, tzTo]) => { const [hh, mm, ss] = (timeFrom ? timeFrom : moment.tz(tzFrom).format('H:m:s')) .split(':') .map(e => +e); const fromDt = moment.tz(tzFrom).hour(hh).minute(mm); const toDt = moment.tz(tzFrom).hour(hh).minute(mm).tz(tzTo); return `${timeFrom ? 'When it\'s' : 'It\'s'} ${fromDt.format('h:mm a')} in ${getLocation(locationFrom)}, ${timeFrom ? 'it\'s' : 'and'} ${toDt.format('h:mm a')} in ${getLocation(locationTo)} `; })
morgan.token('request_at_time', function(req, res, param) { return moment().tz('Asia/Dhaka').format('DD-MM-YYYY hh:mm:ss A Z'); });
Nominatim.get('search', { params: { q } }).then(response => { if(response.data.length > 0){ let place = response.data[0]; let timezone = tzlookup(Number(place.lat), Number(place.lon)); resolve(`${moment().tz(timezone).format('HH:mm, MMM DD')} (${timezone})`); }else{ reject("Couldn't find this place"); } }).catch(err => { reject("An error occured fetching the place"); });
createBirthdayReminder(daysUntilBirthday, timezone, locale, message) { moment.locale(locale); const createdMoment = moment().tz(timezone); let triggerMoment = createdMoment.startOf('day').add(daysUntilBirthday, 'days'); if (daysUntilBirthday === 0) { triggerMoment = createdMoment.startOf('day').add(1, 'years'); // reminder created on the day of birthday will trigger next year } console.log('Reminder schedule: ' + triggerMoment.format('YYYY-MM-DDTHH:mm:00.000')); return util.createReminder(createdMoment, triggerMoment, timezone, locale, message); }
async function modificarNoticia(req, res) { try { const { id } = req.params; await Coronavirus.updateOne({ _id: id }, { date: moment(new Date()).tz('America/Argentina/Buenos_Aires').format('HH:mm'), titulo: req.body.titulo, confirmados: req.body.confirmados, total_mundo: req.body.total_mundo, recuperados: req.body.recuperados, fallecidos: req.body.fallecidos, activos: req.body.confirmados - req.body.recuperados - req.body.fallecidos }); res.status(200).json('Modificado con éxito!') log.warn('Modificado con éxito!'); } catch (err) { log.error('Ups hubo un error!! ' + err); } }
const nowLocal = moment().tz(tz)
getAdjustedDate(timezone) { const today = moment().tz(timezone).startOf('day'); return { day: today.date(), month: today.month() + 1 } }
getBirthdayData(day, month, year, timezone) { const today = moment().tz(timezone).startOf('day'); const wasBorn = moment(`${month}/${day}/${year}`, "MM/DD/YYYY").tz(timezone).startOf('day'); const nextBirthday = moment(`${month}/${day}/${today.year()}`, "MM/DD/YYYY").tz(timezone).startOf('day'); if (today.isAfter(nextBirthday)) { nextBirthday.add(1, 'years'); } const age = today.diff(wasBorn, 'years'); const daysAlive = today.diff(wasBorn, 'days'); const daysUntilBirthday = nextBirthday.startOf('day').diff(today, 'days'); // same day returns 0 return { daysAlive: daysAlive, // not used but nice to have :) daysUntilBirthday: daysUntilBirthday, age: age //in years } }
db.Channel.update({ comments_crawled_at: moment().subtract(2, 'h').tz('utc') }, { where: { id: uncrawledChannel.id }, }).catch((e) => log.error('Comments Crawler update channel crawl time (found no new comments) error', e))
fetchTZ(location, utz) .then(tz => { const nowUTC = moment.tz(utz).utc(); const dt = (date ? moment.utc(date) .hour(nowUTC.hour()) .minute(nowUTC.minute()) .second(nowUTC.second()) : moment ).tz(utz); const realDayOfWeek = dt.tz(tz).format('dddd'); return dayofweek === realDayOfWeek ? ` Yes, it's ${realDayOfWeek} ` : `No, it's ${realDayOfWeek}` })