Skip to content
This repository has been archived by the owner on Jan 9, 2023. It is now read-only.

Commit

Permalink
fix(breadcrumb): set appointment date precision to minutes in breadcrumb
Browse files Browse the repository at this point in the history
fix #1853
  • Loading branch information
oliv37 committed Feb 27, 2020
1 parent aaaadf0 commit 33b4dc3
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,24 @@ import { getAppointmentLabel } from '../../../../scheduling/appointments/util/sc
describe('scheduling appointment util', () => {
describe('getAppointmentLabel', () => {
it('should return the locale string representation of the start time and end time', () => {
const options = {
year: 'numeric',
month: '2-digit',
day: '2-digit',
hour: '2-digit',
minute: '2-digit',
}

const appointment = {
id: '123',
startDateTime: '2020-03-07T18:15:00.000Z',
endDateTime: '2020-03-07T20:15:00.000Z',
} as Appointment

expect(getAppointmentLabel(appointment)).toEqual(
`${new Date(appointment.startDateTime).toLocaleString()} - ${new Date(
appointment.endDateTime,
).toLocaleString()}`,
)
const startDateLabel = new Date(appointment.startDateTime).toLocaleString([], options)
const endDateLabel = new Date(appointment.endDateTime).toLocaleString([], options)

expect(getAppointmentLabel(appointment)).toEqual(`${startDateLabel} - ${endDateLabel}`)
})

it('should return the appointment id when start time is not defined', () => {
Expand Down
14 changes: 13 additions & 1 deletion src/scheduling/appointments/util/scheduling-appointment.util.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
import Appointment from '../../../model/Appointment'

const options = {
year: 'numeric',
month: '2-digit',
day: '2-digit',
hour: '2-digit',
minute: '2-digit',
}

function toLocaleString(date: Date) {
return date.toLocaleString([], options)
}

export function getAppointmentLabel(appointment: Appointment) {
const { id, startDateTime, endDateTime } = appointment

return startDateTime && endDateTime
? `${new Date(startDateTime).toLocaleString()} - ${new Date(endDateTime).toLocaleString()}`
? `${toLocaleString(new Date(startDateTime))} - ${toLocaleString(new Date(endDateTime))}`
: id
}

0 comments on commit 33b4dc3

Please sign in to comment.