@@ -19,6 +19,7 @@ import ClockIcon from "@/app/conf/_design-system/pixelarticons/clock.svg?svgr"
19
19
20
20
import { getEventTitle } from "../../utils"
21
21
import { CalendarIcon } from "@/app/conf/_design-system/pixelarticons/calendar-icon"
22
+ import { formatBlockTime } from "./format-block-time"
22
23
23
24
function isString ( x : unknown ) : x is string {
24
25
return Object . prototype . toString . call ( x ) === "[object String]"
@@ -139,17 +140,10 @@ export function ScheduleSessionCard({
139
140
{ session . venue }
140
141
</ span >
141
142
) }
142
- { blockTimeFraction < 1 && (
143
- < span className = "typography-body-xs flex items-center gap-0.5" >
144
- < ClockIcon className = "size-4 text-pri-base [@container(width<240px)]:hidden" />
145
- { Math . round (
146
- ( new Date ( session . event_end ) . getTime ( ) -
147
- new Date ( session . event_start ) . getTime ( ) ) /
148
- ( 1000 * 60 ) ,
149
- ) } { " " }
150
- min
151
- </ span >
152
- ) }
143
+ < SessionDuration
144
+ session = { session }
145
+ blockTimeFraction = { blockTimeFraction }
146
+ />
153
147
< AddToCalendarLink
154
148
eventTitle = { eventTitle }
155
149
session = { session }
@@ -164,6 +158,33 @@ export function ScheduleSessionCard({
164
158
)
165
159
}
166
160
161
+ function SessionDuration ( {
162
+ session,
163
+ blockTimeFraction,
164
+ } : {
165
+ session : ScheduleSession
166
+ blockTimeFraction : number
167
+ } ) : React . ReactNode {
168
+ if ( blockTimeFraction >= 1 ) return null
169
+
170
+ const durationMs =
171
+ new Date ( session . event_end ) . getTime ( ) -
172
+ new Date ( session . event_start ) . getTime ( )
173
+
174
+ // if a session is longer than 3 hourse, we show the time range
175
+ const formattedTime =
176
+ durationMs > 1000 * 60 * 60 * 3
177
+ ? formatBlockTime ( session . event_start , new Date ( session . event_end ) )
178
+ : `${ Math . round ( durationMs / ( 1000 * 60 ) ) } min`
179
+
180
+ return (
181
+ < span className = "typography-body-xs flex items-center gap-0.5" >
182
+ < ClockIcon className = "size-4 text-pri-base [@container(width<240px)]:hidden" />
183
+ { formattedTime }
184
+ </ span >
185
+ )
186
+ }
187
+
167
188
function AddToCalendarLink ( {
168
189
eventTitle,
169
190
session,
0 commit comments