From 5eaea8a43b0fdadcbebd7341bf4802850dfc4a74 Mon Sep 17 00:00:00 2001 From: Ahmad Awais Date: Sat, 25 Apr 2020 00:56:09 +0500 Subject: [PATCH] =?UTF-8?q?=F0=9F=93=A6=20NEW:=20First=20version?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- data/lahore.json | 182 ++++++++++++++++++++++++++++++++++++++++++++++ index.js | 27 ++++++- package.json | 3 +- readme.md | 2 +- utils/dateDiff.js | 7 ++ utils/init.js | 4 +- utils/theEnd.js | 10 ++- 7 files changed, 225 insertions(+), 10 deletions(-) create mode 100644 data/lahore.json mode change 100644 => 100755 index.js create mode 100644 utils/dateDiff.js diff --git a/data/lahore.json b/data/lahore.json new file mode 100644 index 0000000..2f0aac7 --- /dev/null +++ b/data/lahore.json @@ -0,0 +1,182 @@ +[ + { + "no": "#1", + "date": "2020-04-25", + "sehar": "3:55 AM", + "iftar": "6:40 PM" + }, + { + "no": "#2", + "date": "2020-04-26", + "sehar": "3:54 AM", + "iftar": "6:40 PM" + }, + { + "no": "#3", + "date": "2020-04-27", + "sehar": "3:52 AM", + "iftar": "6:41 PM" + }, + { + "no": "#4", + "date": "2020-04-28", + "sehar": "3:51 AM", + "iftar": "6:42 PM" + }, + { + "no": "#5", + "date": "2020-04-29", + "sehar": "3:50 AM", + "iftar": "6:43 PM" + }, + { + "no": "#6", + "date": "2020-04-30", + "sehar": "3:49 AM", + "iftar": "6:43 PM" + }, + { + "no": "#7", + "date": "2020-05-01", + "sehar": "3:47 AM", + "iftar": "6:44 PM" + }, + { + "no": "#8", + "date": "2020-05-02", + "sehar": "3:46 AM", + "iftar": "6:45 PM" + }, + { + "no": "#9", + "date": "2020-05-03", + "sehar": "3:45 AM", + "iftar": "6:45 PM" + }, + { + "no": "#10", + "date": "2020-05-04", + "sehar": "3:44 AM", + "iftar": "6:46 PM" + }, + { + "no": "#11", + "date": "2020-05-05", + "sehar": "3:43 AM", + "iftar": "6:47 PM" + }, + { + "no": "#12", + "date": "2020-05-06", + "sehar": "3:41 AM", + "iftar": "6:47 PM" + }, + { + "no": "#13", + "date": "2020-05-07", + "sehar": "3:40 AM", + "iftar": "6:48 PM" + }, + { + "no": "#14", + "date": "2020-05-08", + "sehar": "3:39 AM", + "iftar": "6:49 PM" + }, + { + "no": "#15", + "date": "2020-05-09", + "sehar": "3:38 AM", + "iftar": "6:50 PM" + }, + { + "no": "#16", + "date": "2020-05-10", + "sehar": "3:37 AM", + "iftar": "6:50 PM" + }, + { + "no": "#17", + "date": "2020-05-11", + "sehar": "3:36 AM", + "iftar": "6:51 PM" + }, + { + "no": "#18", + "date": "2020-05-12", + "sehar": "3:35 AM", + "iftar": "6:52 PM" + }, + { + "no": "#19", + "date": "2020-05-13", + "sehar": "3:34 AM", + "iftar": "6:52 PM" + }, + { + "no": "#20", + "date": "2020-05-14", + "sehar": "3:33 AM", + "iftar": "6:53 PM" + }, + { + "no": "#21", + "date": "2020-05-15", + "sehar": "3:32 AM", + "iftar": "6:54 PM" + }, + { + "no": "#22", + "date": "2020-05-16", + "sehar": "3:31 AM", + "iftar": "6:54 PM" + }, + { + "no": "#23", + "date": "2020-05-17", + "sehar": "3:30 AM", + "iftar": "6:55 PM" + }, + { + "no": "#24", + "date": "2020-05-18", + "sehar": "3:29 AM", + "iftar": "6:56 PM" + }, + { + "no": "#25", + "date": "2020-05-19", + "sehar": "3:29 AM", + "iftar": "6:56 PM" + }, + { + "no": "#26", + "date": "2020-05-20", + "sehar": "3:28 AM", + "iftar": "6:57 PM" + }, + { + "no": "#27", + "date": "2020-05-21", + "sehar": "3:27 AM", + "iftar": "6:58 PM" + }, + { + "no": "#28", + "date": "2020-05-22", + "sehar": "3:26 AM", + "iftar": "6:58 PM" + }, + { + "no": "#29", + "date": "2020-05-23", + "sehar": "3:25 AM", + "iftar": "6:59 PM" + }, + { + "no": "#30", + "date": "2020-05-24", + "sehar": "3:25 AM", + "iftar": "7:00 PM" + } +] diff --git a/index.js b/index.js old mode 100644 new mode 100755 index b3c66af..7229be9 --- a/index.js +++ b/index.js @@ -1,12 +1,16 @@ #!/usr/bin/env node -const ora = require('ora'); -const spinner = ora({text: ''}); +// const {green, yellow, hex} = require('chalk'); +const chalk = require('chalk'); +const sym = require('log-symbols'); const cli = require('./utils/cli.js'); const init = require('./utils/init.js'); -const to = require('await-to-js').default; const theEnd = require('./utils/theEnd.js'); const handleError = require('cli-handle-error'); +const data = require('./data/lahore.json'); +const dateDiff = require('./utils/dateDiff'); +const Table = require('cli-table3'); +const green = string => chalk.hex(`#81EF96`)(string); // CLI. const [input] = cli.input; @@ -14,5 +18,22 @@ const option = cli.flags.option; (async () => { init(); + const firstRoza = '2020-04-25'; + const today = new Date().toISOString().substring(0, 10); + const rozaNumber = dateDiff(firstRoza, '2020-06-10'); + if (rozaNumber > 30) { + console.log( + `${sym.success} Eid Mubarak.\nRamadan is already over. Hope you had a fun time on Eid.\n` + ); + } else { + const roza = rozaNumber > 1 ? data[rozaNumber] : data[0]; + + const table = new Table({ + head: [green('Roza'), green('Sehar'), green('Iftar')] + }); + + table.push([roza.no, roza.sehar, roza.iftar]); + console.log(table.toString()); + } theEnd(); })(); diff --git a/package.json b/package.json index 2c1f2a9..e3d6fca 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "ramadan-cli", "version": "0.0.1", - "description": "CLI to check Sehar and Iftar times in Ramadan.", + "description": "Check Sehar and Iftar times in Ramadan within your terminal.", "license": "MIT", "repository": "ahmadawais/ramadan-cli", "author": { @@ -42,7 +42,6 @@ "cli-handle-unhandled": "^1.1.0", "cli-welcome": "^1.4.0", "meow": "^6.1.0", - "ora": "^4.0.4", "update-notifier": "^4.1.0" } } diff --git a/readme.md b/readme.md index c254d81..e9b41e0 100644 --- a/readme.md +++ b/readme.md @@ -1,6 +1,6 @@ # ramadan-cli -[![DOWNLOADS](https://img.shields.io/npm/dt/ramadan-cli?label=DOWNLOADS%20%20❯&colorA=6A788D&colorB=6A788D&style=flat)](https://www.npmjs.com/package/ramadan-cli) [![Learn VSCode](https://img.shields.io/badge/-VSCODE.pro%20%E2%86%92-gray.svg?colorB=6A788D&style=flat)](https://VSCode.pro/?utm_source=GitHubFOSS) +[![DOWNLOADS](https://img.shields.io/npm/dt/{{name}}?label=DOWNLOADS%20%20❯&colorA=6A788D&colorB=6A788D&style=flat)](https://www.npmjs.com/package/{{name}}) [![Node.js CLI](https://img.shields.io/badge/-NodeCLI.com-gray.svg?colorB=6A788D&style=flat)](https://NodeCLI.com/?utm_source=FOSS) [![Learn VSCode](https://img.shields.io/badge/-VSCODE.pro-gray.svg?colorB=6A788D&style=flat)](https://VSCode.pro/?utm_source=FOSS) [![Sponsor](https://img.shields.io/badge/-Sponsor-gray.svg?colorB=6A788D&style=flat)](https://github.com/ahmadawais/sponsor?utm_source=FOSS) [![Follow @MrAhmadAwais on Twitter](https://img.shields.io/badge/FOLLOW%20@MRAHMADAWAIS%20%E2%86%92-gray.svg?colorA=6A788D&colorB=6A788D&style=flat)](https://twitter.com/mrahmadawais/) > CLI to check Sehar and Iftar times in Ramadan. diff --git a/utils/dateDiff.js b/utils/dateDiff.js new file mode 100644 index 0000000..75eb569 --- /dev/null +++ b/utils/dateDiff.js @@ -0,0 +1,7 @@ +module.exports = (first, second) => { + // Take the difference between the dates and divide by milliseconds per day. + // Round to nearest whole number to deal with DST. + return Math.round( + (new Date(second) - new Date(first)) / (1000 * 60 * 60 * 24) + ); +}; diff --git a/utils/init.js b/utils/init.js index 559f8b8..933d771 100644 --- a/utils/init.js +++ b/utils/init.js @@ -8,7 +8,7 @@ module.exports = async () => { unhandledError(); checkNode(`12`); welcome(`ramadan-cli`, `by Awais.dev\n${pkgJSON.description}`, { - bgColor: `#007C91`, + bgColor: `#81EF96`, color: `#FFFFFF`, bold: true, clear: true, @@ -18,5 +18,5 @@ module.exports = async () => { pkg: pkgJSON, shouldNotifyInNpmScript: true, updateCheckInterval: 1000 * 60 * 60 * 24 * 7 // 1 week. - }).notify({ isGlobal: true }); + }).notify({isGlobal: true}); }; diff --git a/utils/theEnd.js b/utils/theEnd.js index 24b9395..3240c1e 100644 --- a/utils/theEnd.js +++ b/utils/theEnd.js @@ -1,6 +1,12 @@ const sym = require('log-symbols'); -const chalk = require('chalk'); +const {dim} = require('chalk'); module.exports = async () => { - console.log(`${sym.success} All done.\n`); + console.log( + `\n${sym.success} ${dim( + `Star the repo for updates → https://git.io/ramadan-cli` + )}\n${sym.info} ${dim( + `Follow for more CLIs → https://twitter.com/MrAhmadAwais\n\n` + )}` + ); };