Search code examples
javascriptnuxt.jsdayjs

Day JS in Nuxt guessing timezone using tz.guess() not a function


I'm using the @nuxtjs/dayjs module v1.4.1 in my Nuxt 2 project. I need to guess the user's timezone and set a datetime in their timezone. When I try to run my JS, I get an error telling me it's not a function, what am I missing?

// Day JS config
dayjs: {
  locales: ['en'],
  defaultLocale: 'en',
  plugins: [
    'utc',
    'timezone',
    'relativeTime',
    'advancedFormat',
    'localizedFormat',
    'customParseFormat'
  ]
},

Called like in a function:

this.$dayjs().tz.guess()

returns error:

this.$dayjs(...).tz.guess is not a function


Solution

  • It should be

    this.$dayjs.tz.guess()
    

    Refer https://day.js.org/docs/en/timezone/guessing-user-timezone