Skip to content

Commit

Permalink
fix(ui): time to date info
Browse files Browse the repository at this point in the history
  • Loading branch information
RaneHyv committed Mar 26, 2024
1 parent 0fa4bb0 commit 01a6f48
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ const messages = defineMessages({
});

const Card = ({ item, index, hideText }) => {
const { title, start, end, whole_day } = item || {};
const wholeDay = typeof whole_day === 'boolean' ? whole_day : true;
const { title, start, end } = item || {};
const isEvent = item?.['@type'] === 'Event';
const endDate = new Date(end || Date.now());
const startDate = new Date(start || Date.now());
Expand Down Expand Up @@ -84,12 +83,7 @@ const Card = ({ item, index, hideText }) => {
<h1 className="slide-title hero">{title || ''}</h1>
{startDate && isEvent && (
<p className="slide-description hero">
{getDateRangeDescription(
intl.locale,
startDate,
endDate,
wholeDay,
)}
{getDateRangeDescription(intl.locale, startDate, endDate)}
</p>
)}
</div>
Expand Down
5 changes: 2 additions & 3 deletions frontend/src/components/blocks/Listing/ListingTemplate.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { Grid } from 'semantic-ui-react';

const Card = ({ item, showDescription = true, hideDates = false }) => {
const intl = useIntl();
const wholeDay = typeof item.whole_day === 'boolean' ? item.whole_day : true;
const start = item.start ? new Date(item.start) : undefined;
const end = item.end ? new Date(item.end) : undefined;
const image = item?.image_field
Expand All @@ -35,14 +34,14 @@ const Card = ({ item, showDescription = true, hideDates = false }) => {
{item['@type'] === 'Event' && start && end && (
<div className="listing-dates">
<div className={`listing-dates-wrapper`}>
{getDateRangeDescription(intl.locale, start, end, wholeDay)}
{getDateRangeDescription(intl.locale, start, end)}
</div>
</div>
)}
{item['@type'] === 'News Item' && (
<div className="listing-dates">
<div className={`listing-dates-wrapper`}>
{getDateRangeDescription(intl.locale, start, end, wholeDay)}
{getDateRangeDescription(intl.locale, start, end)}
</div>
</div>
)}
Expand Down
4 changes: 3 additions & 1 deletion frontend/src/helpers/getDateRangeDescription.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export function getDateRangeDescription(lang, start, end, wholeDay = true) {
export function getDateRangeDescription(lang, start, end) {
const startTime = new Intl.DateTimeFormat(lang, {
hour: 'numeric',
minute: 'numeric',
Expand All @@ -9,6 +9,8 @@ export function getDateRangeDescription(lang, start, end, wholeDay = true) {
minute: 'numeric',
}).format(end);

const wholeDay = startTime === '00:00' && endTime === '23:59';

const time =
wholeDay || startTime === endTime ? '' : `, ${startTime} - ${endTime}`;

Expand Down

0 comments on commit 01a6f48

Please sign in to comment.