{"id":25449300,"url":"https://github.com/dpfens/stopwatch","last_synced_at":"2026-04-13T22:33:59.629Z","repository":{"id":90663371,"uuid":"263752994","full_name":"dpfens/stopwatch","owner":"dpfens","description":"A more functional stopwatch for Javascript","archived":false,"fork":false,"pushed_at":"2024-09-04T04:18:45.000Z","size":20277,"stargazers_count":1,"open_issues_count":8,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-05-16T08:43:57.221Z","etag":null,"topics":["javascript","nodejs","splits","stopwatch","time","web"],"latest_commit_sha":null,"homepage":"https://dpfens.github.io/stopwatch","language":"TypeScript","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/dpfens.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,"zenodo":null}},"created_at":"2020-05-13T22:03:15.000Z","updated_at":"2023-09-10T05:43:26.000Z","dependencies_parsed_at":"2025-02-17T20:41:36.210Z","dependency_job_id":null,"html_url":"https://github.com/dpfens/stopwatch","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/dpfens/stopwatch","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dpfens%2Fstopwatch","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dpfens%2Fstopwatch/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dpfens%2Fstopwatch/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dpfens%2Fstopwatch/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dpfens","download_url":"https://codeload.github.com/dpfens/stopwatch/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dpfens%2Fstopwatch/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31774032,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-13T20:17:16.280Z","status":"ssl_error","status_checked_at":"2026-04-13T20:17:08.216Z","response_time":93,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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","nodejs","splits","stopwatch","time","web"],"created_at":"2025-02-17T20:27:31.090Z","updated_at":"2026-04-13T22:33:59.599Z","avatar_url":"https://github.com/dpfens.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Stopwatch\nA simple Javascript stopwatch.\nThe stopwatch records metadata about the stopwatch execution, such as when the stopwatch was started, stopped, and resumed.  All stopwatch measurements are taken using UTC time, to account for timezone changes.  The stopwatch also records when each split was taken and if/when the split was modified.\n\n\n## Usage\n\n### Basic usage\n```javascript\nvar stopwatchInstance  = new BasicStopWatch();\n\nstopwatchInstance.start();\n```\n\nto get the total duration:\n```javascript\nvar currentTotalDuration = stopwatchInstance.totalDuration();\n```\n\nTo stop the stopwatch:\n```javascript\nvar totalDuration = stopwatchInstance.stop()\n```\n\nTo resume a stopped stopwatch:\n```javascript\nstopwatchInstance.resume();\n```\n\nTo reset a stopwatch, use the `reset` method:\n```javascript\nstopwatchInstance.reset();\n```\n\nBut, let's say that you (or an end-user) hit the `start` button too early/late.  Use the `setStartValue` with the correct unix-timestamp of when the stopwatch should have started to correct the stopwatch.\n```javascript\nvar correctStart = new Date(2020, 13, 18),\n    correctStartTimestamp = correctStart.getTime();\nstopwatchInstance.setStartValue(correctStartTimestamp);\n```\n**NOTE**:  `setStartValue` will modify the first `split` and `lap` to account for the difference between the old `startValue` and the new one.  The modification will be reflected in the `metadata.lastModified` date.\n\nThis can also be done for the stop using `setStopValue` function:\n```javascript\nvar correctStop = new Date(2020, 13, 22),\n    correctStopTimestamp = correctStart.getTime();\nstopwatchInstance.setStopValue(correctStopTimestamp);\n```\n\n**NOTE**:  `setStopValue` will modify the last `split` and `lap` to account for the difference between the old `stopValue` and the new one.  The modification will be reflected in the `metadata.lastModified` date.\n\n### Splits\nTo use a stopwatch that support splits, using the `SplitStopwatch`:\n```javascript\nvar stopwatchInstance = new SplitStopwatch();\n```\n\nTo take a split for the current time use the `addSplit` method:\n```javascript\nvar splitValue = stopwatchInstance.addSplit();\n```\n\nTo find the duration of the stopwatch since the last split, use the `splitDuration` method.  The value will be returned in milliseconds:\n```javascript\ncurrentSplitDuration = stopwatchInstance.splitDuration();\n```\n\nTo read all the existing splits taken on the stopwatch:\n```javascript\nfor (var i = 0; i \u003c stopwatchInstance.splits.length; i++) {\n    var splitValue = stopwatchInstance.splits[i];\n    console.log(splitValue);\n}\n```\n\nUse the `update` method to change a split at a given `index` to a given `value`.  This method will recalculate the next split to account for the change to the previous split:\n```javascript\nvar index = 1;\n    value = 257000; // 4 minutes, 17 seconds\nstopwatchInstance.update(index, value);\n```\nwhich will set the second split to `257000` milliseconds\n\nTo add a new split to the stopwatch, use the `addRelativeSplit(value)`, where the `value` is the number of milliseconds since the start of the stopwatch:\n```javascript\nvar value = 240000;\nstopwatchInstance.addRelativeSplit(value);\n```\nIf there is a split after the one specified, its duration will be modified to account for the newly-added split.\n\nTo delete a split, use the `removeSplit` method, where the `index` specifies the index of the split to remove.  This method will also modify the next split to account for the change.\n\n```javascript\nvar index = 2;\nstopwatchInstance.removeSplit(index);\n```\n\n### Laps\nTo record laps, use the `LapStopwatch`:\n```javascript\nvar lapDistance = 400,\n    lapUnits = 'Meters',\n    stopwatchInstance = new LapStopwatch(lapDistance, lapUnits);\n```\n\nTo record a lap, use the `addLap` method:\n```javascript\nvar lap = stopwatchInstance.addLap();\n```\n\nto get the current lap duration, use the `lapDuration` method:\n```javascript\nvar currentLapDuration = stopwatchInstance.lapDuration();\n```\n\n### State\nTo get metadata about a stopwatch, using the `metadata` property:\n```javascript\nvar metadata = stopwatch.metadata;\n```\n\nTo get the start time of a stopwatch, use the `startValue` property:\n```javascript\nvar startTimestamp = stopwatch.startValue;\n```\n\nTo find out if the stopwatch is currently being used to time something, use the `isRunning` method:\n```javascript\nif (stopwatchInstance.isRunning()) {\n    stopwatchInstance.stop();\n}\n```\n\n\nTo find out if the stopwatch has been used and not been reset, use the `isActive` method:\n```javascript\nif (!stopwatchInstance.isActive()) {\n    stopwatchInstance.start();\n}\n```\n\nTo iterate over existing splits in the stopwatch:\n```javascript\nfor (var i = 0; i \u003c splitStopwatch.splits.length; i++) {\n  var split = splitStopwatch.splits[i];\n}\n```\n\nTo iterate over existing laps in the stopwatch:\n```javascript\nfor (var i = 0; i \u003c lapStopwatch.laps.length; i++) {\n  var lap = lapStopwatch.laps[i];\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdpfens%2Fstopwatch","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdpfens%2Fstopwatch","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdpfens%2Fstopwatch/lists"}