Skip to content

Commit c811a96

Browse files
committed
set time via storyblok
1 parent 3b2bc2e commit c811a96

File tree

1 file changed

+16
-27
lines changed

1 file changed

+16
-27
lines changed

src/components/giving-tuesday/Countdown.js

Lines changed: 16 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const getDescriptorString = (descriptor, time) => {
1616
const convertDaysToHours = (days) => (days ? days * 24 : 0);
1717

1818
const Countdown = ({ blok }) => {
19-
const { date, hasDays, hourPieRange, useNew } = blok;
19+
const { date, dayPieRange, hasDays, hourPieRange } = blok;
2020
const [countdownDate, setCountdownDate] = useState(null);
2121
const [days, hours, minutes, seconds] = UseCountdown(countdownDate) || [];
2222
const displayHours = hasDays ? hours : convertDaysToHours(days) + hours;
@@ -29,31 +29,20 @@ const Countdown = ({ blok }) => {
2929

3030
useEffect(() => {
3131
if (!countdownDate) {
32-
if (!date) {
33-
if (useNew) {
34-
/**
35-
* manually set date to 04/05/2024 7PM w/ a UTC offset (no daylight savings)
36-
* this should only stay for the current campaign, can remove this and make
37-
* component purely storyblok configurable after campaign
38-
*/
39-
setCountdownDate(new Date(Date.UTC(2024, 3, 6, 2, 0, 0)));
40-
} else {
41-
/**
42-
* manually set date to 04/04/2024 7AM w/ a UTC offset (no daylight savings)
43-
* this should only stay for the current campaign, can remove this and make
44-
* component purely storyblok configurable after campaign
45-
*/
46-
setCountdownDate(new Date(Date.UTC(2024, 3, 4, 14, 0, 0)));
47-
}
48-
} else {
49-
/**
50-
* the date prop returns in the following format: "2023-11-21 23:56"
51-
* we have convert it to be usable for the js Date object
52-
*/
53-
const dateArray = date.split(' ');
54-
55-
setCountdownDate(new Date(`${dateArray[0]}T${dateArray[1]}`));
56-
}
32+
const blokDateArray = date.split(' ');
33+
const dateArray = blokDateArray[0].split('-');
34+
const timeArray = blokDateArray[1].split(':');
35+
const blokDateObj =
36+
new Date(`${dateArray[0]}-${dateArray[1]}-${dateArray[2]}T${timeArray[0]}:${timeArray[1]}`);
37+
const utcOffset = blokDateObj.getTimezoneOffset();
38+
const utcDateObj = new Date(blokDateObj.getTime() + utcOffset);
39+
setCountdownDate(new Date(Date.UTC(
40+
utcDateObj.getFullYear(),
41+
utcDateObj.getMonth(),
42+
utcDateObj.getDate(),
43+
timeArray[0],
44+
timeArray[1]
45+
)))
5746
}
5847
}, [countdownDate, setCountdownDate]);
5948

@@ -70,7 +59,7 @@ const Countdown = ({ blok }) => {
7059
<CountdownPie
7160
className={daysClassName}
7261
descriptor={getDescriptorString('day', days)}
73-
percent={noTime ? 0 : (days / 29) * 100}
62+
percent={noTime ? 0 : (days / dayPieRange) * 100}
7463
>
7564
{noTime ? 0 : days}
7665
</CountdownPie>

0 commit comments

Comments
 (0)