Skip to content

Commit 0b929fd

Browse files
committed
[DATETIME]: input parser and output timezone will be same, and can't be different
Signed-off-by: ashish <[email protected]>
1 parent 0c06328 commit 0b929fd

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

src/commands/datetime.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,9 @@ export default class Datetime extends Command {
7777
let date: moment.Moment
7878

7979
if (args.date)
80-
date = moment(args.date)
80+
date = moment.tz(args.date, args.timezone)
8181
else
82-
date = moment([]) // return now() if args.date is undefined
82+
date = moment.tz([], args.timezone) // return now() if args.date is undefined
8383

8484
// set locale
8585
date.locale(flags.locale)

test/commands/datetime.test.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,24 @@
11
import {expect, test} from '@oclif/test'
2+
import * as moment from 'moment-timezone' //has both momentjs and timezone support
23

34
describe('datetime', () => {
45
test
56
.stdout()
6-
.command(['datetime', '01-Jul-2019'])
7+
.command(['datetime', '2019-07-01 00:00:00'])
78
.it('If locale is not given, default - en', ctx => {
8-
expect(ctx.stdout).to.contain('1st July 2019, 12:0:0 AM, +05:30 UTC')
9+
expect(ctx.stdout).to.contain(`1st July 2019, 12:0:0 AM, ${moment('01-Jul-2019').format('Z')} UTC`)
910
})
1011

1112
test
1213
.stdout()
13-
.command(['datetime', '01-Jul-2019', '-l', 'fr'])
14+
.command(['datetime', '2019-07-01 00:00:00', '-l', 'fr'])
1415
.it('If locale is given for french', ctx => {
15-
expect(ctx.stdout).to.contain('1er juillet 2019, 12:0:0 AM, +05:30 UTC')
16+
expect(ctx.stdout).to.contain(`1er juillet 2019, 12:0:0 AM, ${moment('01-Jul-2019').format('Z')} UTC`)
1617
})
1718

1819
test
1920
.stdout()
20-
.command(['datetime', '01-Jul-2019', '-l', 'hi'])
21+
.command(['datetime', '2019-07-01 00:00:00', '-l', 'hi'])
2122
.it('If locale is given for hindi', ctx => {
2223
expect(ctx.stdout).to.contain('१ जुलाई २०१९, १२:०:० रात, +०५:३० UTC')
2324
})

0 commit comments

Comments
 (0)