├── .gitignore ├── docs └── demo.png ├── README.md ├── package.json └── time.js /.gitignore: -------------------------------------------------------------------------------- 1 | # dependencies 2 | /node_modules -------------------------------------------------------------------------------- /docs/demo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CompSciLauren/work-clock/master/docs/demo.png -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Work Clock 2 | 3 | A CLI that lets user know what time they should clock out at work. Built with NodeJS. 4 | 5 | ## Demo 6 | 7 |

8 | Screenshot showing an example of the terminal output when a user runs the program 9 |

10 | 11 | ## Installation and Setup Instructions 12 | 13 | Clone this repository. You will need `node` and `npm` installed globally on your machine. 14 | 15 | Installation: 16 | 17 | `npm install` 18 | 19 | To run program: 20 | 21 | `node ./time.js` 22 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "work-clock", 3 | "version": "1.0.0", 4 | "description": "Lets user know what time they should clock out at work.", 5 | "main": "time.js", 6 | "dependencies": { 7 | "chalk": "^2.4.1", 8 | "moment": "^2.22.2" 9 | }, 10 | "devDependencies": {}, 11 | "scripts": { 12 | "test": "echo \"Error: no test specified\" && exit 1" 13 | }, 14 | "repository": { 15 | "type": "git", 16 | "url": "git+https://github.com/CompSciLauren/work-clock.git" 17 | }, 18 | "keywords": [ 19 | "work", 20 | "clock", 21 | "time", 22 | "promise", 23 | "moment", 24 | "momentjs" 25 | ], 26 | "author": "Lauren Stephenson", 27 | "license": "ISC", 28 | "bugs": { 29 | "url": "https://github.com/CompSciLauren/work-clock/issues" 30 | }, 31 | "homepage": "https://github.com/CompSciLauren/work-clock#readme" 32 | } 33 | -------------------------------------------------------------------------------- /time.js: -------------------------------------------------------------------------------- 1 | const readline = require('readline'); 2 | const moment = require('moment'); 3 | const chalk = require('chalk'); 4 | 5 | const rl = readline.createInterface({ 6 | input: process.stdin, 7 | output: process.stdout, 8 | }); 9 | 10 | const hoursToWorkToday = () => { 11 | return new Promise(resolve => { 12 | rl.question( 13 | chalk.cyan('Number of hours to work today: '), 14 | answer => { 15 | const result = answer; 16 | resolve(result); 17 | } 18 | ); 19 | }); 20 | }; 21 | 22 | const hoursWorkedSoFar = () => { 23 | return new Promise(resolve => { 24 | rl.question( 25 | chalk.cyan('Total hours worked (up to last clock-in time): '), 26 | answer => { 27 | const result = answer; 28 | resolve(result); 29 | } 30 | ); 31 | }); 32 | }; 33 | 34 | const timeIn = () => { 35 | return new Promise(resolve => { 36 | rl.question(chalk.cyan('Time of last clock-in (e.g. 12:30 PM): '), answer => { 37 | const time = moment(answer, 'HH:mm a').format('LT'); 38 | resolve(time); 39 | }); 40 | }); 41 | }; 42 | 43 | const main = async () => { 44 | const hoursToWorkPerDayInMinutes = (await hoursToWorkToday()) * 60; 45 | const timeLeft = hoursToWorkPerDayInMinutes - (await hoursWorkedSoFar() * 60); 46 | 47 | const timeToClockOut = moment( 48 | await timeIn(), 49 | 'HH:mm a' 50 | ) 51 | .add(timeLeft, 'minutes') 52 | .format('LT'); 53 | 54 | console.log( 55 | chalk.yellow('You should clock out at: ', chalk.magenta(timeToClockOut)) 56 | ); 57 | 58 | rl.close(); 59 | }; 60 | 61 | main(); 62 | --------------------------------------------------------------------------------