I'm having trouble with dates, which are always a pain to deal with in code, especially when timezones are involved ;)
Here's the problem, I have a UTC date as a string, which I run through $core_v2_utility.ParseDate, that works fine with $core_v2_language.FormatAgoDate, but doesn't take timezone into account.
If I run the output from ParseDate through $core_v2_language.FormatDateAndTime telling it the TimeZoneId of the user, that doesn't do anything to the outputted date, and doesn't then work with FormatAgoDate. Built-in functions like AddDays don't work on the variable either, so it appears to be in a different DateTime format from what ParseDate outputs.
Here's the code I've been working with in the sandbox;
Current User datetime: $core_v2_utility.CurrentUserDate() <br>
User timezone: $core_v2_user.Accessing.TimeZoneId <br>
#set($lastRun = $core_v2_utility.ParseDate("01/10/2024 15:00:00.000"))
#set($lastRunFmt = $core_v2_language.FormatDateAndTime($lastRun))
#set($lastRunLocalised = $core_v2_language.FormatDateAndTime($lastRun, "%{ TimeZoneId = $core_v2_user.Accessing.TimeZoneId }"))
<b>Basic output</b><br>
$lastRun <br>
$lastRunFmt <br>
$lastRunLocalised <hr>
<b>Add 1 day</b><br>
Add 1 day: $lastRun.AddDays(1) <br>
Add 1 day: $lastRunFmt.AddDays(1) <br>
Add 1 day: $lastRunLocalised.AddDays(1) <hr>
<b>Ago</b><br>
Ago: $core_v2_language.FormatAgoDate($lastRun) <br>
Ago: $core_v2_language.FormatAgoDate($lastRunFmt) <br>
Ago: $core_v2_language.FormatAgoDate($lastRunLocalised) <br>
The output looks like this;
The DateTime object returned by core_v2_utility.ParseDate doesn't look to match the object that's returned by $core_v2_language.FormatDateAndTime, which isn't apparent in the documentation.
Am I missing something obvious?