{"id":23714805,"url":"https://github.com/happycoda/chronos","last_synced_at":"2025-07-13T17:37:12.913Z","repository":{"id":57198560,"uuid":"51032284","full_name":"happyCoda/chronos","owner":"happyCoda","description":"A simple and lightweight JavaScript timer","archived":false,"fork":false,"pushed_at":"2017-04-01T01:09:42.000Z","size":80,"stargazers_count":10,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-10-18T23:17:24.755Z","etag":null,"topics":["javascript-timer","timer"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/happyCoda.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-02-03T21:36:19.000Z","updated_at":"2018-02-12T19:30:58.000Z","dependencies_parsed_at":"2022-09-11T06:50:37.732Z","dependency_job_id":null,"html_url":"https://github.com/happyCoda/chronos","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/happyCoda%2Fchronos","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/happyCoda%2Fchronos/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/happyCoda%2Fchronos/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/happyCoda%2Fchronos/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/happyCoda","download_url":"https://codeload.github.com/happyCoda/chronos/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":231913315,"owners_count":18444930,"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":["javascript-timer","timer"],"created_at":"2024-12-30T20:38:05.091Z","updated_at":"2024-12-30T20:38:05.902Z","avatar_url":"https://github.com/happyCoda.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# chronos\n\u003e A JavaScript timer with simple and convenient API\n\n## Installation\nLibrary can be installed via [Bower](http://bower.io/) package manager:\n\n```shell\nbower i chronosjs\n```\n\nAn `npm` package also available:\n\n```shell\n$ npm install chronos-js\n```\n\nOr you can clone a git repo:\n\n```shell\ngit clone https://github.com/happyCoda/chronos.git\n```\n\n### Getting started\nJust as simple as is.\n\n```js\nvar chr = new Chronos();\n\nchr.start({\n  direction: 'forward',\n  callback: function (chr) {\n    console.log(chr.composeString());\n  }\n});\n```\n\n### Usage\n\nChronos.js supports `CommonJS` and `AMD` modules. However, library can be used directly in browser, since it exposes chronos object globally in case when no module system detected.\n\n\n### API\n\n#### start\n\nLibrary entry point. Here all the gears and sprocket starts running.\n\n```js\nchr.start({\n  duration: 10000,\n  callback: function (chrInst) {\n    console.log(chrInst.composedToArray(chrInst.composeString())[2] + ' seconds left before explosion!');\n  }\n});\n```\n\nStart method expects to get an `Object` as an argument. This object can must have some of these configuration properties – `direction`, `callback`, `duration` and `timeString`. The first one, `direction` decides whether Chronos will act like a regular clock, or like a countdown timer. If direction is omitted, then `Chronos` will work like a timer. The `callback` option specifies a function callback which will be invoked every second with Chronos instance passed as an argument. `duration` represents time in milliseconds for a timer set up. If you have your setup time represented by a unix timestamp, you can pass this time as `timeString` property instead of `duration`.\n\n#### stop\n\nChronos last stop.\n\n```js\nchr.stop();\n```\n\nThis method does exactly as it says. If you need to stop Chronos for time counting, just call `stop`.\n\n#### composeString\n\nAssembles current time value into a string.\n\n```js\nChronos.composeString();\n```\n\n#### composedToArray\n\nConverts composed string into a usable array of time units (hours, mins, secs).\n\n```js\nChronos.composedToArray(composedString);\n```\n\n### Examples\n\n#### Create timer and write time to the page\n\nIn this example, we start Chronos with `forward` option and update changed time every second:\n\n```js\nvar clockDisplay = document.querySelector('.clock-display');\n\nChronos.start({\n  direction: 'forward',\n  callback: function (chr) {\n    clockDisplay.textContent = chr.composeString();\n  }\n});\n```\n\n#### Counting time backwards\n\nCreating a reverse timer:\n\n```js\nvar $timeLeft = $('.time-left'),\ntimeString = new Date(Date.now() + 60 * 60 * 1000);\n\nChronos.start({\n  direction: 'backward',\n  timeString: timeString\n  callback: function (chr) {\n    timeLeft.text(chr.composeString());\n  }\n});\n```\n\n## Release History\n* 2017-02-15   v0.5.5   CommonJS support added.\n* 2016-02-06   v0.5.4   Switched from singleton to constructor. Now multiple Chronos instances allowed.\n* 2016-02-06   v0.4.4   Added support for timer duration in milliseconds.\n* 2016-02-06   v0.4.3   AMD support refactor.\n* 2016-02-05   v0.4.2   Case when backwards time is past fix.\n* 2016-02-05   v0.4.1   Chronos time runner added.\n* 2016-02-04   v0.3.0   Forward counting logic added.\n* 2016-02-04   v0.2.3   Docs and bower integration.\n* 2016-02-04   v0.2.2   adjustUnits method bug fixed.\n* 2016-02-04   v0.2.1   Code refactor.\n* 2016-02-04   v0.2.0   composedToArray method added \u0026 copyrights.\n* 2016-02-04   v0.1.0   First official release. Tests and main logic.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhappycoda%2Fchronos","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhappycoda%2Fchronos","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhappycoda%2Fchronos/lists"}