Skip to content

Commit

Permalink
Merge pull request #16 from josedotjs/fix-plugins
Browse files Browse the repository at this point in the history
fix: load plugins from esm, add plugins tests in playground
  • Loading branch information
nathanchase authored Mar 8, 2023
2 parents 005af3f + 7e48c97 commit 8de04a4
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
22 changes: 22 additions & 0 deletions playground/app.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
{{ locale.name }} {{ locale.value }}
</option>
</select>

<h1>Example: Date formatting</h1>
<p>Unformatted: {{ new Date() }}</p>
<p>
Expand All @@ -27,6 +28,21 @@
{{ month }}
</li>
</ul>
<p>UTC: {{ $dayjs.utc().format() }}</p>
<p>Weekday: {{ $dayjs().weekday() }}</p>
<p>Day of year: {{ $dayjs().dayOfYear() }}</p>
<p>Duration: {{ $dayjs.duration(10000) }}</p>
{{ $dayjs(new Date()).isBetween('2023-01-01', '2023-02-01', 'day', '[)') }}
<p>Is Leap year? {{ $dayjs().isLeapYear() }}</p>
<p>Is same or after 2023-04-30 ? {{ $dayjs().isSameOrAfter('2023-04-30', 'day') }}</p>
<p>Is same or before 2023-04-30 ? {{ $dayjs().isSameOrBefore('2023-04-30', 'day') }}</p>
<p>Start of day to Now: {{ $dayjs($dayjs().startOf('day')).toNow() }}</p>
<div> Timezone :</div>
<select v-model="currentTimezone">
<option v-for="item in timezones" :value="item">
{{ item }}
</option>
</select><div> {{ $dayjs().tz(currentTimezone).format('DD/MM/YYYY HH:mm z') }}</div>
</div>
</template>

Expand All @@ -37,6 +53,11 @@ const locales = ref([
{ name: 'Portuguese', value: 'pt' }
])
const currentLocale = ref('en')
const currentTimezone = ref('America/New_York')
const timezones = ref(['America/New_York',
'Asia/Taipei'
])
const { $dayjs } = useNuxtApp()
Expand All @@ -46,4 +67,5 @@ const prettyDate = computed(() =>
watch(currentLocale, (newVal) => {
$dayjs.locale(newVal)
})
</script>
11 changes: 10 additions & 1 deletion playground/nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,25 @@ export default defineNuxtConfig({
],
dayjs: {
locales: ['en', 'es', 'pt'],

defaultLocale: 'en',
plugins: [
'advancedFormat',
'customParseFormat',
'utc',
'timezone',
'relativeTime',
'localizedFormat',
'localeData',
'isToday',
'updateLocale'
'updateLocale',
'weekday',
'dayOfYear',
'duration',
'isBetween',
'isLeapYear',
'isSameOrAfter',
'isSameOrBefore'
]
}
})
2 changes: 1 addition & 1 deletion src/gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ ${locales.map(l => `import 'dayjs/esm/locale/${l}'`).join('\n')}
${shouldSetDefaultLocale ? `dayjs.locale('${defaultLocale}')` : ''}
${plugins.map((p) => {
const _p = renamePlugin(p)
return `import ${_p} from 'dayjs/plugin/${p}.js'\ndayjs.extend(${_p})`
return `import ${_p} from 'dayjs/esm/plugin/${p}/index.js'\ndayjs.extend(${_p})`
}).join('\n')}
${shouldSetDefaultTimeZone ? `dayjs.tz.setDefault('${defaultTimeZone}')` : ''}
`
Expand Down

0 comments on commit 8de04a4

Please sign in to comment.