I have a little problem with logic, I would like to be able to automatically calculate the difference in days and or months between two dates, ex: there are 20 days left, there is 1 month and 17 days left, ... function that does this directly with dayjs and I can't seem to get the logic of what I want.
Thank you in advance for your help :)
for the moment...
let creation = dayjs(currentEstimate.createdAt)
let limit_date = dayjs(currentEstimate.createdAt).add(currentEstimate.estimate_validation_date, 'd')
let diff = dayjs(limit_date).diff(creation, 'd')
let months = diff / 31
if (months < 1){
console.log(`devis valable ${diff} jours`)
}else{
console.log(`devis valable ${months} mois`)
}
EDIT
Thanks to Stephan Collins ->
let duration = require('dayjs/plugin/duration')
dayjs.extend(duration)
let relativeTime = require('dayjs/plugin/relativeTime')
dayjs.extend(relativeTime)
dayjs(currentEstimate.createdAt).to(dayjs(currentEstimate.createdAt).add(currentEstimate.estimate_validation_date, 'd'), true)
//one month