Skip to main content
Kinetic Community

Date searching - avoiding timezone issues

Many Remedy environments are run serving clients that connect in from different timezones and use different Locale formats. Kinetic Request handles dates quite well by deriving the clients(browsers) locale and timezone then displays the adjusting dates correctly. However, if you develop a query against a remedy server that will have a different timezone to the clients browser, then we can have an issue. The best solution I have found is to use the actual time number value in the query instead of a String formatted date. If the string format does not match up correctly then the result will not work as desired. So instead of a qualification looking like 'Date' >= "2001-11-24' we would use 'Date >=1321880400 This solution gives you a javascript function that will convert a String date, returned from a Kinetic Date field in a consistant format of YYYY-MM-DD (eg. 2001-11-22) into an integer value that can be applied to a qualification.

Usage

Below is a simple javascript function called dateToARSNumber(aDateStr).

The aDateStr parameter can be passed in by calling the KD.utils.Action.getQuestionValue("My Date Question").

This function will convert the date question value to a number date. The code will take into accoount the clients GMT offset and add or substract to give you a GMT 0 date value. The GMT 0 date is what remedy actually stores for its Datetime field.

 

// Convert the date string(YYYY-MM-YY) to an integer which then will work no matter what timezone/locale etc is running
// Work for the Remedy Datetime field
// This function will apply the users timezone offset, thus allowing the users context/timezone to be applied.
// We do this because we ensure the users date use, is relative to them, knowing that Remedy stores the GMT 0 version.
// If a user from Australia (GMT +11) stores a date of 1st November then a user from Minnesota (GMT-6) will need to see the date
// as the 31st October.
function dateToARSDatetimeNumber(aDateStr) {
      var parts = aDateStr.split("-");
      var Y = parseInt(parts[0]);
      var M = parseInt(parts[1]);
      var D = parseInt(parts[2]);

   var dt = new Date(0);
   return ((Date.UTC(Y,M-1,D)/1000)-39600)+(dt.getTimezoneOffset()*60);
}