Подскажите пожалуста как остановить таймер когда он доходит до 00:00:00, сейчас он идет дальше в минус. Спасибо, в js я новичек
function timer() {
const newData = new Date('Mar 31 2023 00:00:00');
const daysVal = document.querySelectorAll('.time-count__days .time-count__val');
const hoursVal = document.querySelectorAll('.time-count__hours .time-count__val');
const minutesVal = document.querySelectorAll('.time-count__minutes .time-count__val');
const secondsVal = document.querySelectorAll('.time-count__seconds .time-count__val');
const normalize = (n) => n <= 9 ? `0${n}` : n
const timeCount = () => {
let now = new Date();
let leftUntil = newData - now;
let days = normalize(Math.floor(leftUntil / 1000 / 60 / 60 / 24));
let hours = normalize(Math.floor(leftUntil / 1000 / 60 / 60) % 24);
let minutes = normalize(Math.floor(leftUntil / 1000 / 60) % 60);
let seconds = Math.floor(leftUntil / 1000) % 60;
daysVal.forEach(dayVal => {
dayVal.innerHTML = days.toString().replace(/\d/gi, (substring) => `<span>${substring}</span>`);
});
hoursVal.forEach(hourVal => {
hourVal.innerHTML = hours.toString().replace(/\d/gi, (substring) => `<span>${substring}</span>`);
});
minutesVal.forEach(minuteVal => {
minuteVal.innerHTML = minutes.toString().replace(/\d/gi, (substring) => `<span>${substring}</span>`);
});
secondsVal.forEach(secondVal => {
secondVal.innerHTML = seconds.toString().replace(/\d/gi, (substring) => `<span>${substring}</span>`);
});
};
timeCount();
setInterval(timeCount, 1000);
}
timer()
.time-count__content{
display: flex;
}
.time-count__item{
margin: 0px 10px;
}
.time-count__val{
font-size: 40px;
}
.time-count__text{
text-align:center;
}
<div class="time-count">
<div class="time-count__content">
<div class="time-count__item time-count__days">
<div class="time-count__val">00</div>
<div class="time-count__text">д</div>
</div>
<div class="time-count__item time-count__hours">
<div class="time-count__val">00</div>
<div class="time-count__text">ч</div>
</div>
<div class="time-count__item time-count__minutes">
<div class="time-count__val">00</div>
<div class="time-count__text">м</div>
</div>
<div class="time-count__item time-count__seconds">
<div class="time-count__val">00</div>
<div class="time-count__text">с</div>
</div>
</div>
</div>