Skip to content

Commit

Permalink
rolling date-fns#2423 back
Browse files Browse the repository at this point in the history
  • Loading branch information
Lucas Silva committed Aug 16, 2021
1 parent a3e7e6e commit 83a9bc4
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
10 changes: 5 additions & 5 deletions src/formatDuration/index.js
Expand Up @@ -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) => {
Expand Down
7 changes: 4 additions & 3 deletions src/getWeekYear/index.ts
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion src/getWeeksInMonth/index.ts
Expand Up @@ -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)

Expand Down

0 comments on commit 83a9bc4

Please sign in to comment.