Quintiq file version 2.0
#parent: #root
Method PTF_ConvertDateTimeStringToSelectedClientTimezone (
  String datetimeString
) as String id:Method_LibPTF_pnlTestController_PTF_ConvertDateTimeStringToSelectedClientTimezone
{
  #keys: '[131464.1.896623008]'
  Body:
  [*
    /* Convert a DateTime that was formatted into a String to another DateTime String based on selected timezone
    1. Append timezone offset into datetimeString
    2. Convert string in (1) to datetime (This will be the time as it is but with timezoe offset info)
    3. Convert datetime in (2) to string based on selected client timezone
    */
    
    // The "Z" indicates timezone offset is appended in the datatime. Example +0800
    timezoneOffsetMask               := "Z";                                                
    dateTimeFormatWithTimezoneOffset := this.PTF_GetPTFGlobalParameters().DefaultDateFormat() + timezoneOffsetMask;
    
    // 1. lblClientTimezoneOff stores timezone offset value, example: +0800
    datetimeStringWithTimeZoneOffset := datetimeString + lblClientTimezoneOffset.Text();
    
    // 2. Convert string in (1) to datetime (This will be the time as it is but with timezoe offset info)
    stringToDateTimeConverter := StringToDateTime::StandardConverter();
    stringToDateTimeConverter.SetCustomConversion();
    stringToDateTimeConverter.CustomFormatString( dateTimeFormatWithTimezoneOffset );
    
    dateTimeInCurrentTimezone := stringToDateTimeConverter.Convert( datetimeStringWithTimeZoneOffset );
    
    // 3. Convert datetime in current timezone to string based on selected client timezone
    dateTimeToStringConverter := DateTimeToString::UserConverter();
    dateTimeToStringConverter.SetCustomConversion();                                          
    dateTimeToStringConverter.CustomFormatString( dateTimeFormatWithTimezoneOffset );
    
    strDateTimeInSelectedTimezone := dateTimeToStringConverter.Convert( dateTimeInCurrentTimezone );
    
    // Just extract the date time part, ignore the timezone offset part
    startIndex             := 0;
    timezoneOffsetLength   := 5; 
    convertedDatTimeString := strDateTimeInSelectedTimezone.SubString( startIndex, strDateTimeInSelectedTimezone.Length() - timezoneOffsetLength );
    
    return convertedDatTimeString;
  *]
}
