I'm curious how others deal with the embedded vRO with vRA since the appliance is set to etc/utc. The date object in vRO doesn't seem to support this code:
you can try momentjs
var moment = System.getModule("com.test.momentjs").getMomentInstance();
var momentTZ = System.getModule("com.test.momentjs").getMomentTZ(moment);
var d = moment("2021-09-23T23:13:58.166554Z");
System.log(d.format());
System.log(d.tz("America/Los_Angeles").format("L, LTS"));
---
[2022-02-10 13:19:45.294] [I] 2021-09-23T23:13:58+00:00
[2022-02-10 13:19:45.301] [I] 09/23/2021, 4:13:58 PM
you can try momentjs
var moment = System.getModule("com.test.momentjs").getMomentInstance();
var momentTZ = System.getModule("com.test.momentjs").getMomentTZ(moment);
var d = moment("2021-09-23T23:13:58.166554Z");
System.log(d.format());
System.log(d.tz("America/Los_Angeles").format("L, LTS"));
---
[2022-02-10 13:19:45.294] [I] 2021-09-23T23:13:58+00:00
[2022-02-10 13:19:45.301] [I] 09/23/2021, 4:13:58 PM
Wow... I find it a bit disappointing that this may be the answer. Thanks for pointing me to this article though! Considering VMware has products where they want etc/utc set as the appliance time zone you'd think they would have a solution for generating dates in a local or other time zone easily. Especially since it seems this is easily done with basic javascript but their implementation isn't allowing for it? Maybe I am missing something since I am not in anyway an expert in javascript.
@xian_ do you have this working? I tried downloading the package but it downloads corrupted for me at least when I try to import to vRA 7.6 or vRA 8.6.2. If so can you repost a package in this thread?
Unfortunately I do not have mosestef's package, I simply recreated the actions based on @eoinbyrne 's instructions.
I attach my package that I got working.
Oh awesome... for some reason I thought the instructions were just on using his package. Thanks for sharing. I also came up with a work around calling the linux date command line using the epoch of the date but much prefer to keep it all in vRO and not have to use an external host.
TZ=":America/Los_Angeles" date -d @1644521536 +'%xT%T' will output in the specified timezone in whatever way you want to format it. I just formatted it in something I could easily parse similar to other date strings I've seen. That commands output looks like this "02/10/2022T11:32:16"
I'm now realizing what I thought was standard javascript I mentioned earlier was actually an example from luxon https://moment.github.io/luxon/#/?id=luxon . I wonder if luxon can be pulled into vRO like momentsjs was? Sounds like momentsjs is deprecated but this all works great for my needs. This should really be better supported in vRO though they should have some sort of equivalent. Still hoping I'm just missing something.
The benefit of deprecated JS implementations are that they are more likely to run on vRO's old ES5 JS engine. Luxon may run but one has to try it...
Another approach is using vRO polyglot capabilities and run JS code with the NodeJS engine. I found these FaaS actions starting slower as they deployed into containers.
vRO can parse your date string with:
d = System.getDateFromFormat(stringInput.substr(0,23), "yyyy-MM-dd'T'HH:mm:ss.SSS");
but I found no TZ support for displaying it other than the default timezone.
The moments.js is working great so I'll stick with that for now! Great idea on FaaS. I forgot that was now an option. Maybe at some point in the future I'll try that.