Timezone Issue to be fixed for changes in SNC

nikhithanik
Tera Contributor

We have users with multiple locations like China ,Hamburg, India etc., when user table is updated for the users with their respective time zone and my system default is US/Eastern.

Issue is:

The users preference setting is changing to system default as US/Eastern rather than taking user record preference. When updating in Preference-Display to their time zone.

 

Can anyone suggest how we can resolve this?

6 REPLIES 6

@Kieran Anson 

I was facing an issue in DurationCalculator API and calcScheduleDuration function and it seems when I use this script and the schedule is Victoria which has holiday the script doesn't work fine keeping UTC in calculation as function 2nd parameter.

Did you ever face this?

your thoughts on this

We observed this in our timesheet portal and it gives incorrect hours and always give 1 hour less than actual.

we expect 40 and it gives us 39, the schedule for holiday is for entire 24 hours

ServiceNow case team informed us to use UTC in calculations which we are already doing but it behaves weird when holiday is present in DST period

 var weekStartDate = new GlideDateTime(timeSheetStartDate); //week start date
    gs.info('week start date' + weekStartDate);
    var weekEndDate = new GlideDateTime(timeSheetStartDate);
    weekEndDate.addDaysUTC(6); //week end date
    gs.info('week end date' + weekEndDate);
    var durationCalculator = new DurationCalculator();
    durationCalculator.setSchedule(userSchedule,'UTC');
    var workDays = 0;
    if (weekEndDate > weekStartDate) {
        workDays = durationCalculator.calcScheduleDuration(weekStartDate, weekEndDate);
    } else {
        workDays = durationCalculator.calcScheduleDuration(weekEndDate, weekStartDate);
    }
    gs.info("workDays" + workDays);

 

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Hi,

If you switch to calcRelativeDueDate, it accounts for daylight savings time which is adding the 1-hour you're seeing

 

var VICTORIA_SCHEDULE = '5c2861ff83c922105e43c4a6feaad3c3';

var weekStart = new GlideDateTime('27/04/2025')

var durationCalculator = new DurationCalculator();
durationCalculator.setSchedule(VICTORIA_SCHEDULE,'UTC');
durationCalculator.calcRelativeDueDate(weekStart, 5)
durationCalculator.getSeconds()