Skip to content

Fix Datetime localization issue when handling serverdate in PostgreSQL #1158

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion dotnet/src/dotnetframework/GxClasses/Core/GXUtilsCommon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3277,7 +3277,16 @@ public static DateTime ServerDate(IGxContext context, IDataStoreProvider dataSto
{
if (dataStore == null)
return ServerDate(context, new DataStoreHelperBase().getDataStoreName());
return ResetTime(dataStore.serverNow());
return ResetTimeAndKind(dataStore.serverNow());
}

private static DateTime ResetTimeAndKind(DateTime dateTime)
{
if (dateTime.Kind != DateTimeKind.Unspecified)
{
return new DateTime(dateTime.Year, dateTime.Month, dateTime.Day, 0, 0, 0, 0);
}
else return ResetTime(dateTime);
}
#if !NETCORE
[Obsolete("ServerTime with string dataSource is deprecated, use ServerTime(IGxContext context, Data.NTier.IDataStoreProvider dataStore) instead", false)]
Expand Down
5 changes: 5 additions & 0 deletions dotnet/src/dotnetframework/GxClasses/Data/GXDataCommon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1169,6 +1169,11 @@ public virtual string AfterCreateCommand(string stmt, GxParameterCollection parm
{
return stmt;
}

internal virtual DateTime NormalizeDbmsDateTime(DateTime d)
{
return d;
}
}

public class DbDataAdapterElem
Expand Down
5 changes: 3 additions & 2 deletions dotnet/src/dotnetframework/GxClasses/Data/GXDataNTier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -752,10 +752,11 @@ public DateTime serverNow()
public DateTime serverNowIn(bool hasMilliseconds )
{
string stmt = "";
GxDataRecord gxDataRecord = (GxDataRecord)_ds.Db;
if (hasMilliseconds)
stmt = ((GxDataRecord)_ds.Db).GetServerDateTimeStmtMs(_ds.Connection);
stmt = gxDataRecord.GetServerDateTimeStmtMs(_ds.Connection);
else
stmt = ((GxDataRecord)_ds.Db).GetServerDateTimeStmt(_ds.Connection);
stmt = gxDataRecord.GetServerDateTimeStmt(_ds.Connection);

if (string.IsNullOrEmpty(stmt))
{
Expand Down
8 changes: 8 additions & 0 deletions dotnet/src/dotnetframework/GxClasses/Data/GXDataPostgreSQL.cs
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,14 @@ public override string ConcatOp(int pos)
{
return ConcatOpValues[pos];
}
internal override DateTime NormalizeDbmsDateTime(DateTime d)
{
if (d.Kind != DateTimeKind.Unspecified)
{
d = new DateTime(d.Year, d.Month, d.Day, d.Hour, d.Minute, d.Second, d.Millisecond);
}
return d;
}
}
sealed internal class PostgresqlConnectionWrapper : GxAbstractConnectionWrapper
{
Expand Down
Loading