Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/televisionninja/daily-intervals
Create intervals that are based on the time
https://github.com/televisionninja/daily-intervals
intervals javascript
Last synced: about 1 month ago
JSON representation
Create intervals that are based on the time
- Host: GitHub
- URL: https://github.com/televisionninja/daily-intervals
- Owner: TelevisionNinja
- License: mit
- Created: 2021-03-18T00:58:48.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2022-11-14T15:05:44.000Z (about 2 years ago)
- Last Synced: 2024-11-03T03:32:34.311Z (about 2 months ago)
- Topics: intervals, javascript
- Language: JavaScript
- Homepage:
- Size: 34.2 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# daily-intervals
Create intervals that are based on the time## Usage
```javascript
import {
setDailyInterval,
clearDailyInterval
} from 'daily-intervals';/*
This executes every 2 hours
The intervals start at 1 amMeaning the times it will execute will be:
This is the given starting time
|
V
..., 21:00, 23:00, 1:00, 3:00, 5:00, 7:00, ...The interval will not wait until the current time has reached the starting time to execute the callback function. The closest interval will be used as the time to execute the function.
Example:
Current time: 22:34
Execution time Starting time
| |
V V
..., 21:00, 23:00, 1:00, 3:00, 5:00, 7:00, ...The callback function will be executed at 23:00 in this example
*/
setDailyInterval(() => {
console.log('hello world');
}, 2 * 60, '1:00');//------------------
// similar usage to setTimeout and setIntervalsetDailyInterval(() => {
console.log('Hello world 1');
});setDailyInterval(() => {
console.log('Hello world 2');
}, 2);setDailyInterval(() => {
console.log('Hello world 3');
}, 3, '3:33');setDailyInterval((a, b, c) => {
console.log(a, b, c);
}, 4, '4:44', '1', '2', '3');setDailyInterval("console.log('Hello world 4');");
//------------------
// clearing a dailyIntervalconst id = setDailyInterval(() => console.log('cleared'));
clearDailyInterval(id);
```