Skip to content

Commit be1d271

Browse files
Replace TZ4Net by NodaTime. (#811)
* Replace TZ4Net by NodaTime. * Fix TZ4Net.dll path. * Mark interfaces that utilize the NZ4Net OlsonTimezone class as obsolete. * Fix error: Invalid DateTime.Kind for Instant.FromDateTimeUtcParameter name: dateTime
1 parent 2b74c61 commit be1d271

File tree

12 files changed

+345
-21
lines changed

12 files changed

+345
-21
lines changed

dotnet/src/dotnetcore/GxClasses/GxClasses.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<PropertyGroup>
44
<TargetFrameworks>net6.0</TargetFrameworks>
55
<OutputType>Library</OutputType>
6-
<DefineConstants>NETCORE</DefineConstants>
6+
<DefineConstants>NETCORE;NODATIME</DefineConstants>
77
<PackageTags>Data Access</PackageTags>
88
<PackageId>GeneXus.Classes.Core</PackageId>
99
<EnableUnsafeBinaryFormatterSerialization>true</EnableUnsafeBinaryFormatterSerialization>
@@ -159,6 +159,7 @@
159159
<PackageReference Include="MySqlConnector" Version="2.2.3" />
160160
<PackageReference Include="NetTopologySuite" Version="2.0.0" />
161161
<PackageReference Include="NetTopologySuite.Core" Version="1.15.3" />
162+
<PackageReference Include="NodaTime" Version="3.1.9" />
162163
<PackageReference Include="Novell.Directory.Ldap.NETStandard" Version="3.3.1" />
163164
<PackageReference Include="Npgsql" Version="3.2.7" />
164165
<PackageReference Include="Sandwych.GeographicLib" Version="1.49.3" />

dotnet/src/dotnetframework/GxClasses/Core/GXApplication.cs

Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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>>();

dotnet/src/dotnetframework/GxClasses/Core/GXUtils.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ public static bool Val(string valString)
8282

8383
public class TimeZoneUtil
8484
{
85+
[Obsolete("GetInstanceFromWin32Id is deprecated.", false)]
8586
public static OlsonTimeZone GetInstanceFromWin32Id(string sTZ)
8687
{
8788
lock (OlsonTimeZone.SyncRoot)
@@ -96,7 +97,7 @@ public static OlsonTimeZone GetInstanceFromWin32Id(string sTZ)
9697
}
9798
}
9899
}
99-
100+
[Obsolete("GetInstanceFromOlsonName is deprecated.", false)]
100101
public static OlsonTimeZone GetInstanceFromOlsonName(string sTZ)
101102
{
102103
lock (OlsonTimeZone.SyncRoot)

0 commit comments

Comments
 (0)