Skip to content
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
21 changes: 21 additions & 0 deletions dotnet/src/dotnetframework/GxClasses/Core/GXUtilsCommon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2297,6 +2297,20 @@ static string FormatEmptyDate(string pic)
}
return emptyDT.ToString();
}
static string FormatEmptyJsonDate(string pic)
{
StringBuilder emptyDT = new StringBuilder(pic);
emptyDT.Replace('d', '0');
emptyDT.Replace('M', '0');
emptyDT.Replace('y', '0');

emptyDT.Replace('m', '0');
emptyDT.Replace('s', '0');
emptyDT.Replace('f', '0');
emptyDT.Replace('h', '0');
emptyDT.Replace('H', '0');
return emptyDT.ToString();
}
string TimeFormatFromSDT(String S, String TSep, bool allowsOneDigitTime)
{
int pos1, pos2, pos3, tSize, ampmFmt;
Expand Down Expand Up @@ -2551,6 +2565,13 @@ public static string DToC2(DateTime dt)
else
return dt.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture);
}
internal static string DToC2(DateTime dt, string format)
{
if (dt == nullDate)
return FormatEmptyJsonDate(format);
else
return dt.ToString(format, CultureInfo.InvariantCulture);
}
public static DateTime CToD2(string value)
{
if (isNullJsonDate(value))
Expand Down
30 changes: 15 additions & 15 deletions dotnet/src/dotnetframework/GxClasses/Services/GxRestWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -745,13 +745,7 @@ protected Task Serialize(Dictionary<string, object> parameters, Dictionary<strin
object strVal = null;
if (parameters[key].GetType() == typeof(DateTime))
{
DateTime udt = ((DateTime)parameters[key]).ToUniversalTime();
if (fmtParameters.ContainsKey(key) && !String.IsNullOrEmpty(fmtParameters[key]))
{
strVal = udt.ToString(fmtParameters[key], CultureInfo.InvariantCulture);
}
else
strVal = udt;
strVal = SerializeDateTime((DateTime)parameters[key], key, fmtParameters);
}
else
strVal = parameters[key];
Expand All @@ -775,14 +769,8 @@ protected Task Serialize(Dictionary<string, object> parameters, Dictionary<strin
}
if (kv.Value.GetType() == typeof(DateTime))
{
DateTime udt = ((DateTime)kv.Value).ToUniversalTime();
if (fmtParameters.ContainsKey(kv.Key) && !String.IsNullOrEmpty(fmtParameters[kv.Key]))
{
object strVal = udt.ToString(fmtParameters[kv.Key], CultureInfo.InvariantCulture);
serializablePars.Add(strKey, strVal);
}
else
serializablePars.Add(strKey, udt);
object strVal = SerializeDateTime((DateTime)kv.Value, kv.Key, fmtParameters);
serializablePars.Add(strKey, strVal);
}
else
serializablePars.Add(strKey, kv.Value);
Expand All @@ -792,6 +780,18 @@ protected Task Serialize(Dictionary<string, object> parameters, Dictionary<strin
_httpContext.Response.Write(json); //Use intermediate StringWriter in order to avoid chunked response
return Task.CompletedTask;
}

private object SerializeDateTime(DateTime dt, string key, Dictionary<string, string> fmtParameters)
{
DateTime udt = (dt==DateTimeUtil.NullDate()) ? dt: dt.ToUniversalTime();

if (fmtParameters.ContainsKey(key) && !String.IsNullOrEmpty(fmtParameters[key]))
{
return DateTimeUtil.DToC2(udt, fmtParameters[key]);
}
return udt;
}

private bool PrimitiveType(Type type)
{
return type.IsPrimitive || type == typeof(string) || type.IsValueType;
Expand Down