Timezone Handling with Moment (moment-timezone.min.js)

Timezone Handling with Moment TZ.

  1. 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.

  1. Added custom code in both Premise and cloud instance.

  2. Saved, released & reloaded app.

  3. Result is:

     {
     name: "TypeError",
     message: "moment is not a function"
     }
    
  4. 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');

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.