{"id":16581637,"url":"https://github.com/onweru/javascript-timer","last_synced_at":"2025-03-06T01:25:42.634Z","repository":{"id":161193241,"uuid":"217363466","full_name":"onweru/javascript-timer","owner":"onweru","description":"A countdown timer that converts javascript timestamp to days, hours, minutes and seconds","archived":false,"fork":false,"pushed_at":"2019-10-26T16:39:02.000Z","size":4,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-16T11:26:35.540Z","etag":null,"topics":["countdown-javascript","countdown-timer","countdowntimer","javascript","javascript-library","timer"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/onweru.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-10-24T18:08:48.000Z","updated_at":"2019-10-26T16:51:44.000Z","dependencies_parsed_at":null,"dependency_job_id":"6e2819d3-0a45-4c9f-81a5-d5568457592c","html_url":"https://github.com/onweru/javascript-timer","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/onweru%2Fjavascript-timer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/onweru%2Fjavascript-timer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/onweru%2Fjavascript-timer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/onweru%2Fjavascript-timer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/onweru","download_url":"https://codeload.github.com/onweru/javascript-timer/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":242129663,"owners_count":20076448,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["countdown-javascript","countdown-timer","countdowntimer","javascript","javascript-library","timer"],"created_at":"2024-10-11T22:29:35.072Z","updated_at":"2025-03-06T01:25:42.623Z","avatar_url":"https://github.com/onweru.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Javascript countdown timer\nIt converts a javascript timestamp into days, hours, minutes and seconds\n\n## Install\n### Using NPM OR YARN\n\n`npm install javascript-timer`\n\nOR\n\n`yarn add javascript-timer`\n\n## Usage\n\nYou can either include *index.js* on your html file, or you can simply copy its contents to you main js file\n\n```javascript\n\n// use a future date (keep it reasonable)\n\nconst timestamp = Date.parse(\"2022-04-11T10:20:30Z\"); // return a timestamp in ms\n\nconst timeObject = calculateTimeUntil(timestamp) \n/*\n  returns an object with 4 key-value pairs i.e \n  {\n    days: Number, \n    hrs: Number,\n    mins: Number, \n    seconds: Number\n  }\n*/\n```\n\nYou can then use `setInterval` to populate a countdown elements(s) on your DOM\n\n### Example\n\n```html\n\u003cscript src = '/js/helpers.js'\u003e\u003c/script\u003e\n\u003cdiv class = 'timer'\u003e\n  \u003cdiv class = 'timer_value' id = 'days'\u003e\n    \u003cspan class = 'timer_unit'\u003e\u003c/span\u003e\n    \u003clabel class = 'timer_label'\u003eDays\u003c/label\u003e\n  \u003c/div\u003e\n  \u003cspan class = 'timer_divider'\u003e:\u003c/span\u003e\n  \u003cdiv class = 'timer_value' id = 'hrs'\u003e\n    \u003cspan class = 'timer_unit'\u003e\u003c/span\u003e\n    \u003clabel class = 'timer_label'\u003eHours\u003c/label\u003e\n  \u003c/div\u003e\n  \u003cspan class = 'timer_divider'\u003e:\u003c/span\u003e\n  \u003cdiv class = 'timer_value' id = 'mins'\u003e\n    \u003cspan class = 'timer_unit'\u003e\u003c/span\u003e\n    \u003clabel class = 'timer_label'\u003eMinutes\u003c/label\u003e\n  \u003c/div\u003e\n  \u003cspan class = 'timer_divider'\u003e:\u003c/span\u003e\n  \u003cdiv class = 'timer_value' id = 'seconds'\u003e\n    \u003cspan class = 'timer_unit'\u003e\u003c/span\u003e\n    \u003clabel class = 'timer_label'\u003eSeconds\u003c/label\u003e\n  \u003c/div\u003e\n\u003c/div\u003e\n\n\u003cscript\u003e\n  function fillUnits(labels, obj) {\n    labels.forEach(label =\u003e {\n      let id, num;\n      id = label.id;\n      num = obj[id];\n      num = num \u003c 10 ? `0${num}` : num;\n      label.children[0].textContent = num;\n    });\n  }\n\n  function populateCountDown(timer, num) {\n    let labels, timeTo;\n    timeTo = calculateTimeUntil(num);\n    labels = Array.from(timer.children).filter(function(label){\n      return label.classList.contains('timer_value')\n    });\n    fillUnits(labels, timeTo)\n  }\n\n  (function() {\n    const timer = document.currentScript.previousElementSibling;\n    const timestamp = Date.parse(\"2022-04-11T10:20:30Z\"); // return a timestamp in ms\n    populateCountDown(timer, timestamp);\n    setInterval(function(){\n      populateCountDown(timer,timestamp)\n    }, 1000);            \n  })();                  \n                  \n\u003c/script\u003e\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fonweru%2Fjavascript-timer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fonweru%2Fjavascript-timer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fonweru%2Fjavascript-timer/lists"}