diff --git a/src/components/Events.jsx b/src/components/Events.jsx index 1b052e7..72f6a77 100644 --- a/src/components/Events.jsx +++ b/src/components/Events.jsx @@ -21,9 +21,15 @@ const Events = () => { fetchData(); }, []); - function dateConverter(date) { - const newDate = new Date(date); - return newDate.toLocaleString('en-uk', { weekday: 'short', month: 'short', day: 'numeric', hour: 'numeric', minute: 'numeric' }); + function dateConverter(start, end) { + const startDate = new Date(start); + const endDate = new Date(end); + + if (startDate.getDate() == endDate.getDate()) { + return startDate.toLocaleString('en-uk', { weekday: 'long', month: 'short', day: 'numeric', hour: 'numeric', minute: 'numeric' })+" - "+endDate.toLocaleString('en-uk', { hour: 'numeric', minute: 'numeric' }); + } else { + return startDate.toLocaleString('en-uk', { weekday: 'long', month: 'short', day: 'numeric', hour: 'numeric', minute: 'numeric' })+" - "+endDate.toLocaleString('en-uk', { weekday: 'short', month: 'short', day: 'numeric', hour: 'numeric', minute: 'numeric' }) + } } console.log(dateConverter("2024-08-05 17:00:00")) @@ -31,51 +37,68 @@ const Events = () => { return (
-
- +
+ + {events.length != 0 ? :
} +
-

{events.length != 0 ? events[0].title : ""}

-

{events.length != 0 ? dateConverter(events[0].start_date) : ""} - {events.length != 0 ? dateConverter(events[0].end_date) : ""}

-

{events.length != 0 ? events[0].long_description : ""}

+ +

{events.length != 0 ? events[0].title : ""}

+
+

{events.length != 0 ? dateConverter(events[0].start_date, events[0].end_date) : ""}

+
+

{events.length != 0 ? events[0].long_description : ""}

- + + {events.length != 0 ? :
} +
-

{events.length != 0 ? events[1].title : ""}

-

{events.length != 0 ? dateConverter(events[1].start_date) : ""} - {events.length != 0 ? dateConverter(events[1].end_date) : ""}

-

{events.length != 0 ? events[1].long_description : ""}

+ +

{events.length != 0 ? events[1].title : ""}

+
+

{events.length != 0 ? dateConverter(events[1].start_date, events[1].end_date) : ""}

+
+

{events.length != 0 ? events[1].long_description : ""}

-
+

{events.length != 0 ? events[2].title : ""}

-

{events.length != 0 ? dateConverter(events[2].start_date) : ""} - {events.length != 0 ? dateConverter(events[2].end_date) : ""}

+

{events.length != 0 ? dateConverter(events[2].start_date, events[2].end_date) : ""}

-
-
+ +

{events.length != 0 ? events[3].title : ""}

-

{events.length != 0 ? dateConverter(events[3].start_date) : ""} - {events.length != 0 ? dateConverter(events[3].end_date) : ""}

+

{events.length != 0 ? dateConverter(events[3].start_date, events[3].end_date) : ""}

-
-
+ +

{events.length != 0 ? events[4].title : ""}

-

{events.length != 0 ? dateConverter(events[4].start_date) : ""} - {events.length != 0 ? dateConverter(events[4].end_date) : ""}

+

{events.length != 0 ? dateConverter(events[4].start_date, events[4].end_date) : ""}

+
+
+ + + +

{events.length != 0 ? events[5].title : ""}

+

{events.length != 0 ? dateConverter(events[5].start_date, events[5].end_date) : ""}

-
-
+ +

{events.length != 0 ? events[5].title : ""}

-

{events.length != 0 ? dateConverter(events[5].start_date) : ""} - {events.length != 0 ? dateConverter(events[5].end_date) : ""}

+

{events.length != 0 ? dateConverter(events[5].start_date, events[5].end_date) : ""}

-
+