@@ -16,7 +16,7 @@ const getDescriptorString = (descriptor, time) => {
16
16
const convertDaysToHours = ( days ) => ( days ? days * 24 : 0 ) ;
17
17
18
18
const Countdown = ( { blok } ) => {
19
- const { date, hasDays , hourPieRange , useNew } = blok ;
19
+ const { date, dayPieRange , hasDays , hourPieRange } = blok ;
20
20
const [ countdownDate , setCountdownDate ] = useState ( null ) ;
21
21
const [ days , hours , minutes , seconds ] = UseCountdown ( countdownDate ) || [ ] ;
22
22
const displayHours = hasDays ? hours : convertDaysToHours ( days ) + hours ;
@@ -29,31 +29,20 @@ const Countdown = ({ blok }) => {
29
29
30
30
useEffect ( ( ) => {
31
31
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
+ ) ) )
57
46
}
58
47
} , [ countdownDate , setCountdownDate ] ) ;
59
48
@@ -70,7 +59,7 @@ const Countdown = ({ blok }) => {
70
59
< CountdownPie
71
60
className = { daysClassName }
72
61
descriptor = { getDescriptorString ( 'day' , days ) }
73
- percent = { noTime ? 0 : ( days / 29 ) * 100 }
62
+ percent = { noTime ? 0 : ( days / dayPieRange ) * 100 }
74
63
>
75
64
{ noTime ? 0 : days }
76
65
</ CountdownPie >
0 commit comments