Skip to content

Instantly share code, notes, and snippets.

@yinxin630
Last active August 16, 2019 09:00
Show Gist options
  • Select an option

  • Save yinxin630/c6fe884d11b35a9b86a5cf5dffaff450 to your computer and use it in GitHub Desktop.

Select an option

Save yinxin630/c6fe884d11b35a9b86a5cf5dffaff450 to your computer and use it in GitHub Desktop.
|-|&tag=code
// npm i --save chalk draftlog
const chalk = require('chalk');
require('draftlog').into(console);
function getLog() {
const now = new Date();
const goHome = new Date();
goHome.setHours(18);
goHome.setMinutes(0);
goHome.setSeconds(0);
const duration = goHome.getTime() - now.getTime();
if (duration <= 0) {
return chalk.red(`下班啦~ 赶紧滚回去`);
}
const hour = Math.floor(duration / 1000 / 60 / 60);
const minute = Math.floor(duration / 1000 / 60 % 60);
const second = Math.floor(duration / 1000 % 60);
return `>> 距离下班还有 ${chalk.green(`${hour ? hour + '小时' : ''}${minute ? minute + '分钟' : ''}${second ? second + '秒' : ''}`)}`;
}
const update = console.draft(getLog());
setInterval(() => {
update(getLog());
}, 1000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment