Skip to content

Commit

Permalink
Fix time zone calculation by getDeviceTime (#392)
Browse files Browse the repository at this point in the history
  • Loading branch information
mykola-mokhnach authored Aug 7, 2019
1 parent 7502871 commit 4dc8ae5
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
6 changes: 3 additions & 3 deletions lib/commands/general.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
6 changes: 3 additions & 3 deletions test/unit/driver-specs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down Expand Up @@ -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');
});
});
}));

0 comments on commit 4dc8ae5

Please sign in to comment.