Skip to content

Commit 0591b46

Browse files
authored
Merge pull request #3 from simpletut/supportBookingsDateFormat
add support for 'to' & 'from' dates to be in Date format
2 parents ec685db + 058fa30 commit 0591b46

File tree

6 files changed

+19
-19
lines changed

6 files changed

+19
-19
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ import Calendar from 'reactjs-availability-calendar'
3535
export default function App() {
3636
const bookings = [
3737
{
38-
from: '01-08-2022',
39-
to: '01-16-2022',
38+
from: new Date('01-16-2022'),
39+
to: new Date('01-27-2022'),
4040
middayCheckout: true,
4141
},
4242
{
@@ -74,14 +74,14 @@ Please copy and self host the default CSS linked below.
7474
**Example:**
7575
```
7676
{
77-
from: '01-08-2022',
78-
to: '01-16-2022',
77+
from: new Date('01-16-2022'),
78+
to: new Date('01-27-2022'),
7979
middayCheckout: true,
8080
}
8181
```
8282
**Type:** Array of Bookings\
8383
**Default:** []\
84-
**Description:** Dates should be in US format (MM-DD-YYYY).
84+
**Description:** Dates to be shown as unavailable on the calendar
8585

8686

8787
### showNumberOfMonths

example/src/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import Calendar from 'reactjs-availability-calendar'
44

55
const bookings = [
66
{
7-
from: '01-08-2022',
8-
to: '01-16-2022',
7+
from: new Date('01-16-2022'),
8+
to: new Date('01-27-2022'),
99
middayCheckout: true,
1010
},
1111
{

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "reactjs-availability-calendar",
3-
"version": "1.0.5",
3+
"version": "1.0.6",
44
"description": "React Availability Calendar",
55
"main": "./dist/cjs/index.js",
66
"module": "./dist/esm/index.js",

src/components/Calendar/Utils/index.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ export const formatBookingsData = ({ bookings, year }: IFormatBookingsData): Boo
2929
if (!validStartDate && !validEndDate) return null
3030

3131
const nxtBooking: BookingType = {
32-
from,
33-
to,
32+
from: dayjs(from).format('MM-DD-YYYY'),
33+
to: dayjs(to).format('MM-DD-YYYY'),
3434
middayCheckout,
3535
}
3636

@@ -77,7 +77,7 @@ export const getAllHalfDays = ({ dates }: IGetAllHalfDays): blockedDaysType => {
7777
const arr: blockedDaysType = []
7878

7979
dates.forEach(({ to, middayCheckout }) => {
80-
if (middayCheckout) {
80+
if (middayCheckout && typeof to === 'string') {
8181
arr.push(to)
8282
}
8383
})

src/components/Calendar/types.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
export type BookingType = {
2-
from: string
3-
to: string
2+
from: string | Date
3+
to: string | Date
44
middayCheckout?: boolean
55
}
66

@@ -35,8 +35,8 @@ export interface IGetAllHalfDays {
3535
}
3636

3737
export interface IGetDatesInRange {
38-
startDate: string
39-
endDate: string
38+
startDate: string | Date
39+
endDate: string | Date
4040
}
4141

4242
export interface IControls {

tests/common.test.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import Calendar from '../src'
77

88
const bookings = [
99
{
10-
from: '01-08-2022',
11-
to: '01-16-2022',
10+
from: new Date('01-16-2022'),
11+
to: new Date('01-27-2022'),
1212
middayCheckout: true,
1313
},
1414
{
@@ -99,9 +99,9 @@ describe('Calendar', () => {
9999
expect(months).toHaveLength(6)
100100
})
101101

102-
it('Should Render 18 Booked Days', () => {
102+
it('Should Render 21 Booked Days', () => {
103103
const { container } = render(<Calendar bookings={bookings} />)
104-
expect(container.getElementsByClassName('booked').length).toBe(18)
104+
expect(container.getElementsByClassName('booked').length).toBe(21)
105105
})
106106

107107
it('Should Render 1 Late Checkout Day', () => {

0 commit comments

Comments
 (0)