@@ -3,7 +3,6 @@ import { Box, Skeleton, styled, Typography } from "@mui/material";
33import { alpha } from "@mui/material/styles" ;
44import Avatar from "components/Avatar" ;
55import { useAuthContext } from "features/auth/AuthProvider" ;
6- import useCurrentUser from "features/userQueries/useCurrentUser" ;
76import { useLiteUser } from "features/userQueries/useLiteUsers" ;
87import { useTranslation } from "i18n" ;
98import { DASHBOARD } from "i18n/namespaces" ;
@@ -12,11 +11,10 @@ import { HostRequest } from "proto/requests_pb";
1211import { routeToHostRequest } from "routes" ;
1312import { Temporal } from "temporal-polyfill" ;
1413import {
14+ daysBetween ,
1515 localizeDateTimeRange ,
1616 localizeRelativeTimeUnit ,
17- UTC_TIMEZONE ,
1817} from "utils/date" ;
19- import dayjs from "utils/dayjs" ;
2018
2119const StyledCard = styled ( Box ) ( ( { theme } ) => ( {
2220 display : "flex" ,
@@ -131,8 +129,6 @@ export default function UpcomingStayCard({
131129 hostRequest,
132130} : UpcomingStayCardProps ) {
133131 const { authState } = useAuthContext ( ) ;
134- const { data : currentUser } = useCurrentUser ( ) ;
135- const timezone = currentUser ?. timezone ?? UTC_TIMEZONE ;
136132 const {
137133 t,
138134 i18n : { language : locale } ,
@@ -144,31 +140,29 @@ export default function UpcomingStayCard({
144140 : hostRequest . hostUserId ;
145141 const { data : otherUser , isLoading } = useLiteUser ( otherUserId ) ;
146142
147- const fromDate = dayjs . tz ( hostRequest . fromDate , UTC_TIMEZONE ) ;
148- const toDate = dayjs . tz ( hostRequest . toDate , UTC_TIMEZONE ) ;
149- const nights = toDate . diff ( fromDate , "day" ) ;
150- const today = dayjs ( ) . tz ( timezone ) . startOf ( "day" ) ;
151- const daysUntil = fromDate . diff ( today , "day" ) ;
152- const daysUntilEnd = toDate . diff ( today , "day" ) ;
143+ const fromDate = Temporal . PlainDate . from ( hostRequest . fromDate ) ;
144+ const toDate = Temporal . PlainDate . from ( hostRequest . toDate ) ;
145+ const today = Temporal . Now . plainDateISO ( ) ;
146+ const nights = daysBetween ( fromDate , toDate ) ;
147+ const daysUntil = daysBetween ( today , fromDate ) ;
148+ const daysUntilEnd = daysBetween ( today , toDate ) ;
153149 const isOngoing = daysUntil <= 0 && daysUntilEnd >= 0 ;
154150 const isImminent = daysUntil <= 3 ;
155151 const relativeDaysLabel = localizeRelativeTimeUnit (
156152 daysUntil ,
157153 "days" ,
158154 locale ,
159- { capitalize : true } ,
160- ) ;
161-
162- const dateRange = localizeDateTimeRange (
163- Temporal . PlainDateTime . from ( hostRequest . fromDate ) ,
164- Temporal . PlainDateTime . from ( hostRequest . toDate ) ,
165155 {
166- locale,
167- includeTime : false ,
168- abbreviate : true ,
156+ capitalize : true ,
169157 } ,
170158 ) ;
171159
160+ const dateRange = localizeDateTimeRange ( fromDate , toDate , {
161+ locale,
162+ includeTime : false ,
163+ abbreviate : true ,
164+ } ) ;
165+
172166 const primary = isLoading ? (
173167 < Skeleton width = { 80 } />
174168 ) : (
0 commit comments