Hi Dojo,
How I can display a datetime field of a DOM object in local time in a LCA, but display the date and time as separate columns
I tried using column manipulations with regex and custom operators, which works, but the issue is that since the initial ad hoc source is subscribed to real-time updates, the new values take too long to update, which is also undesirable.
Not sure what other possible options I should try here; any recommendations would be appreciated.
Thank you!
UPDATE
this is showing the correct time using the column manipulations but losing the ability of real time updates. is showing the local time which is the idea.
Now, this is by using the displayValue and is showing the incorrect time, using the server time
Hi Carlos,
Both custom operators and column manipulation operators indeed do not support real-time updates yet and will only update every 30 seconds if an update was detected.
Real-time updates for these operators will be supported in the future.
For now, the solution is to integrate the datetime transformation into the initial Ad Hoc data source.
Note: if the ad hoc data source is also to be reused in places where no such datetime transformation is necessary, we would recommend to create a separate ad hoc data source for that in the same library that can derive from the original and add this specific behavior.
Hi Carlos,
What type of columns are you using to return these values?
If you’re using GQIDateTimeColumns the actual Value in the GQICell will always be a DateTime in UTC time (enforced) but GQI should automatically assign a DisplayValue with the local time unless you manually specified something else.
If you’re using GQIStringColumns then you manually need to manage how the time is displayed, but there is no way to know the users local time at that point.
Feel free to share a code snippet to clarify what you tried so far.
here are my columns, i’m using DateTime columns
public override GQIColumn[] GetColumns()
{
return new GQIColumn[]
{
new GQIDateTimeColumn(“Start Date”),
new GQIDateTimeColumn(“Start Time”),
new GQIDateTimeColumn(“End Time”),
new GQIDateTimeColumn(“End Date”),
};
}
and here is what im doing with the Datetimes
var startEventDateTime = startDatetime.Value.ToUniversalTime();
var endEventDateTime = endDatetime.Value.ToUniversalTime();
var row = new[]
{
new GQICell {Value = startEventDateTime, DisplayValue = startEventDateTime.ToString(“d”) },
new GQICell {Value = startEventDateTime, DisplayValue = startEventDateTime.ToString(“hh:mm tt”)},
new GQICell {Value = endEventDateTime, DisplayValue = endEventDateTime.ToString(“hh:mm tt”) },
new GQICell {Value = endEventDateTime, DisplayValue = endEventDateTime.ToString(“d”)},
};
the problem is that by doing that is changing the times and not showing the local time.
I will attach screenshots to the original question so I can show better the idea.
I see. So if you’re specifying the DisplayValue like this, you take full control over which time zone is used.
The eventDateTime variables are all in UTC, so using ToString directly will format them in UTC as well.
In order to use a different time zone, you’ll need a TimeZoneInfo object representing that time zone (see: https://learn.microsoft.com/en-us/dotnet/standard/datetime/instantiate-time-zone-info).
Then you can convert your eventDateTimes like so:
var localEventTime = TimeZoneInfo.ConvertTimeFromUtc(eventDateTime, timeZoneInfo);
And then use localEventTime.ToString(“…”);
The limitation of this approach is that there is no easy way yet to know the actual local client time zone at this point. So either you have to hardcode the time zone or select it using an input argument.
I’m trying that on my end but haven’t accomplished it yet. Could you give me some directions on how to do it? What I’ve tried so far hasn’t worked, as it still returns the server time instead of the user’s local time.