Timezone Handling with Moment TZ.
Reviewed docs: https://docs.uibakery.io/how-tos/connect-external-js-library#using-moment.js .
<script src="https://cdn.jsdelivr.net/npm/moment@2.29.4/moment.min.js></script>
<script src="https://cdn.jsdelivr.net/npm/moment-timezone@0.5.40/moment-timezone.min.js></script>
Then, implemented action with copied code.
Added custom code in both Premise and cloud instance.
Saved, released & reloaded app.
Result is:
{
name: "TypeError",
message: "moment is not a function"
}
Also attempted the latest from moment CDN by jsDelivr - A CDN for npm and GitHub & moment-timezone CDN by jsDelivr - A CDN for npm and GitHub
<script src="https://cdn.jsdelivr.net/npm/moment@2.30.1/moment.min.js"> </script>
<script src="https://cdn.jsdelivr.net/npm/moment-timezone@0.5.45/moment-timezone.min.js"></script>
Same result. Any advice?
Hi Kris,
Thanks for reaching out!
Weβre looking into it.
As a workaround, please use the code below:
var moment = await require('moment');
await require('moment-timezone');
const now = moment();
return now.tz('America/Los_Angeles').format('ha z');
Max
September 9, 2024, 12:01pm
3
I have tested around with different approaches, but it seems that the moment
object is not correctly extended with the methods from moment-timezone
.
But one thing to consider, is that moment.js
is a project from the previous decade, meaning it is rather outdated. So by now, most browser, sources online and even the team behind the project recommend using other methods.
In their own words (source ):
We now generally consider Moment to be a legacy project in maintenance mode. It is not dead , but it is indeed done .
In most cases, you should not choose Moment for new projects.
So it would be best to choose a different approach
Here you can find some recommended alternatives on the moment.js website.