Skip to content

Commit

Permalink
fix: getWeeksInMonth with properly weekStartsOn option
Browse files Browse the repository at this point in the history
  • Loading branch information
achamorro-dev committed Feb 13, 2023
1 parent c2b7b91 commit 0f44d7e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@ import CalendarHeader from 'modules/binnacle/page/BinnacleDesktop/ActivitiesCale
import { useCalendarKeysNavigation } from 'modules/binnacle/page/BinnacleDesktop/ActivitiesCalendar/useCalendarKeyboardNavigation'
import { forwardRef, Fragment, useState } from 'react'
import { useGlobalState } from 'shared/arch/hooks/use-global-state'
import { isSaturday, isSunday } from 'shared/utils/chrono'
import { getWeeksInMonth, isSaturday, isSunday } from 'shared/utils/chrono'
import { CellHeader } from './CalendarCell/CellHeader/CellHeader'
import { CellBody } from 'modules/binnacle/page/BinnacleDesktop/ActivitiesCalendar/CalendarCell/CellBody/CellBody'
import type { ActivitiesPerDay } from 'modules/binnacle/data-access/interfaces/activities-per-day.interface'
import { getWeeksInMonth } from 'date-fns'

export const ActivitiesCalendar = observer(() => {
const { activities, holidays, selectedDate } = useGlobalState(BinnacleState)
Expand Down
17 changes: 16 additions & 1 deletion src/shared/utils/chrono.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import chrono, { parseISO, getHumanizedDuration } from 'shared/utils/chrono'
import chrono, { parseISO, getHumanizedDuration, getWeeksInMonth } from 'shared/utils/chrono'

describe('Chrono', () => {
it('should format relative as expected', function () {
Expand Down Expand Up @@ -105,4 +105,19 @@ describe('Chrono', () => {
expect(humanDuration).toBe(result)
}
)

test.each`
selectedDate | result
${'2023-01-01'} | ${6}
${'2023-02-01'} | ${5}
${'2023-03-01'} | ${5}
${'2023-04-01'} | ${5}
${'2023-05-01'} | ${5}
${'2023-07-01'} | ${6}
${'2023-12-01'} | ${5}
`('should get $result weeks for $selectedDate', function ({ selectedDate, result }) {
const weeksInMonth = getWeeksInMonth(parseISO(selectedDate))

expect(weeksInMonth).toBe(result)
})
})

0 comments on commit 0f44d7e

Please sign in to comment.