Skip to content

Commit 298a1d2

Browse files
authored
Merge pull request #18 from simpletut/setDefaultTimezoneV2
Set default timezone v2
2 parents cf5611b + eca93a5 commit 298a1d2

File tree

4 files changed

+24
-24
lines changed

4 files changed

+24
-24
lines changed

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.2.0",
3+
"version": "1.2.1",
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: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,14 @@ export const formatBookingsData = ({ bookings, year }: IFormatBookingsData): Boo
7575
const to = booking?.to
7676
const middayCheckout = booking?.middayCheckout
7777

78-
const validStartDate = dayjs.tz(from).year() === Number(year)
79-
const validEndDate = dayjs.tz(to).year() === Number(year)
78+
const validStartDate = dayjs(from).year() === Number(year)
79+
const validEndDate = dayjs(to).year() === Number(year)
8080

8181
if (!validStartDate && !validEndDate) return null
8282

8383
const nxtBooking: BookingType = {
84-
from: dayjs.tz(from).format(dateFormat),
85-
to: dayjs.tz(to).format(dateFormat),
84+
from: dayjs(from).format(dateFormat),
85+
to: dayjs(to).format(dateFormat),
8686
middayCheckout,
8787
}
8888

@@ -93,12 +93,12 @@ export const formatBookingsData = ({ bookings, year }: IFormatBookingsData): Boo
9393
}
9494

9595
export const getDatesInRange = ({ startDate, endDate }: IGetDatesInRange): blockedDaysType => {
96-
let _startDate = dayjs.tz(startDate).hour(0).minute(0).second(0);
97-
const _endDate = dayjs.tz(endDate).hour(0).minute(0).second(0);
96+
let _startDate = dayjs(startDate).hour(0).minute(0).second(0);
97+
const _endDate = dayjs(endDate).hour(0).minute(0).second(0);
9898

9999
const dates: blockedDaysType = []
100100

101-
while (!dayjs.tz(_startDate).isAfter(_endDate)) {
101+
while (!dayjs(_startDate).isAfter(_endDate)) {
102102
dates.push(_startDate.format(dateFormat));
103103

104104
_startDate = _startDate.add(1, 'day')

src/components/Calendar/Year/index.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const Year = ({
1010
lateCheckouts = [],
1111
monthsFrom = 1,
1212
}: IYear): JSX.Element => {
13-
const _year = activeYear || dayjs.tz().year()
13+
const _year = activeYear || dayjs().year()
1414

1515
return (
1616
<div className='year' data-testid='year'>
@@ -19,8 +19,8 @@ const Year = ({
1919
const month = monthsFrom + pos
2020
const date = `${_year}-${month}`
2121
const monthName = getMonthName(month)
22-
const totalDays = dayjs.tz(date).daysInMonth()
23-
const firstDayOfWeek = dayjs.tz(`${date}-01`).day()
22+
const totalDays = dayjs(date).daysInMonth()
23+
const firstDayOfWeek = dayjs(`${date}-01`).day()
2424

2525
const offsetDays =
2626
firstDayOfWeek !== 0

src/components/Calendar/index.tsx

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,17 @@ import Controls from './Controls'
66
import Year from './Year'
77
import Key from './Key'
88
import { ICalendarPropTypes, IControls, blockedDaysType, IYear } from './types'
9-
import timezone from "dayjs/plugin/timezone";
10-
import utc from "dayjs/plugin/utc";
11-
import advancedFormat from "dayjs/plugin/advancedFormat";
9+
// import timezone from "dayjs/plugin/timezone";
10+
// import utc from "dayjs/plugin/utc";
11+
// import advancedFormat from "dayjs/plugin/advancedFormat";
1212
import customParseFormat from 'dayjs/plugin/customParseFormat'
1313

14-
const defaultTimeZone = 'Europe/London';
14+
// const defaultTimeZone = 'Europe/London';
1515

16-
dayjs.extend(utc);
17-
dayjs.extend(timezone);
18-
dayjs.extend(advancedFormat);
19-
dayjs.tz.setDefault(defaultTimeZone);
16+
// dayjs.extend(utc);
17+
// dayjs.extend(timezone);
18+
// dayjs.extend(advancedFormat);
19+
// dayjs.tz.setDefault(defaultTimeZone);
2020
dayjs.extend(isBetween);
2121
dayjs.extend(customParseFormat);
2222

@@ -31,7 +31,7 @@ const Calendar = ({
3131
const initialPage = 1
3232
const totalCalendarMonths = 12
3333
const _showNumberOfMonths = isValidMonthsOption(showNumberOfMonths) ? showNumberOfMonths : totalCalendarMonths
34-
const _year = dayjs.tz().year();
34+
const _year = dayjs().year();
3535
const [activeYear, setActiveYear] = useState(_year)
3636
const [bookedDates, setBookedDates] = useState<blockedDaysType>([])
3737
const [lateCheckouts, setLateCheckouts] = useState<blockedDaysType>([])
@@ -55,7 +55,7 @@ const Calendar = ({
5555
)
5656

5757
const findActivePage = useCallback(() => {
58-
const now = dayjs.tz()
58+
const now = dayjs()
5959
const _month = now.month() + 1
6060
let _page = 1
6161
for (let i = 1; i <= totalPages; i++) {
@@ -74,7 +74,7 @@ const Calendar = ({
7474
}, [findActivePage, _showNumberOfMonths])
7575

7676
const initCal = useCallback(() => {
77-
const now = dayjs.tz()
77+
const now = dayjs()
7878
const _year = now.year()
7979
setActiveYear(_year)
8080
if (_showNumberOfMonths !== totalCalendarMonths) findActivePage()
@@ -85,7 +85,7 @@ const Calendar = ({
8585
const isFirstPage = page === 1
8686

8787
if (isFirstPage) {
88-
const _previousYear = dayjs.tz(`${activeYear}`).subtract(1, 'year').year()
88+
const _previousYear = dayjs(`${activeYear}`).subtract(1, 'year').year()
8989
setActiveYear(_previousYear)
9090

9191
if (_showNumberOfMonths === totalCalendarMonths) {
@@ -110,7 +110,7 @@ const Calendar = ({
110110
const next = useCallback(() => {
111111
const isLastPage = page === totalPages
112112
if (isLastPage) {
113-
const _nextYear = dayjs.tz(`${activeYear}`).add(1, 'year').year()
113+
const _nextYear = dayjs(`${activeYear}`).add(1, 'year').year()
114114
setActiveYear(_nextYear)
115115
resetCalendarYear()
116116
return

0 commit comments

Comments
 (0)