1
1
"use client" ;
2
2
3
3
import { conferenceDateTime } from "@/data/timing" ;
4
- import moment from "moment" ;
5
4
import Wave from "@/assets/images/home/count-down-wave.svg" ;
6
5
import WaveMobile from "@/assets/images/home/count-down-wave-mobile.svg" ;
7
6
import Image from "next/image" ;
@@ -24,26 +23,40 @@ export default function CountDown() {
24
23
< HiOutlineClock className = "absolute inset-y-0 -z-10 size-60 text-zinc-800/20 lg:size-[460px]" />
25
24
26
25
< div className = "flex flex-col gap-2 text-center text-2xl lg:text-4xl" >
27
- < strong className = "font-bold" > ساعتها رو دوباره کوک کردیم</ strong >
28
- < span className = "text-zinc-400" > اینجا ثانیهها ارزشمندند</ span >
26
+ < strong className = "font-bold" > دلتنگتون هستیم</ strong >
27
+ < span className = "text-zinc-400" >
28
+ به خاطر خاطرههای زیبایی که ساختیم
29
+ </ span >
29
30
</ div >
30
31
< CountDownTimer />
31
32
< p className = "text-xl text-zinc-400 lg:mt-8 lg:text-3xl/snug" >
32
- تا شروع دومین همایش فرانت چپتر
33
+ گذشته از آخرین دورهمی حضوری
33
34
</ p >
34
35
</ section >
35
36
) ;
36
- }
37
+ }
37
38
38
39
const CountDownTimer = ( ) => {
40
+ const calculateDuration = ( start : number , end : number ) => {
41
+ const totalSeconds = Math . floor ( ( end - start ) / 1000 ) ;
42
+ const days = Math . floor ( totalSeconds / ( 3600 * 24 ) ) ;
43
+ const hours = Math . floor ( ( totalSeconds % ( 3600 * 24 ) ) / 3600 ) ;
44
+ const minutes = Math . floor ( ( totalSeconds % 3600 ) / 60 ) ;
45
+ const seconds = Math . floor ( totalSeconds % 60 ) ;
46
+
47
+ return {
48
+ days,
49
+ hours,
50
+ minutes,
51
+ seconds,
52
+ } ;
53
+ } ;
54
+
39
55
const [ now , setNow ] = useState ( Date . now ( ) ) ;
40
- const duration = moment . duration (
41
- Math . max ( moment ( conferenceDateTime ) . diff ( now ) , 0 ) ,
42
- ) ;
56
+ const conferenceDate = conferenceDateTime . getTime ( ) ;
57
+ const duration = calculateDuration ( now , conferenceDate ) ;
43
58
44
- /**
45
- * Update the current time every second
46
- */
59
+ // Update the current time every second
47
60
useEffect ( ( ) => {
48
61
const interval = setInterval ( ( ) => {
49
62
setNow ( Date . now ( ) ) ;
@@ -54,32 +67,32 @@ const CountDownTimer = () => {
54
67
const times = [
55
68
{
56
69
label : "ثانیه" ,
57
- value : duration . seconds ( ) ,
70
+ value : duration . seconds ,
58
71
} ,
59
72
{
60
73
label : "دقیقه" ,
61
- value : duration . minutes ( ) ,
74
+ value : duration . minutes ,
62
75
} ,
63
76
{
64
77
label : "ساعت" ,
65
- value : duration . hours ( ) ,
78
+ value : duration . hours ,
66
79
} ,
67
80
{
68
81
label : "روز" ,
69
- value : Math . trunc ( duration . asDays ( ) ) ,
82
+ value : duration . days ,
70
83
} ,
71
84
] ;
72
85
73
86
return (
74
87
< div className = "mt-7 flex gap-3 lg:mt-8 lg:gap-6" >
75
- { [ ...times ] . map ( ( { label, value } , index ) => (
88
+ { [ ...times ] . map ( ( { label, value } ) => (
76
89
< Fragment key = { label } >
77
90
< div className = "flex w-12 flex-col text-center lg:w-24" >
78
91
< span
79
92
className = "text-3xl/snug text-green-500 lg:text-5xl/snug"
80
93
suppressHydrationWarning
81
94
>
82
- { value . toLocaleString ( "fa-IR" ) }
95
+ { Math . abs ( value ) . toLocaleString ( "fa-IR" ) }
83
96
</ span >
84
97
< span className = "text-zinc-500 lg:text-xl" > { label } </ span >
85
98
</ div >
0 commit comments