Schedule are not getting adjusted based on their time zone
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-10-2024 12:00 AM
I am a Europe/Dublin user created a schedule for 2024-05-16 14:00:00 to 2024-05-16 16:00:00 when impersonate as IST user i dont see any difference the date remains the same 2024-05-16 14:00:00 to 2024-05-16 16:00:00
so whatt i understand is GMT is getting changed instead of display value
But in change request form when iam in Europe/Dublin planned start is 2024-05-16 14:00:00 to 2024-05-16 16:00:00 when i impersonate the display value is getting change and the GMT remains common for all timezones
why is this behaviour?
when iam checking my planned start date and planned end date against the blackout schedules through scripting
how can i handle this timezone convertion
example script:
// Script to check blackout schedule
// Get user timezone - just to show the difference in outputs
var userTimeZone = gs.getSession().getTimeZone();
gs.info('User Timezone: ' + userTimeZone);
// Retrieve change request dates
var cor = new GlideRecord('change_request');
cor.addQuery('sys_id', 'd7312046978e0210b793938de053af76');
cor.query();
if (cor.next()) {
var startdateofchgci = cor.start_date;
var enddataeofchgci = cor.end_date;
gs.info('Start Date: ' + startdateofchgci);
gs.info('End Date: ' + enddataeofchgci);
}
// Retrieve blackout schedule
var scheduleEntryGRsoft = new GlideRecord('cmn_schedule_span');
scheduleEntryGRsoft.addQuery('schedule', '83cd9a930a0a2c3e6d4957fe9651c24d');
scheduleEntryGRsoft.query();
if (scheduleEntryGRsoft.next()) {
var recurrencerule = scheduleEntryGRsoft.schedule;
var schedule = new GlideSchedule(recurrencerule);
schedule.setTimeZone('Europe/Dublin');
// Convert dates to GlideDateTime objects
var gdt_start = new GlideDateTime(startdateofchgci);
var gdt_end = new GlideDateTime(enddataeofchgci);
// Calculate duration
var dur = schedule.duration(gdt_start, gdt_end);
var schedule_time = dur.getNumericValue() / 1000;
// Check if dates are within schedule
if (schedule.isInSchedule(gdt_start) || schedule.isInSchedule(gdt_end) || schedule_time > 0) {
gs.info('Found in blackout schedule');
} else {
gs.info('Not found in blackout schedule');
}
}