{"size": 1414, "ext": "js", "max_stars_repo_path": "goit-js-hw-11/goit-js-hw-11-timer/index.js", "max_stars_repo_name": "Irina-vn/js-hw", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "goit-js-hw-11/goit-js-hw-11-timer/index.js", "max_issues_repo_name": "Irina-vn/js-hw", "max_issues_repo_issues_event_min_datetime": "2021-03-11T02:09:44.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-27T08:30:22.000Z", "max_forks_repo_path": "goit-js-hw-11/goit-js-hw-11-timer/index.js", "max_forks_repo_name": "Irina-vn/js-hw", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": 4, "max_forks_count": null, "avg_line_length": 34.487804878, "max_line_length": 85, "alphanum_fraction": 0.6209335219}
class CountdownTimer {
    constructor(selector, targetDate) {
        this.selector = selector;
        this.targetDate = targetDate;
    }
    getTime() {
        const startDate = Date.now();
        this.timerId = setInterval(() => {
            const currentDate = Date.now(); ///Дата в реальном времени
            const targetDate = Date.parse(this.targetDate);
            const deltaTime = targetDate - currentDate;

            updateClockface(deltaTime);
        }, 1000);
    }
};

const timer1 = new CountdownTimer('#timer-1', 'July 17, 2021');
timer1.getTime();

const daysValue = document.querySelector('.value[data-value="days"]');
const hoursValue = document.querySelector('.value[data-value="hours"]');
const minsValue = document.querySelector('.value[data-value="mins"]');
const secsValue = document.querySelector('.value[data-value="secs"]');

function updateClockface(time) {

    const days = pad(Math.floor(time / (1000 * 60 * 60 * 24)));
    const hours = pad(Math.floor((time % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60)));
    const mins = pad(Math.floor((time % (1000 * 60 * 60)) / (1000 * 60)));
    const secs = pad(Math.floor((time % (1000 * 60)) / 1000));

    daysValue.textContent = `${days}`;
    hoursValue.textContent = `${hours}`;
    minsValue.textContent = `${mins}`;
    secsValue.textContent = `${secs}`;
}

function pad(value) {
    return String(value).padStart(2, '0');
}