Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update tizo to the latest version 🚀 #3

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
language: node_js
node_js:
- '11'
- '12'
- '10'
- '8'
- '6'
31 changes: 0 additions & 31 deletions cli.ts

This file was deleted.

56 changes: 32 additions & 24 deletions index.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,41 @@
#!/usr/bin/env node
'use strict';
import tizo from 'tizo';
import chalk from 'chalk';

function print([hours, minutes]) {
let formattedHours = hours;
if (hours < 10) {
formattedHours = String('0' + hours);
function format(tizoTime: [number, number]): string {
let hours = String(tizoTime[0]);
if (hours.length === 1) {
hours = '0' + hours;
}

let formattedMinutes = minutes;
if (minutes < 10) {
formattedMinutes = String('0' + minutes);
let minutes = String(tizoTime[1]);
if (minutes.length === 1) {
minutes = '0' + minutes;
}

console.log(`${formattedHours}:${formattedMinutes}`);
return `${hours}:${minutes}`;
}

export default ({flags, input}) => {
const date = tizo(input.join(' '));
switch (flags.format) {
case 'local':
print(date.local);
break;
case 'utc':
print(date.utc);
break;
case 'original':
print(date.original);
break;
default:
console.log('Unknown format');
}
};
const log = console.log;
const argv = process.argv.splice(2).join(' ');
if (argv.length === 0) {
console.error('No input supplied');
process.exit(1);
}

try {
var tizoResult = tizo(argv);
} catch (error) {
console.error(error.message);
process.exit(1);
}
const {original, local, utc, inputTimezone} = tizoResult;

log();
log(
` ${chalk.blue('original')} ${format(original)} ${inputTimezone.name ||
'Local Time'}`
);
log(` ${chalk.blue('local')} ${format(local)}`);
log(` ${chalk.blue('utc')} ${format(utc)}`);
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"tizo": "out/cli.js"
},
"engines": {
"node": ">=6"
"node": ">= 8"
},
"scripts": {
"prettier-fix": "prettier --write *.ts",
Expand All @@ -36,13 +36,14 @@
"parse"
],
"dependencies": {
"chalk": "^2.4.2",
"meow": "^5.0.0",
"tizo": "^2.0.1"
"tizo": "^3.0.0"
},
"devDependencies": {
"@types/meow": "^5.0.0",
"@types/node": "^11.13.8",
"ava": "^1.1.0",
"ava": "^2.1.0",
"prettier": "^1.16.4",
"typescript": "^3.3.3333"
}
Expand Down
25 changes: 10 additions & 15 deletions test.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
import {execSync} from 'child_process';
import test from 'ava';

test('return correct format', t => {
const stdout = execSync('node ./out/cli.js -f="utc" 12am pdt');
t.true(stdout.includes('07:00'));
});

test('use standard format if not provided', t => {
const stdout = execSync('node ./out/cli.js 12am pdt');
t.true(stdout.length === 6);
});

test('throw error if format not found', t => {
const stdout = execSync(
'node ./out/cli.js -f="idontexist" 12am pdt'
).toString();
t.true(stdout.includes('Unknown format'));
test('return correct formats', t => {
const stdout = execSync('node ./out/index.js 12am pt');
t.(
stdout.toString(),
`
original 00:00 Pacific Time
local 10:00
utc 08:00
`
);
});