All Projects → SeverinDK → Moment Timer

SeverinDK / Moment Timer

Licence: mit
Timer plugin for Moment.js that allows creation of setInterval and setTimeout-like timers.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Moment Timer

cron-schedule
A zero-dependency cron parser and scheduler for Node.js, Deno and the browser.
Stars: ✭ 28 (-71.43%)
Mutual labels:  timer, interval
AdvancedTimer
AdvancedTimer implementation for Xamarin.Forms This repo is no longer maintained. New repo available.
Stars: ✭ 40 (-59.18%)
Mutual labels:  timer, interval
chronoman
Utility class to simplify use of timers created by setTimeout
Stars: ✭ 15 (-84.69%)
Mutual labels:  timer, interval
Time4j
Advanced date, time and interval library for Java with sun/moon-astronomy and calendars like Chinese, Coptic, Ethiopian, French Republican, Hebrew, Hijri, Historic Christian, Indian National, Japanese, Julian, Korean, Minguo, Persian, Thai, Vietnamese
Stars: ✭ 328 (+234.69%)
Mutual labels:  interval, duration
Placeline Nextjs
HyperTrack Placeline web application sample using NextJS, Ant-Design, Styled-Components, and Heroku
Stars: ✭ 88 (-10.2%)
Mutual labels:  moment
Csnackbar
This is a wrapper for android Snackbar. Which giving support to change Snackbar color, duration, message or even it's content view with a custom view.
Stars: ✭ 76 (-22.45%)
Mutual labels:  duration
Iso8601
Ruby parser to work with ISO8601 dateTimes and durations — http://en.wikipedia.org/wiki/ISO_8601
Stars: ✭ 70 (-28.57%)
Mutual labels:  interval
Swiftytimer
Swifty API for NSTimer
Stars: ✭ 1,143 (+1066.33%)
Mutual labels:  timer
Brein Time Utilities
Library which contains several time-dependent data and index structures (e.g., IntervalTree, BucketTimeSeries), as well as algorithms.
Stars: ✭ 94 (-4.08%)
Mutual labels:  interval
Dipstick
Configurable metrics toolkit for Rust applications
Stars: ✭ 92 (-6.12%)
Mutual labels:  timer
Rc Datetime Picker
React component for datetime picker by Moment.js
Stars: ✭ 85 (-13.27%)
Mutual labels:  moment
Steamcmd Autoupdate Any Gameserver
Windows SteamCMD to autoupdate and install any game server steam cmd settings configurable lots of useful features. This batch script will keep your game servers automaticly updated updating intervals announce the server is shutting down for updates etc all configurable.
Stars: ✭ 77 (-21.43%)
Mutual labels:  interval
Angular Bootstrap Datetimepicker
Native Angular date/time picker component styled by Twitter Bootstrap
Stars: ✭ 1,289 (+1215.31%)
Mutual labels:  moment
Git Repo Watcher
A simple bash script to watch a git repository and pull upstream changes if needed.
Stars: ✭ 73 (-25.51%)
Mutual labels:  interval
Timer
This is a simple rxjava2/rxjava3/kotlin-flow timer
Stars: ✭ 93 (-5.1%)
Mutual labels:  timer
Flip Clock
A flip clock, timer and countdown made with Polymer
Stars: ✭ 69 (-29.59%)
Mutual labels:  timer
Timerlab
⏰ A simple and customizable timer
Stars: ✭ 84 (-14.29%)
Mutual labels:  timer
Moment Business
Utilities for work days in Moment. (Western workweeks only.)
Stars: ✭ 91 (-7.14%)
Mutual labels:  moment
Hackaru
Simple, cross-platform time tracking application
Stars: ✭ 82 (-16.33%)
Mutual labels:  timer
Humanizeduration.js
361000 becomes "6 minutes, 1 second"
Stars: ✭ 1,234 (+1159.18%)
Mutual labels:  duration

moment-timer

NPM version NPM downloads MIT License


Synopsis

This is a Moment.js plugin that allows the use of timers, which offer much more control than the native JavaScript timers. It's basically a rewrite of JavaScripts own setInterval and setTimeout. For an example, see the example folder or read the Usage section below.


Installation

Npm

npm install moment-timer

Bower

bower install moment-timer

CDN

<script src="https://cdn.jsdelivr.net/npm/moment-timer/lib/moment-timer.js"></script>

Browser

<script src="path/to/moment-timer.js"></script>

When using this plugin in the browser, be sure to include moment.js on your page first.


Attributes

(bool) start

new moment.duration(1000).timer({ start: true }, callback);

Setting this attribute to true will cause the timer to start once instantiated.


(bool) loop

new moment.duration(1000).timer({ loop: true }, callback);

Setting this attribute to true will cause the timer to loop/restart once a duration is complete.


(int | moment.duration) wait

new moment.duration(1000).timer({ wait: 5000 }, callback);
new moment.duration(1000).timer({ wait: moment.duration(5, 'seconds') }, callback);

Setting this attribute will cause the timer to wait for a specified amount of time before starting it's duration. This is kind of an extra first duration. Imagine a timer that runs every second. Setting the wait attribute to 5000 / 5 seconds, means it waits that long and then starts acting like a normal timer would. Notice that this attribute accepts both int and moment.duration .


(bool) executeAfterWait

new moment.duration(1000).timer({ wait: 5000, executeAfterWait: true }, callback);

Setting this attribute to true will cause the callback function to be called after the wait duration has ended. This is a way to make sure the callback is executed even before the timer starts.


Functions

.start()

let timer = new moment.duration(1000).timer(callback);
timer.start();

This function will cause the timer to start. It can be used if the start attribute has not been set or if the timer has been stopped.


.stop()

let timer = new moment.duration(1000).timer({ start: true }, callback);
timer.stop();

This function will cause the timer to stop. It can be used if timer has been started to halt it.


.duration(int | moment.duration)

let timer = new moment.duration(1000).timer(callback);
timer.duration(5000);
timer.duration(moment.duration(5, "seconds");

This function can be used to change the duration the timer was instantiated with.


.getDuration()

let timer = new moment.duration(1000).timer(callback);
timer.getDuration();

This function will return the current duration of a timer. In this case it will return 1000.


.getRemainingDuration()

let timer = new moment.duration(1000).timer(callback);
timer.getRemainingDuration();

This function will return the remaining duration of a timers cycle. In this case, imagine that the timer has been running for 500ms and we call .getRemainingDuration() on it, in this example it will return 500, since half of the cycle has completed.


.isStopped()

let timer = new moment.duration(1000).timer(callback);
timer.start();
timer.isStopped();  // false
timer.stop();
timer.isStopped();  // true

This function can be used to see if the timer has been stopped by the .stop() function.


.isStarted()

let timer = new moment.duration(1000).timer(callback);
timer.start();
timer.isStarted();  // true
timer.stop();
timer.isStarted();  // false

This function can be used to see if the timer has been started by the .start() function. If this function is called on a timer that has reached the end of it's duration and does not loop, it will also return false as if the timer has not yet been started.


Feel free to open a new issue or create a pull request if you can think of other useful attributes or functions.


Changelog

v1.3.1

Added nodejs example and increased minimum version of moment. See https://github.com/SeverinDK/moment-timer/issues/26

v1.3.0

Fixed issue where .stop() would not stop the timer. See https://github.com/SeverinDK/moment-timer/issues/20

v1.2.3

Relaxed moment dependency.

v1.2.2

Removed debug console.log

v1.2.1

Updated readme with better documentation and added a new isStarted function.

v1.2.0

Added module loading!

v1.1.5

Added getDuration and executeAfterWait attribute.

v1.1.4

Added isStopped function.

v1.1.3:

...

v1.1.2:

Fixed stop function. It still had an old unused paused variable instead of the new stopped variable. Fixing this will ensure that stopping and starting the timer will not cause any problems.

v1.1.1:

Cleaned up some things, fixed a remainingDuration bug and added an internal clearTimer function.

v1.1.0:

Changed setDuration to duration and added actual moment.duration support to it. Deprecated error message on setDuration will be removed in next release.

v1.0.0:

Initial Release.


Contributing

You are always welcome to contribute to this repository. Create your own branch, make the changes you wish to see and create a pull request that we can have a look at. If the changes make sense and the quality of code is good enough, then it will be merged into the master branch so other people can use it.

A full list of contributers for moment-timer.js can be found here.


License

Moment-timer.js is freely distributable under the terms of the MIT license.


Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].