Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add options.unit check #2411

Merged
merged 1 commit into from Apr 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/formatDistanceStrict/index.js
Expand Up @@ -262,7 +262,7 @@ export default function formatDistanceStrict(
// 1 up to 12 months
} else if (unit === 'month') {
var months = roundingMethodFn(dstNormalizedMinutes / MINUTES_IN_MONTH)
return months === 12
return months === 12 && options.unit !== 'month'
? locale.formatDistance('xYears', 1, localizeOptions)
: locale.formatDistance('xMonths', months, localizeOptions)

Expand Down
9 changes: 9 additions & 0 deletions src/formatDistanceStrict/test.js
Expand Up @@ -266,6 +266,15 @@ describe('formatDistanceStrict', function () {
assert(result === '4 months')
})

it('12 months - see issue 2388', function () {
var result = formatDistanceStrict(
new Date(1986, 7, 4, 10, 32, 0),
new Date(1985, 7, 4, 10, 32, 0),
{ unit: 'month' }
)
assert(result === '12 months')
})

it('24 months', function () {
var result = formatDistanceStrict(
new Date(1986, 3, 4, 10, 32, 0),
Expand Down