@@ -42,6 +42,8 @@ namespace GeneXus.Application
4242#if NETCORE
4343 using Microsoft . AspNetCore . Http . Features ;
4444#endif
45+ using NodaTime ;
46+ using NodaTime . TimeZones ;
4547 using System . Threading ;
4648 using System . Security . Claims ;
4749 using System . Security ;
@@ -68,6 +70,7 @@ public interface IGxContext
6870 void DisableSpaRequest ( ) ;
6971 String AjaxCmpContent { get ; set ; }
7072 bool isCloseCommand { get ; }
73+ [ Obsolete ( "GetOlsonTimeZone is deprecated. Use GetTimeZone() instead" , false ) ]
7174 OlsonTimeZone GetOlsonTimeZone ( ) ;
7275 String GetTimeZone ( ) ;
7376 Boolean SetTimeZone ( String sTZ ) ;
@@ -392,6 +395,8 @@ public List<string[]> userStyleSheetFiles {
392395 private bool _isSumbited ;
393396 [ NonSerialized ]
394397 private OlsonTimeZone _currentTimeZone ;
398+ [ NonSerialized ]
399+ private String _currentTimeZoneId ;
395400
396401 [ NonSerialized ]
397402 MessageQueueTransaction _mqTransaction ;
@@ -3503,7 +3508,7 @@ public string GetLanguageProperty(String propName)
35033508 }
35043509
35053510 internal static string GX_REQUEST_TIMEZONE = "GxTZOffset" ;
3506-
3511+ [ Obsolete ( "ClientTimeZone is deprecated. Use GxContext.GetTimeZone() instead" , false ) ]
35073512 public OlsonTimeZone ClientTimeZone
35083513 {
35093514 get
@@ -3541,7 +3546,37 @@ public OlsonTimeZone ClientTimeZone
35413546 return _currentTimeZone ;
35423547 }
35433548 }
3549+ internal string ClientTimeZoneId
3550+ {
3551+ get
3552+ {
3553+ if ( _currentTimeZoneId != null )
3554+ return _currentTimeZoneId ;
3555+ string sTZ = _HttpContext == null ? "" : ( string ) _HttpContext . Request . Headers [ GX_REQUEST_TIMEZONE ] ;
3556+ GXLogging . DebugSanitized ( log , "ClientTimeZone GX_REQUEST_TIMEZONE header:" , sTZ ) ;
3557+ if ( String . IsNullOrEmpty ( sTZ ) )
3558+ {
3559+ sTZ = ( string ) GetCookie ( GX_REQUEST_TIMEZONE ) ;
3560+ GXLogging . Debug ( log , "ClientTimeZone GX_REQUEST_TIMEZONE cookie:" , sTZ ) ;
3561+ }
3562+ try
3563+ {
3564+ _currentTimeZoneId = String . IsNullOrEmpty ( sTZ ) ? DateTimeZoneProviders . Tzdb . GetSystemDefault ( ) . Id : sTZ ;
3565+ }
3566+ catch ( Exception e1 )
3567+ {
3568+ GXLogging . Warn ( log , "ClientTimeZone GetInstanceFromWin32Id error" , e1 ) ;
3569+ Preferences . StorageTimeZonePty storagePty = Preferences . getStorageTimezonePty ( ) ;
3570+ if ( storagePty == Preferences . StorageTimeZonePty . Undefined )
3571+ _currentTimeZoneId = null ;
3572+ else
3573+ throw e1 ;
3574+ }
35443575
3576+ return _currentTimeZoneId ;
3577+ }
3578+ }
3579+ [ Obsolete ( "GetOlsonTimeZone is deprecated. Use GetTimeZone() instead" , false ) ]
35453580 public OlsonTimeZone GetOlsonTimeZone ( )
35463581 {
35473582 return TimeZoneUtil . GetInstanceFromOlsonName ( GetTimeZone ( ) ) ;
@@ -3554,15 +3589,45 @@ public String GetTimeZone()
35543589 {
35553590 SetTimeZone ( sTZ ) ;
35563591 }
3592+
3593+ #if NODATIME
3594+ if ( _currentTimeZoneId == null )
3595+ _currentTimeZoneId = ClientTimeZoneId ;
3596+ if ( _currentTimeZoneId == null )
3597+ _currentTimeZoneId = DateTimeZoneProviders . Tzdb . GetSystemDefault ( ) . Id ;
3598+ return _currentTimeZoneId ;
3599+ #else
35573600 if ( _currentTimeZone == null )
35583601 _currentTimeZone = ClientTimeZone ;
35593602 return _currentTimeZone == null ? TimeZoneUtil . GetInstanceFromWin32Id ( TimeZoneInfo . Local . Id ) . Name : _currentTimeZone . Name ;
3603+ #endif
35603604 }
35613605
35623606 public Boolean SetTimeZone ( String sTZ )
35633607 {
35643608 sTZ = StringUtil . RTrim ( sTZ ) ;
35653609 Boolean ret = false ;
3610+ #if NODATIME
3611+ string tzId ;
3612+ try
3613+ {
3614+ if ( DateTimeZoneProviders . Tzdb [ sTZ ] != null )
3615+ {
3616+ tzId = DateTimeZoneProviders . Tzdb [ sTZ ] . Id ;
3617+ }
3618+ else
3619+ {
3620+ tzId = DateTimeZoneProviders . Tzdb . GetSystemDefault ( ) . Id ;
3621+ }
3622+ ret = true ;
3623+ }
3624+ catch ( Exception )
3625+ {
3626+ tzId = DateTimeZoneProviders . Tzdb . GetSystemDefault ( ) . Id ;
3627+ }
3628+ SetProperty ( "GXTimezone" , tzId ) ;
3629+ _currentTimeZoneId = tzId ;
3630+ #else
35663631 try
35673632 {
35683633 _currentTimeZone = TimeZoneUtil . GetInstanceFromOlsonName ( sTZ ) ;
@@ -3581,6 +3646,7 @@ public Boolean SetTimeZone(String sTZ)
35813646 }
35823647 }
35833648 SetProperty ( "GXTimezone" , _currentTimeZone . Name ) ;
3649+ #endif
35843650 return ret ;
35853651 }
35863652 private static ConcurrentDictionary < string , HashSet < string > > m_imagesDensity = new ConcurrentDictionary < string , HashSet < string > > ( ) ;
0 commit comments