From 83a9bc4ee966842e0e45d0d123c9b76d3011a591 Mon Sep 17 00:00:00 2001 From: Lucas Silva Date: Sun, 15 Aug 2021 21:16:57 -0300 Subject: [PATCH] rolling #2423 back --- src/formatDuration/index.js | 10 +++++----- src/getWeekYear/index.ts | 7 ++++--- src/getWeeksInMonth/index.ts | 2 +- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/formatDuration/index.js b/src/formatDuration/index.js index c4130a6721..e020e69a8c 100644 --- a/src/formatDuration/index.js +++ b/src/formatDuration/index.js @@ -73,17 +73,17 @@ const defaultFormat = [ * formatDuration({ years: 2, months: 9, weeks: 3 }, { delimiter: ', ' }) * //=> '2 years, 9 months, 3 weeks' */ -export default function formatDuration(duration, options) { +export default function formatDuration(duration, options = {}) { if (arguments.length < 1) { throw new TypeError( `1 argument required, but only ${arguments.length} present` ) } - const format = options?.format || defaultFormat - const locale = options?.locale || defaultLocale - const zero = options?.zero || false - const delimiter = options?.delimiter || ' ' + const format = options.format || defaultFormat + const locale = options.locale || defaultLocale + const zero = options.zero || false + const delimiter = options.delimiter || ' ' const result = format .reduce((acc, unit) => { diff --git a/src/getWeekYear/index.ts b/src/getWeekYear/index.ts index 649b8d1102..ce31d5d27e 100644 --- a/src/getWeekYear/index.ts +++ b/src/getWeekYear/index.ts @@ -53,21 +53,22 @@ import { */ export default function getWeekYear( dirtyDate: Date | number, - options?: LocaleOptions & WeekStartOptions & FirstWeekContainsDateOptions + options: LocaleOptions & WeekStartOptions & FirstWeekContainsDateOptions = {} ): number { requiredArgs(1, arguments) const date = toDate(dirtyDate) const year = date.getFullYear() + const locale = options.locale const localeFirstWeekContainsDate = - options?.locale?.options?.firstWeekContainsDate + locale && locale.options && locale.options.firstWeekContainsDate const defaultFirstWeekContainsDate = localeFirstWeekContainsDate == null ? 1 : toInteger(localeFirstWeekContainsDate) const firstWeekContainsDate = - options?.firstWeekContainsDate == null + options.firstWeekContainsDate == null ? defaultFirstWeekContainsDate : toInteger(options.firstWeekContainsDate) diff --git a/src/getWeeksInMonth/index.ts b/src/getWeeksInMonth/index.ts index 288ca59348..dfc770c5b9 100644 --- a/src/getWeeksInMonth/index.ts +++ b/src/getWeeksInMonth/index.ts @@ -37,7 +37,7 @@ import { LocaleOptions, WeekStartOptions } from '../types' */ export default function getWeeksInMonth( date: Date | number, - options?: LocaleOptions & WeekStartOptions + options: LocaleOptions & WeekStartOptions = {} ): number { requiredArgs(1, arguments)