Moment.js Time Zone isn't working

7 Comments

  • Bryan - Community Manager
    Comment actions Permalink

    Hi David,

    In the past, there have been conflicts with including moment.js within Zendesk Guide's implementation. While including moment.js doesn't seem to cause a problem anymore, as you found out, including moment-timezone-with-data.js (or one of the related libraries) does.

    I'm trying to find out if there are any workarounds to using this library. In the meantime, it does indeed look like there's an issue with including it. I'll post back here when I find out more.

    0
  • David Bjorgen
    Comment actions Permalink

    I created a workaround by loading the scripts from a CDN, like so:

    // Load moment.js remotely from CDN
    $.getScript("https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.24.0/moment.min.js", function() {
      // Load the moment.js time zone data remotely
      $.getScript("https://cdnjs.cloudflare.com/ajax/libs/moment-timezone/0.5.26/moment-timezone.min.js", function() {
       // Add time zone(s)
        moment.tz.add('America/New_York|EST EDT|50 40|0101|1Lz50 1zb0 Op0');
       // Get current EST time
       var now = moment().tz("America/New_York");
       // Execute rest of script here...
      });
    });

    0
  • Bryan - Community Manager
    Comment actions Permalink

    Great workaround David -- I was able to reproduce the original issue by including the libraries via script tags. Your approach does workaround the issue, however. Thanks for sharing!

    0
  • Diziana
    Comment actions Permalink

    Bryan - Community Manager

     

    It seems, the bug has popped up again. The moment.js in themes are failing to work -- probably Zendesk is loading another version? We reported it here: https://support.zendesk.com/hc/en-us/community/posts/360031296373-Do-you-use-moment-js-in-your-Theme-Has-it-been-broken-in-last-couple-of-days-

    A lot of people have moment.js (old and newer versions) included in theme, and those are being broken. Kindly check it.


    Thank you

    0
  • Devan
    Comment actions Permalink

    Hello Diziana,

    We reached out to our engineering team, and it looks like we will have to take this issue in a ticket to further troubleshoot it for you. I'll go ahead and create one on your behalf so expect to hear from a member of our team shortly. 

    Best regards.

    0
  • Diziana
    Comment actions Permalink

    Thank you. I realized the change was rolled back but we need to discuss and come to a solution so it doesn't happen again. A lot of help-centers are using moment.js for years, and it will be hard to have all them change their code because Zendesk is using a newer moment.js in their own code which some way overrides customer's version of code.

     

    Thank you

    0
  • David Bjorgen
    Comment actions Permalink

    Diziana, we began having trouble with moment.js also, so we switched over to the lightweight Dayjs for our time calculations.

    0

Please sign in to leave a comment.

Powered by Zendesk