This commit is contained in:
2021-02-05 18:19:26 +00:00
parent 8b072ac322
commit b784bb678c

View File

@@ -806,15 +806,12 @@ namespace AyaNova.DataList
System.DateTime dtData = DateTime.Parse(sValue).ToUniversalTime();//comes in UTC, parse converts it to local but touniversal puts it back in utc, weird but only thing that consistently work
//THis is because we don't want milliseconds (or seconds in some cases)
//to alter the value in any way, AyaNova resolution for time is seconds not milliseconds to allow for some sloppiness
//and After Time values should start at zero seconds to encompass that minute because users can't select seconds in the UI when filtering etc
//so no date is exact and we work around that with ranges that rule out milliseconds affecting query
//also this needs to work in conjunction with client filters for date ranges that provide a value one second before the range in question as START timestamp
//and exactly the end of range in question as END timestamp
string sDateValueWithMaxMilliseconds = PostgresDateFormat(MaxMilliseconds(dtData));
string sDateValueWithZeroMilliseconds = PostgresDateFormat(ZeroMilliseconds(dtData));
//Filter time resolution is in minutes only, you can't select seconds in a filter
//so the filter code below must construct a filter time
//that falls within the 0th second, 0th millisecond and 59th second and 999th millisecond of the specified time
//to ensure it matches the users selections
string sDateValueWithZeroSeconds = PostgresDateFormat(ZeroSeconds(dtData));
string sDateValueWithMaxSeconds = PostgresDateFormat(MaxSeconds(dtData));
@@ -833,34 +830,34 @@ namespace AyaNova.DataList
case DataListFilterComparisonOperator.GreaterThan:
sb.Append(">'");
sb.Append(sDateValueWithMaxMilliseconds);
sb.Append(sDateValueWithMaxSeconds);
sb.Append("'");
break;
case DataListFilterComparisonOperator.GreaterThanOrEqualTo:
sb.Append(">='");
sb.Append(sDateValueWithZeroMilliseconds);
sb.Append(sDateValueWithMaxSeconds);
sb.Append("'");
break;
case DataListFilterComparisonOperator.LessThan:
sb.Append("<'");
sb.Append(sDateValueWithZeroMilliseconds);
sb.Append(sDateValueWithMaxSeconds);
sb.Append("'");
break;
case DataListFilterComparisonOperator.LessThanOrEqualTo:
sb.Append("<='");
sb.Append(sDateValueWithMaxMilliseconds);
sb.Append(sDateValueWithMaxSeconds);
sb.Append("'");
break;
case DataListFilterComparisonOperator.NotEqual:
sb.Append("<'");
sb.Append(sDateValueWithZeroMilliseconds);
sb.Append(sDateValueWithMaxSeconds);
sb.Append("' OR ");
sb.Append(SqlColumnNameToFilter);
sb.Append(" ");
sb.Append(">'");
sb.Append(sDateValueWithMaxMilliseconds);
sb.Append(sDateValueWithMaxSeconds);
sb.Append("'");
break;
@@ -993,12 +990,12 @@ namespace AyaNova.DataList
{
sb.Append(">'");
sb.Append(PostgresDateFormat(MaxMilliseconds(dtAfter.ToUniversalTime())));
sb.Append(PostgresDateFormat(MaxSeconds(dtAfter.ToUniversalTime())));
sb.Append("' AND ");
sb.Append(sColumn);
sb.Append(" ");
sb.Append("<'");
sb.Append(PostgresDateFormat(ZeroMilliseconds(dtBefore.ToUniversalTime())));
sb.Append(PostgresDateFormat(ZeroSeconds(dtBefore.ToUniversalTime())));
sb.Append("'");
}
@@ -1009,22 +1006,14 @@ namespace AyaNova.DataList
return new DateTime(d.Year, d.Month, d.Day, d.Hour, d.Minute, 0, DateTimeKind.Utc);
}
private static DateTime ZeroMilliseconds(DateTime d)
{
if (d.Millisecond == 0) return d;
return new DateTime(d.Year, d.Month, d.Day, d.Hour, d.Minute, d.Second, DateTimeKind.Utc);
}
private static DateTime MaxSeconds(DateTime d)
{
return new DateTime(d.Year, d.Month, d.Day, d.Hour, d.Minute, 59, 999, DateTimeKind.Utc);
}
private static DateTime MaxMilliseconds(DateTime d)
{
if (d.Millisecond == 999) return d;
return new DateTime(d.Year, d.Month, d.Day, d.Hour, d.Minute, d.Second, 999, DateTimeKind.Utc);
}
/// <summary>
/// Postgres compatible date format