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

Fix time zone calculation by getDeviceTime #392

Merged
merged 1 commit into from
Aug 7, 2019
Merged
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
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');
});
});
}));