├── .editorconfig ├── .gitattributes ├── .gitignore ├── .travis.yml ├── cli.js ├── license ├── package.json ├── readme.md ├── screenshot.gif └── test.js /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_style = tab 5 | end_of_line = lf 6 | charset = utf-8 7 | trim_trailing_whitespace = true 8 | insert_final_newline = true 9 | 10 | [{package.json,*.yml}] 11 | indent_style = space 12 | indent_size = 2 13 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | env: 3 | global: 4 | secure: lPUvhueyWJHoXntQFba887B38KanE6n0V+cvMqYjwaCcNiu4sT/E3o7oSkcNdKqOU1lkwT9LieGqgRsjsuxF5nF5LNiZJX9d9qM3/fPKUikR5re1p1qQ77SuriJDDniC7lqMSLSWkntzDiVp4GTtAJyCi6PE3s1FWNT4zBHZ0qhxk24lBErcbqdJ23SErEQL6kLtffmsSIKVzlOFUSSft4Af0ZrBfckf62fscuXrVnBSaZc/1OWOY6z41v99fc6LY1aS4s2wZUfDOFKzWTJi7g/275qwbdpa7rjjuYQBqLIQYQmzvtRC1yiC0uNyxwIMi0UYssRtMMzKsPNO3V8WpUHu2Z5oW+c7eqe00qER9yuH16K/apzsKY+F7AFI6ESVg7QT6XQ0XtezTP7xmilq/dyDOm3M3MEddDWiyRPReBe77bV1gUps+ieEwJOKT8GdyglRh4IS8rfE0QeJJvKseBmDAQydIVBYFnJAe80b6Bq+yHqkgI5GLhvFq1TiqimbF3Nb0MfFFPVaXv/QWG01WVRgHHO+VTCGY7cMITFriv976WqGjWLUI5nUMYBO39S5MYePMgE4d1Dt6tuYcYzt0bbyZekpVaabrgg5OT6LGHcstOfzCnFzJ3ccF0AvC6oFY8iP68TkXaNLT0Z8NodyQLrIvcp7UzplEWW+qTJqYs8= 5 | node_js: 6 | - '6' 7 | - '4' 8 | -------------------------------------------------------------------------------- /cli.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 'use strict'; 3 | const updateNotifier = require('update-notifier'); 4 | const meow = require('meow'); 5 | const moment = require('moment-timezone'); 6 | const devTime = require('dev-time'); 7 | const logSymbols = require('log-symbols'); 8 | const chalk = require('chalk'); 9 | const elegantSpinner = require('elegant-spinner'); 10 | const logUpdate = require('log-update'); 11 | 12 | const cli = meow(` 13 | Usage 14 | $ dev-time ... 15 | 16 | Options 17 | -v, --verbose Show UTC offset. 18 | --format The moment format of the output. [Default: HH:mm - D MMM. YYYY] 19 | --token The GitHub authentication token. 20 | 21 | Examples 22 | $ dev-time SamVerschueren 23 | 19:47 - 8 Dec. 2015 24 | 25 | $ dev-time SamVerschueren sindresorhus 26 | SamVerschueren 27 | 19:47 - 8 Dec. 2015 28 | sindresorhus 29 | 18:47 - 8 Dec. 2015 30 | 31 | $ dev-time SamVerschueren -v 32 | 19:47 - 8 Dec. 2015 - UTC+1 33 | 34 | $ dev-time SamVerschueren --format DD-MM-YYYY 35 | 07-12-2015 36 | `, { 37 | string: ['_'], 38 | boolean: ['verbose'], 39 | alias: { 40 | v: 'verbose' 41 | }, 42 | default: { 43 | format: 'HH:mm - D MMM. YYYY' 44 | } 45 | }); 46 | 47 | updateNotifier({pkg: cli.pkg}).notify(); 48 | 49 | if (cli.input.length === 0) { 50 | console.error('Provide a GitHub user'); 51 | process.exit(1); 52 | } 53 | 54 | const result = {}; 55 | const frames = {}; 56 | 57 | cli.input.forEach(user => { 58 | frames[user] = elegantSpinner(); 59 | }); 60 | 61 | function parseError(err) { 62 | if (/no contributions/.test(err.message) || /Rate limit exceeded/.test(err.message)) { 63 | return ` ${logSymbols.error} ${chalk.red('error')} ${err.message.toLowerCase()}`; 64 | } 65 | 66 | return err.stack; 67 | } 68 | 69 | function render() { 70 | const output = []; 71 | 72 | cli.input.forEach(user => { 73 | if (cli.input.length === 1) { 74 | output.push(result[user].stack ? parseError(result[user]) : result[user]); 75 | return; 76 | } 77 | 78 | output.push(user); 79 | 80 | if (result[user]) { 81 | if (result[user] instanceof Error) { 82 | output.push(parseError(result[user])); 83 | } else { 84 | output.push(` ${result[user]}`); 85 | } 86 | } else { 87 | output.push(` ${chalk.gray.dim(frames[user]())}`); 88 | } 89 | }); 90 | 91 | logUpdate(output.join('\n')); 92 | } 93 | 94 | if (cli.input.length > 1) { 95 | setInterval(render, 50); 96 | } 97 | 98 | Promise.all(cli.input.map(user => 99 | devTime(user, cli.flags) 100 | .then(time => { 101 | const date = moment.utc(time).utcOffset(time); 102 | result[user] = date.format(cli.flags.format); 103 | 104 | if (cli.flags.verbose) { 105 | const sign = date.utcOffset() >= 0 ? '+' : ''; 106 | result[user] += ` - UTC${sign}${date.utcOffset() / 60}`; 107 | } 108 | }) 109 | .catch(err => { 110 | result[user] = err; 111 | }) 112 | )).then(() => { 113 | render(); 114 | process.exit(); 115 | }); 116 | -------------------------------------------------------------------------------- /license: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) Sam Verschueren (github.com/SamVerschueren) 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "dev-time-cli", 3 | "version": "1.3.5", 4 | "description": "Get the current local time of a GitHub user.", 5 | "license": "MIT", 6 | "repository": "SamVerschueren/dev-time-cli", 7 | "author": { 8 | "name": "Sam Verschueren", 9 | "email": "sam.verschueren@gmail.com", 10 | "url": "github.com/SamVerschueren" 11 | }, 12 | "bin": { 13 | "dev-time": "cli.js" 14 | }, 15 | "engines": { 16 | "node": ">=4" 17 | }, 18 | "scripts": { 19 | "test": "xo && ava" 20 | }, 21 | "files": [ 22 | "cli.js" 23 | ], 24 | "keywords": [ 25 | "cli-app", 26 | "cli", 27 | "github", 28 | "gh", 29 | "developer", 30 | "dev", 31 | "user", 32 | "local", 33 | "time", 34 | "timezone", 35 | "date" 36 | ], 37 | "dependencies": { 38 | "chalk": "^1.1.1", 39 | "dev-time": "^1.0.0", 40 | "elegant-spinner": "^1.0.1", 41 | "log-symbols": "^1.0.2", 42 | "log-update": "^1.0.2", 43 | "meow": "^3.6.0", 44 | "moment-timezone": "^0.5.4", 45 | "update-notifier": "^1.0.0" 46 | }, 47 | "devDependencies": { 48 | "ava": "*", 49 | "execa": "^0.4.0", 50 | "strip-ansi": "^3.0.0", 51 | "xo": "*" 52 | }, 53 | "xo": { 54 | "esnext": true 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # dev-time-cli [![Build Status](https://travis-ci.org/SamVerschueren/dev-time-cli.svg?branch=master)](https://travis-ci.org/SamVerschueren/dev-time-cli) 2 | 3 | > Get the current local time of a GitHub user. 4 | 5 | 6 | 7 | 8 | ## Install 9 | 10 | ``` 11 | $ npm install --global dev-time-cli 12 | ``` 13 | 14 | 15 | ## Usage 16 | 17 | ``` 18 | $ dev-time --help 19 | 20 | Usage 21 | $ dev-time ... 22 | 23 | Options 24 | -v, --verbose Show UTC offset. 25 | --format The moment format of the output. [Default: HH:mm - D MMM. YYYY] 26 | --token The GitHub authentication token. 27 | 28 | Examples 29 | $ dev-time SamVerschueren 30 | 19:47 - 8 Dec. 2015 31 | 32 | $ dev-time SamVerschueren sindresorhus 33 | SamVerschueren 34 | 19:47 - 8 Dec. 2015 35 | sindresorhus 36 | 18:47 - 8 Dec. 2015 37 | 38 | $ dev-time SamVerschueren -v 39 | 19:47 - 8 Dec. 2015 - UTC+1 40 | 41 | $ dev-time SamVerschueren --format DD-MM-YYYY 42 | 07-12-2015 43 | ``` 44 | 45 | 46 | ## Related 47 | 48 | - [dev-time](https://github.com/SamVerschueren/dev-time) - API for this module 49 | 50 | 51 | ## License 52 | 53 | MIT © [Sam Verschueren](http://github.com/SamVerschueren) 54 | -------------------------------------------------------------------------------- /screenshot.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SamVerschueren/dev-time-cli/293922c778ca8e9593491a901df9c33de518894a/screenshot.gif -------------------------------------------------------------------------------- /test.js: -------------------------------------------------------------------------------- 1 | import test from 'ava'; 2 | import moment from 'moment-timezone'; 3 | import execa from 'execa'; 4 | import stripAnsi from 'strip-ansi'; 5 | 6 | test('error', async t => { 7 | await t.throws(execa('./cli.js'), /Provide a GitHub user/); 8 | }); 9 | 10 | test('result', async t => { 11 | const {stdout} = await execa('./cli.js', ['SamVerschueren']); 12 | 13 | t.is(stripAnsi(stdout), `${moment().tz('Europe/Brussels').format('HH:mm - D MMM. YYYY')}\n`); 14 | }); 15 | 16 | test('formatting', async t => { 17 | const {stdout} = await execa('./cli.js', ['SamVerschueren', '--format', 'DD-MM-YYYY']); 18 | 19 | t.is(stripAnsi(stdout), `${moment().format('DD-MM-YYYY')}\n`); 20 | }); 21 | --------------------------------------------------------------------------------