How do I add the Luxon library google sheet script

33 views Asked by At

I need to add the Luxon library to my google sheet script. Where do I find the ID of the Luxon library, or are there other ways?

Thank you

1

There are 1 answers

0
Tanaike On

It seems that Luxon can be also used with CDN. Ref When https://cdnjs.cloudflare.com/ajax/libs/luxon/3.4.4/luxon.min.js is used, how about the following sample script?

Pattern 1:

In this pattern, the script of Luxon is used by copying to the script editor.

  1. Please access https://cdnjs.cloudflare.com/ajax/libs/luxon/3.4.4/luxon.min.js with your browser.

  2. Copy and paste the script from the URL to the script editor of Google Apps Script.

  3. When the following sample script is used, a result like 2024-03-31T09:45:27.040+09:00 is obtained.

    function myFunction() {
      const res = luxon.DateTime.now().toISO();
      console.log(res); // 2024-03-31T09:45:27.040+09:00
    }
    

Pattern 2:

In this pattern, the script of Luxon is loaded when the script is run.

  1. When the following sample script is used, a result like 2024-03-31T09:45:27.040+09:00 is obtained.

    function myFunction() {
      // Load library.
      const url = "https://cdnjs.cloudflare.com/ajax/libs/luxon/3.4.4/luxon.min.js";
      eval(UrlFetchApp.fetch(url).getContentText());
    
      // Use library.
      const res = luxon.DateTime.now().toISO();
      console.log(res); // 2024-03-31T09:45:27.040+09:00
    }
    

Note:

  • I cannot test all methods of luxon. So, I'm not sure whether all methods can be worked.