Applied Dimensionality

Display time in different timezones in Planning Analytics

Posted at — Oct 12, 2022
Display time in different timezones in Planning Analytics

Quick write-up on how to display time in different timezones in Planning Analytics while we’re waiting for a timezone aware format to be added.

We end up using a cube to display messages to end users in every project, something as simple as:

Timestamp Log Level Message
2020/10/13 13:25:15 info Starting OpEx allocation
2020/10/13 13:25:23 warn Cost centre ABC is not allocated 100%, please update profile

which is populated by a bog standard logMessage TI that you call to alert to interesting conditions. The goal is to expose configuration / mapping / input issues.

The time part of this is interesting whenever you have:

Here’s what I’m doing lately:

['User timestamp'] = N: 
	['Server timestamp'] +
      # offset of timezone by user
      DB('SYS User Parameter', TM1User(), 'Timezone offset, hours' ) \ 24;
# Update daily offset of hours to user timezones to cater for daylight savings
sLocale = CellGetS( 'Sys Parameter', 'Locale', 'text'  );
sServerTimezone =CellGetS( 'Sys Parameter', 'Server timezone', 'text'  );

nServerDateFormatter = NewDateFormatter(sLocale, sServerTimezone, 'serial', 'full', 'datetime');
sDateFormat = 'yyyy-MM-dd HH:mm:ss';
nNow = Now;
sServerTimeStamp = FormatDate(nNow, sDateFormat, nServerDateFormatter);

CellPutS('NO', '}CubeProperties', 'Sys Timezone', 'Logging');

CubeClearData( 'Sys Timezone' );

i = 1;
while (i<= DimSiz('Sys Timezone') );
    sTimezone = DimNm('Sys Timezone', i );
    nDateFormatter = NewDateFormatter(sLocale, sTimezone, 'serial', 'full', 'datetime');
    nLocalTime = ParseDate( sServerTimeStamp, sDateFormat, nDateFormatter );
    nTimeDifferenceHours =  ( nNow - nLocalTime  )  * 24;
    CellPutN(nTimeDifferenceHours, 'Sys Timezone',sTimezone, 'Offset from server, hours');
    i = i + 1;
end;
comments powered by Disqus