I am currently utilizing moment.js
in conjunction with vue 3
.
I've implemented a function that calculates the disparity between two dates
. The functionality works as expected, but here's where my query comes in. The function is structured like so:
methods: {
getDateDifference (date) {
var date = moment(date, 'YYYY MM DD')
var today = moment()
return today.diff(date, 'days')
}
}
At this point, I can effectively determine the difference between the passed date
and the current today
. However, the issue arises when I aim to ascertain whether the returned number of days
falls in a specific range - greater than a week but less than a month. In such cases, I would prefer to display the value in terms of weeks
, rather than just stating 28 days
, for instance. Additionally, if the number of days
exceeds 28, it should be shown in months
, and likewise, for over a year, they should be presented as years
.
In essence, instead of showing
26 days
I'd like the system to evaluate if this can be converted to weeks, resulting in:
3 weeks
Furthermore, if feasible, the option to display the duration in terms of months
or years
as well should be provided.