1- import { differenceInMinutes , format , getDay , isSameDay } from "date-fns" ;
1+ import { differenceInMinutes , format } from "date-fns" ;
22import type { TFunction } from "i18next" ;
33import { trim } from "lodash" ;
44import {
@@ -17,63 +17,19 @@ import {
1717 type ReservationQuery ,
1818} from "@gql/gql-types" ;
1919import { formatDuration , fromApiDate } from "common/src/common/util" ;
20- import { toMondayFirstUnsafe } from "common/src/helpers" ;
2120import { truncate } from "@/helpers" ;
22- import { DATE_FORMAT , formatDate , formatTime } from "@/common/util" ;
21+ import { formatDateTimeRange , formatDate } from "@/common/util" ;
2322
2423type ReservationType = NonNullable < ReservationQuery [ "reservation" ] > ;
2524type ReservationUnitType = NonNullable < ReservationType [ "reservationUnit" ] > [ 0 ] ;
2625
27- export function reservationDateTime (
28- start : Date ,
29- end : Date ,
30- t : TFunction
31- ) : string {
32- const startDay = t ( `dayShort.${ toMondayFirstUnsafe ( getDay ( start ) ) } ` ) ;
33-
34- if ( isSameDay ( start , end ) ) {
35- return `${ startDay } ${ format ( start , DATE_FORMAT ) } ${ format (
36- start ,
37- "HH:mm"
38- ) } -${ format ( end , "HH:mm" ) } `;
39- }
40-
41- return `${ format ( start , DATE_FORMAT ) } ${ format ( start , "HH:mm" ) } -${ format (
42- end ,
43- "HH:mm"
44- ) } ${ format ( end , "HH:mm" ) } `;
45- }
46-
47- export function reservationDateTimeString (
48- start : string ,
49- end : string ,
50- t : TFunction
51- ) : string {
52- const startDate = new Date ( start ) ;
53- const endDate = new Date ( end ) ;
54-
55- return reservationDateTime ( startDate , endDate , t ) ;
56- }
57-
58- function reservationDurationString (
59- start : string ,
60- end : string ,
61- t : TFunction
62- ) : string {
63- const startDate = new Date ( start ) ;
64- const endDate = new Date ( end ) ;
65-
66- const durMinutes = differenceInMinutes ( endDate , startDate ) ;
67- const abbreviated = true ;
68- return formatDuration ( durMinutes , t , abbreviated ) ;
69- }
70-
71- const reservationUnitName = (
26+ function reservationUnitName (
7227 reservationUnit : Maybe < ReservationUnitType >
73- ) : string =>
74- reservationUnit
28+ ) : string {
29+ return reservationUnit
7530 ? `${ reservationUnit . nameFi } , ${ reservationUnit . unit ?. nameFi || "" } `
7631 : "-" ;
32+ }
7733
7834export function reservationPrice (
7935 reservation : ReservationType ,
@@ -245,7 +201,7 @@ export function createTagString(
245201 t : TFunction
246202) : string {
247203 const createRecurringTag = ( begin ?: string , end ?: string ) =>
248- begin && end ? `${ formatDate ( begin ) } - ${ formatDate ( end ) } ` : "" ;
204+ begin && end ? `${ formatDate ( begin ) } – ${ formatDate ( end ) } ` : "" ;
249205
250206 const recurringTag = createRecurringTag (
251207 reservation . recurringReservation ?. beginDate ?? undefined ,
@@ -256,30 +212,20 @@ export function createTagString(
256212 ?. map ( reservationUnitName )
257213 . join ( ", " ) ;
258214
259- const singleDateTimeTag = reservationDateTimeString (
260- reservation . begin ,
261- reservation . end ,
262- t
263- ) ;
215+ const begin = new Date ( reservation . begin ) ;
216+ const end = new Date ( reservation . end ) ;
217+ const singleDateTimeTag = formatDateTimeRange ( t , begin , end ) ;
264218
265219 const weekDayTag = reservation . recurringReservation ?. weekdays
266220 ?. sort ( )
267221 ?. map ( ( x ) => t ( `dayShort.${ x } ` ) )
268222 ?. reduce ( ( agv , x ) => `${ agv } ${ agv . length > 0 ? "," : "" } ${ x } ` , "" ) ;
269223
270- const recurringDateTag =
271- reservation . begin && reservation . end
272- ? `${ weekDayTag } ${ formatTime ( reservation . begin , "HH:mm" ) } -${ formatTime (
273- reservation . end ,
274- "HH:mm"
275- ) } `
276- : "" ;
224+ const recurringDateTag = `${ weekDayTag } ${ format ( begin , "HH:mm" ) } –${ format ( end , "HH:mm" ) } ` ;
277225
278- const durationTag = reservationDurationString (
279- reservation . begin ,
280- reservation . end ,
281- t
282- ) ;
226+ const durMinutes = differenceInMinutes ( end , begin ) ;
227+ const abbreviated = true ;
228+ const durationTag = formatDuration ( durMinutes , t , abbreviated ) ;
283229
284230 const reservationTagline = `${
285231 reservation . recurringReservation ? recurringDateTag : singleDateTimeTag
0 commit comments