bunkat / later

A javascript library for defining recurring schedules and calculating future (or past) occurrences for them. Includes support for using English phrases and Cron schedules. Works in Node and in the browser.

Home Page:http://bunkat.github.io/later/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Show how much time is left after later.js text parser applied

sergibondarenko opened this issue · comments

How to display what time is left after the later.js text parser applied?

For example, I want to know it before the setInterval started.

const later = require('later');

later.date.localTime();
const schedule = later.parse.text('at 12:40');

later.setInterval(() => {
    console.log('executed!');
}, schedule);

StackOverflow question.

Looks like you've accepted an answer over at StackOverflow, but in case anyone else is reading this, I use moment.js with the fromNow() function to show, in a human readable form, how long until the next occurrence:

next = later.schedule(mySchedule).next()
timeLeft = moment(next).fromNow()
console.log(timeLeft) // 'in 20 minutes'