Created
November 15, 2022 05:05
-
-
Save srph/3bee677a5f5ee8e0608bc6efd14cd023 to your computer and use it in GitHub Desktop.
date-fns: Convert duration months to days
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { intervalToDuration, isAfter, eachDayOfInterval, addMonths } from 'date-fns' | |
const remaining = intervalToDuration({ | |
start: now, | |
end: target | |
}) | |
const days = | |
remaining.months && remaining.days | |
? remaining.days + | |
eachDayOfInterval({ | |
start: now, | |
end: addMonths(now, remaining.months) | |
}).length | |
: remaining.days |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment