I am trying to make a calendar which I can not do the synchronization adjustment with the server uses UTC ++ 0000
So when making the activation of reminders will always occur a margin well above or below the GMT that the user is.
For the time I am using precolate-cronjobs I leave the code of my logic to see if they can give me a help or to point me a better solution.
I only need to apply the format of the utc + 000 to make the adjustment to any time use with the server utc + 000 and there is no such time difference in any case.
/*remminder.js*/
import moment from 'moment';
SyncedCron.add({
name: 'Recordatorio Personas',
schedule: function(parser) {
return parser.text('every 10 seconds');
},
job: function(intendedAt) {
Meteor.call('timer1', intendedAt);
}
});
Meteor.startup(function () {
SyncedCron.start();
console.log("iniciando..")
});
/*timer.js*/
import { Meteor } from 'meteor/meteor';
import moment from 'moment';
import momentT from 'moment-timezone';
Meteor.methods({
timer1: function(timer){
//console.log("metodos Timer",timer);
var data = AddPerson.find({ id: this.userId}).fetch();
for (var i = 0; i < data.length; i++) {
/****************GLOBAL************************/
console.log('/*Server logs CronJobs*/')
//var timerD = moment(timer).format('HH:mm');
var s = momentT.tz.guess();
var TimerD = momentT.tz(timer, s).format('HH:mm');;
var createdAt=data[i].createdAt;
var m =moment.utc(createdAt).format('YYYY-MM-DD');
var mh= m +' '+ data[i].hora;
var mhutc = momentT.tz(mh, s).format('HH:mm');
var dateTime= new Date();
console.log('hUser:',data[i].hora);
console.log('DateSistema:', dateTime)
console.log('mh:', mh);
console.log('s:',s);
console.log('mhutc',mhutc);
console.log('m',m);
console.log('timerCron:', timer);
console.log('convertTimer:',TimerD);
console.log('/****end logs*****/');
/****************GLOBAL***********************/
/****************Daily************************/
if (data[i].recordatorio === 'Diario' || data[i].recordatorio === 'Daily'){
if (TimerD === data[i].hora) {
console.log("STOP Send Push")
Meteor.call("serverNotification");
} else {
console.log('contando.');
}
}
/*****************Weekly************************/
if (data[i].recordatorio === 'Semanal' || data[i].recordatorio === 'Weekly' ){
var timerSemanal= moment(data[i].createdAt).day();
var timerS = moment(timer).day();
if (TimerD === mhutc && timerSemanal === timerS) {
console.log("STOP Enviar Push")
Meteor.call("serverNotification");
} else {
console.log('contando.');
}
}
/*****************Monthly************************/
if (data[i].recordatorio === 'Mensual' || data[i].recordatorio === 'Monthly'){
var TimerMes= moment(timer).date();
var timerM = moment(timer).date();
if (TimerD === data[i].hora && timerMes === timerM) {
console.log("STOP Enviar Push")
Meteor.call("serverNotification");
} else {
console.log('contando.');
}
}
/*****************end************************/
}
}
})