Skip to content

Commit f4b9df1

Browse files
committed
[DATETIME]: added basic functionality for datetime
Signed-off-by: ashish <[email protected]>
1 parent b8fad99 commit f4b9df1

File tree

4 files changed

+29
-21
lines changed

4 files changed

+29
-21
lines changed

README.md

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ USAGE
4949
* [`cdt autocomplete [SHELL]`](#cdt-autocomplete-shell)
5050
* [`cdt bundlephobia [PACKAGE]`](#cdt-bundlephobia-package)
5151
* [`cdt crypto [STRING]`](#cdt-crypto-string)
52-
* [`cdt date [FILE]`](#cdt-date-file)
52+
* [`cdt datetime [DATE]`](#cdt-datetime-date)
5353
* [`cdt hash [STRING]`](#cdt-hash-string)
5454
* [`cdt help [COMMAND]`](#cdt-help-command)
5555
* [`cdt minify [FILE]`](#cdt-minify-file)
@@ -113,21 +113,23 @@ OPTIONS
113113

114114
_See code: [src/commands/crypto.ts](https://github.com/codingtools/cdt/blob/v0.1.4/src/commands/crypto.ts)_
115115

116-
## `cdt date [FILE]`
116+
## `cdt datetime [DATE]`
117117

118-
describe the command here
118+
Date and Time utility
119119

120120
```
121121
USAGE
122-
$ cdt date [FILE]
122+
$ cdt datetime [DATE]
123123
124124
OPTIONS
125-
-f, --force
126-
-h, --help show CLI help
127-
-n, --name=name name to print
125+
-d, --date=date Datetime input string, could also be passed through argument
126+
-f, --format=format Datetime format
127+
-h, --help show CLI help
128+
-l, --locale=locale Locale, default: en
129+
-z, --timezone=timezone Timezone for Datetime
128130
```
129131

130-
_See code: [src/commands/datetime.ts](https://github.com/codingtools/cdt/blob/v0.1.4/src/commands/date.ts)_
132+
_See code: [src/commands/datetime.ts](https://github.com/codingtools/cdt/blob/v0.1.4/src/commands/datetime.ts)_
131133

132134
## `cdt hash [STRING]`
133135

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@
6363
"oclif": {
6464
"commands": "./lib/commands",
6565
"bin": "cdt",
66+
"macos": {
67+
"identifier": "@codingtools/cdt"
68+
},
6669
"plugins": [
6770
"@oclif/plugin-help",
6871
"@oclif/plugin-not-found",

src/commands/datetime.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
11
import {Command, flags} from '@oclif/command'
2+
import chalk from 'chalk'
23
import * as moment from 'moment'
34

45
// @ts-ignore
56
moment.suppressDeprecationWarnings = true
67

78
import Logger from '../utilities/logger'
89

10+
// TODO: add timezone support
911
export default class Datetime extends Command {
1012
static description = 'Date and Time utility'
1113

1214
static defaultFormat = 'Do MMMM YYYY, h:m:s A, Z UTC'
1315

1416
static flags = {
1517
help: flags.help({char: 'h'}),
16-
date: flags.string({char: 'd', description: 'Datetime provided, could also be passed without -d flag'}),
17-
format: flags.string({char: 'f', description: 'Datetime format'}),
18+
date: flags.string({char: 'd', description: 'Datetime input string, default: Now(), could also be passed through argument'}),
19+
format: flags.string({char: 'f', description: `Datetime format, default: ${Datetime.defaultFormat}`}),
1820
timezone: flags.string({char: 'z', description: 'Timezone for Datetime'}),
1921
locale: flags.string({char: 'l', description: 'Locale, default: en'}),
2022
}
@@ -29,9 +31,9 @@ export default class Datetime extends Command {
2931
args.locale = this.getLocale(flags, args) // getting date object
3032
args.format = this.getFormat(flags, args) // getting date object
3133

32-
Logger.info(this, `Input String: ${args.date}`)
33-
Logger.info(this, `Locale: ${args.locale}`)
34-
Logger.info(this, `Format: ${args.format}`)
34+
Logger.info(this, `Input String: ${ args.date ? args.date : chalk.magenta('Not Provided, using Now()') }`)
35+
Logger.info(this, `Locale: ${chalk.magenta(args.locale)}`)
36+
Logger.info(this, `Format: ${chalk.magenta(args.format)}`)
3537

3638
args.momentDate = this.getMomentDate(flags, args)
3739
this.checkParameters(flags, args)

test/commands/datetime.test.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,15 @@ describe('datetime', () => {
2727
.command(['datetime', 'not a real date'])
2828
.exit(0)
2929
.it('Invalid Datetime or Datetime format with args', ctx => {
30-
expect(ctx.stdout).to.contain('Invalid Datetime or Datetime format')
30+
expect(ctx.stdout).to.contain('Invalid Date String Passed')
31+
})
32+
33+
test
34+
.stdout()
35+
.command(['datetime', '-d', 'not a real date'])
36+
.exit(0)
37+
.it('Invalid Datetime or Datetime format with flags', ctx => {
38+
expect(ctx.stdout).to.contain('Invalid Date String Passed')
3139
})
3240

3341
test
@@ -45,11 +53,4 @@ describe('datetime', () => {
4553
expect(ctx.stdout).to.contain('Invalid Date String Passed')
4654
})
4755

48-
test
49-
.stdout()
50-
.command(['datetime', '-d', 'not a real date'])
51-
.exit(0)
52-
.it('Invalid Datetime or Datetime format with flags', ctx => {
53-
expect(ctx.stdout).to.contain('Invalid Datetime or Datetime format')
54-
})
5556
})

0 commit comments

Comments
 (0)