diff --git a/lib/commands/general.js b/lib/commands/general.js index ee5e7539..90795863 100644 --- a/lib/commands/general.js +++ b/lib/commands/general.js @@ -49,16 +49,16 @@ commands.getDeviceTime = async function getDeviceTime (format = MOMENT_FORMAT_IS log.warn('On simulator. Assuming device time is the same as host time'); cmd = 'date'; args = ['+%Y-%m-%dT%H:%M:%S%z']; - inputFormat = MOMENT_FORMAT_ISO8601; + inputFormat = 'YYYY-MM-DDTHH:mm:ssZZ'; } const stdout = (await exec(cmd, args)).stdout.trim(); log.debug(`Got the following output out of '${cmd} ${args.join(' ')}': ${stdout}`); - const parsedTimestamp = moment(stdout, inputFormat); + const parsedTimestamp = moment.utc(stdout, inputFormat); if (!parsedTimestamp.isValid()) { log.warn(`Cannot parse the timestamp '${stdout}' returned by '${cmd}' command. Returning it as is`); return stdout; } - return parsedTimestamp.format(format); + return parsedTimestamp.utcOffset(parsedTimestamp._tzm || 0).format(format); }; commands.hideKeyboard = async function hideKeyboard (strategy, ...possibleKeys) { diff --git a/package.json b/package.json index 67321dac..2d7d072b 100644 --- a/package.json +++ b/package.json @@ -51,7 +51,8 @@ "colors": "^1.1.2", "js2xmlparser2": "^0.2.0", "lodash": "^4.13.1", - "moment": "^2.22.2", + "moment": "^2.24.0", + "moment-timezone": "^0.5.26", "node-idevice": "^0.1.6", "node-simctl": "^5.0.0", "pem": "^1.8.3", diff --git a/test/unit/driver-specs.js b/test/unit/driver-specs.js index efefcff5..2e53399b 100644 --- a/test/unit/driver-specs.js +++ b/test/unit/driver-specs.js @@ -136,9 +136,9 @@ describe('getDeviceTime', withMocks({fs, teen_process}, (mocks) => { }; it('should call idevicedate', async function () { - let date = 'Tue Jun 12 11:13:31 CEST 2018'; + let date = 'Tue Jun 12 11:13:31 UTC 2018'; let driver = setup(mocks, {date}); - (await driver.getDeviceTime()).startsWith('2018-06-12T').should.be.true; + (await driver.getDeviceTime()).should.eql('2018-06-12T11:13:31+00:00'); }); it('should call idevicedate with format', async function () { @@ -169,7 +169,7 @@ describe('getDeviceTime', withMocks({fs, teen_process}, (mocks) => { .once().withExactArgs('date', ['+%Y-%m-%dT%H:%M:%S%z']) .returns({stdout: '2018-06-12T12:11:59+0200'}); let driver = new IosDriver(); - (await driver.getDeviceTime()).startsWith('2018-06-12T').should.be.true; + (await driver.getDeviceTime()).should.eql('2018-06-12T12:11:59+02:00'); }); }); }));