I want to schedule the cron job according to the specified time zone. It will fire fine for first time but next time it will not firing according to the specified time zone rather it is firing according to the system's time.
Trigger trigger = TriggerBuilder.newTrigger().withDescription(jobPojo.getDescription()).withIdentity(jobPojo.getTriggerName(), jobPojo.getTriggerGroup())
.withSchedule(CronScheduleBuilder.cronSchedule(jobPojo.getExpression().trim()).inTimeZone(TimeZone.getTimeZone(jobPojo.getTimeZone())).withMisfireHandlingInstructionIgnoreMisfires()).usingJobData(jobDataMap).forJob(jobKey).build();
// As i am passing timezone in json pojo eg: jobPojo.getTimeZone() ="GMT+4:00" which is Dubai timezone Id . my system is running in India.
below is my fetching code :
SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
Trigger trigger = scheduler.getTrigger(triggerKey);
jobPojo.setNextFireTime(dateFormat.format(trigger.getNextFireTime()));
thanx in advance ..
Related
Say for example i want to run a job for a day at "3:22, 4:22, 6:22, 10:22, 18:22, 21.22" on these times just for the current day.
How could we write a cron expresion for it or using other Simple Trigger of Quartz API.
Using cron trigger you can set endAt() to stop trigger at the end of the day
trigger = newTrigger()
.withSchedule(cronSchedule(0 22 3,4,6,10,18,21 ? * * *))
.endAt(TRIGGER_END_TIME)
.forJob(myJobKey)
.build();
My Alexa node.js skill involves getting the current date using "new Date()". In the Service Simulator the date returned is UTC. But I need the time in "America/New_York" -- my skill is local to New York. So I can convert the time zone, no problem. But I'm wondering whether this will get the same result when I deploy the skill. That is, does the Date() function on the actual Service convert to local time from UTC? If it does, then I will need some way of determining in my code whether I am in the Service Simulator or the actual Service, and converting to New York time in my accordingly.
Thank you.
From the documentation for Date
If no arguments are provided, the constructor creates a JavaScript Date object for the current date and time according to system settings.
So depending on the system settings the timezones can be different.
To overcome this you can use UTC date everywhere and then simply convert the timezone where needed.
// date with some timezone depending on system
let date = new Date();
// date in UTC
let utcDate = new Date(date.getUTCFullYear(), date.getUTCMonth(), date.getUTCDate(), date.getUTCHours(), date.getUTCMinutes(), date.getUTCSeconds());
Note: utcDate will still be in the system timezone, but the actual value it holds will represent the correct date and time in UTC.
I have configured jobs with node-cron and yeah I love this node module to schedule job in node.
Here I have requirement of sending push notification to users which are located in different timezone.I want to send notification to them on specific time.
Let's say I am sending notification at 9 PM so in all listed timezone cron job will trigger at 9 PM.
var CronJob = require('cron').CronJob;
var job = new CronJob('00 30 11 * * 1-5', function() {
/*
* Runs every weekday (Monday through Friday)
* at 11:30:00 AM. It does not run on Saturday
* or Sunday.
*/
}, function () {
/* This function is executed when the job stops */
},
true, /* Start the job right now */
timeZone /* Time zone of this job. */
);
I know all this and I am doing same for one timezone as mentioned in there doc.
timeZone - [OPTIONAL] - Specify the timezone for the execution. This
will modify the actual time relative to your timezone.
But Can I specify multiple timezone here in timezone attribute?
If somebody aware of some other node module can achieve this then let me know?
NOTE : I already know I can configured multiple configuration here for each timezone but what if there are dynamic list.
I don't know of a way to send a list of timezones to the CRON job but you could change the logic in the method that runs inside the cron job.
You could do this :
run the job every half hour
if it's a day you want it to run on
select users where (convert current GMT time to user timezone - if the db can do this) > 11:30 AM in their timezone && hasn't sent a notification yet
send notifications to the returned users.
You might have already gone this route ... just throwing in my 2c
HTH
I have retrieved Tasks from my Gmail account using OAuth 2.0 Dot Net Google client library (https://developers.google.com/api-client-library/dotnet/apis/tasks/v1). When I save any of these tasks to my exchange account using Microsoft.Exchange.WebServices Dot Net library, the date of Task is adjusted automatically, although the time zone of Gmail account and exchange account are same i.e. Central Time (US & Canada). I want to prevent this automatically adjustment in Task date.
Can any one help?
Make sure you set the time zone on the ExchangeService object to the user's time zone. https://msdn.microsoft.com/EN-US/library/office/dn789029(v=exchg.150).aspx
I have solved the problem by using Calendar time zone. Basically, Google Calendar has time zone information. I retrieved time zone information from primary calendar and then before saving Task to Exchange account, I converted due date to UTC with following C# code
if (task.Due.Value.Kind == DateTimeKind.Local)
{
dueDateUTC = task.Due.Value.ToUniversalTime();
unspecifiedKindDate = new DateTime(dueDateUTC.Year, dueDateUTC.Month, dueDateUTC.Day);
dueDateUTC = TimeZoneInfo.ConvertTime(unspecifiedKindDate, Utility.OlsonTimeZoneToTimeZoneInfo(timezone), TimeZoneInfo.Utc);
}
This code first of all find out that whether Task due date is in local time zone or not. If it is in local time zone then due date is converted into UTC. After converting into UTC, a unspecified kind datetime object is created through following code
unspecifiedKindDate = new DateTime(dueDateUTC.Year, dueDateUTC.Month, dueDateUTC.Day);
This unspecified kind datetime is then again converted to UTC with the help of following code
dueDateUTC = TimeZoneInfo.ConvertTime(unspecifiedKindDate, Utility.OlsonTimeZoneToTimeZoneInfo(timezone), TimeZoneInfo.Utc);
Now this "dueDateUTC" object is used to save Task information into Exchange account. On saving Task, Exchange server automatically converts dueDateUTC to mailbox time zone and this was desired. :)
I have a Windows Service that runs on my
Texas origin Server Central Time.
This will check for all active reminders and compares the reminder time that user wants and send out reminder if it matches with user required time.
Scenarios
User is from EST
User set up a reminder for *1:25 PM * using UI via my website
On submit, my C# business logic converts this time to UTC before storing in my database. That will become '18:25:00'
My Business logic will pull all Active reminders from DB
And checks for reminder time if current UTC time and Reminder setup time diffrence is less then 5 mins, then it will send notification to that customer.
this is how my logic written
DateTime CurrentDate = DateTime.Now.ToUniversalTime();
TimeSpan currentTime = DateTime.Now.ToUniversalTime().TimeOfDay;
if (Reminder.DailyReminders.Any(x => currentTime.Subtract(x.ReminderTime).TotalMinutes < 5
&& currentTime.Subtract(x.ReminderTime).TotalMinutes > 0))
{
if (Reminder.ReminderMedhodID.Equals(1))
_email.ComposeEmail(Reminder);
}
My Problem is
*currentTime* is always 1 hour behind to user requested reminder time SO my reminders are going out 1 hour late.
Note : currentTime is from below
TimeSpan currentTime = DateTime.Now.ToUniversalTime().TimeOfDay;
I am not sure if this is the best way to handle this requirement. considering this is one of the way, can any on help how to fix this issue?
Thanks to peter's answer
Can any one help me how to take user input time with Daylight consideration
This what i have so far
public TimeSpan ConvertToUTCTime(string dateStr)
{
DateTime localDateTime = DateTime.Parse(dateStr); // Local .NET timeZone.
DateTime utcDateTime = localDateTime.ToUniversalTime();
string clTimeZoneKey = TimeZone.CurrentTimeZone.StandardName;
TimeZoneInfo clTimeZone = TimeZoneInfo.FindSystemTimeZoneById(clTimeZoneKey);
DateTime clDateTime = TimeZoneInfo.ConvertTimeFromUtc(utcDateTime, clTimeZone);
if (clTimeZone.IsDaylightSavingTime(localDateTime))
{
// Get DayLight local time in UTC
// Yet to be implemented
}
return clDateTime.TimeOfDay;
}
I got this worked using this
http://msdn.microsoft.com/en-us/library/system.globalization.daylighttime.aspx
Ummm...we are currently using Daylight Saving Time in most of the U.S. (though there are some portions of Indiana that did/do use EST?) Since EDT is one hour ahead of EST, your logic is correct. It is the input (EST) that is incorrect.