"use client"; import React, { useEffect } from "react"; const TimeClock: React.FC = () => { useEffect(() => { const numbers = [ [1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1], // 0 [1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1], // 1 [1, 0, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 0, 1], // 2 [1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1], // 3 [1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 1, 1, 1, 1, 1], // 4 [1, 1, 1, 0, 1, 1, 0, 1, 0, 1, 1, 0, 1, 1, 1], // 5 [1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 0, 1, 1, 1], // 6 [1, 0, 0, 0, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0], // 7 [1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1], // 8 [1, 1, 1, 0, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1], // 9 ]; const blocks: Array = []; const digits = Array.from(document.querySelectorAll(".block")); for (let i = 0; i < 4; i++) { blocks.push(digits.slice(i * 15, i * 15 + 15)); } const setNum = (block: Array, num: number) => { const n = numbers[num]; for (let i = 0; i < block.length; i++) { block[i].classList[n[i] === 1 ? "add" : "remove"]("active"); } }; const time = { s: "", m: "", h: "", p: 0, }; // time loop const animator = () => { const d = new Date(); let h = d.getHours().toString(), m = d.getMinutes().toString(), s = d.getSeconds().toString(); s = s.length === 1 ? "0" + s : s; m = m.length === 1 ? "0" + m : m; h = h.length === 1 ? "0" + h : h; if (s !== time.s) { for (let i = 0; i < digits.length; i++) { const d = digits[i]; if (i === +s) { d.classList.add("second"); if (time.p !== null) digits[time.p].classList.remove("second"); time.p = i; time.s = s; } } } if (m !== time.m) { setNum(blocks[2], parseInt(Array.from(m)[0])); setNum(blocks[3], parseInt(Array.from(m)[1])); time.m = m; } if (h !== time.h) { setNum(blocks[0], parseInt(Array.from(h)[0])); setNum(blocks[1], parseInt(Array.from(h)[1])); time.h = h; } window.requestAnimationFrame(animator); }; // init window.requestAnimationFrame(animator); // toggle button const d = new Date(); const days = ["Dimanche", "Lundi", "Mardi", "Mercredi", "Jeudi", "Vendredi", "Samedi"]; const months = [ "Janvier", "Février", "Mars", "Avril", "Mai", "Juin", "Juillet", "Août", "Septembre", "Octobre", "Novembre", "Décembre", ]; const lib_d = days[d.getDay()]; const lib_m = months[d.getMonth()]; const lib_n = d.getDate(); const lib_y = d.getFullYear(); document.getElementById("datelib")!.innerHTML = lib_d + " " + lib_n + " " + lib_m + " " + lib_y; }, []); return ( <>
); }; export default TimeClock;