nuxt-community / moment-module

Efficient Moment.js integration for Nuxt
MIT License
195 stars 12 forks source link

[QUESTION] Set default format #73

Open andre-paulo98 opened 3 years ago

andre-paulo98 commented 3 years ago

So if in my application, I use 90% of the time, DD/MM/YYYY, is there anyway that the default format is that one? Instead of manually formatting each time?

thibaudallie commented 3 years ago

add this plugin

alfaben12 commented 3 years ago

just add .format('YYYY')

ex: $moment(datetime).format('YYYY') thats work for me

mrleblanc101 commented 3 years ago

You could create a utility function. So instead of calling moment, you call your function which has the correct format.

farnabaz commented 3 years ago

Changing $moment.defaultFormat will do the trick. Checkout https://github.com/moment/moment/issues/3176#issuecomment-638011241

sneakylenny commented 3 years ago

add this plugin

just add .format('YYYY')

You could create a utility function. So instead of calling moment, you call your function which has the correct format.

Changing $moment.defaultFormat will do the trick. Checkout moment/moment#3176 (comment)

Wouldn't it be easier if there was a way to pass it through the module options? Because why would I use this module if I could create a plugin to do the same and have more configuration available. It defeats the whole purpose of this module in my opinion. I don't know if this option already exists but here is my plugin example:

plugins/moment.js:

import moment from 'moment'

moment.defaultFormat = '[test] DD-MM-YYYY HH:mm'

export default (_, inject) => {
  inject('moment', moment)
}
<template>
  <div>{{ $moment().format() }}</div>
  <!-- Returned: test 21-10-2021 14:11 -->
<template>

I may create a PR in the future to add an option like this into the config of this module

sneakylenny commented 2 years ago

I did create a PR to add this feature but I think they've abandoned this package or forgot about it. No response since I submitted it on February 8. 😕 I mean it's not that hard right?