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

tweak android date format #377

Merged
merged 4 commits into from
Jun 10, 2018
Merged
Show file tree
Hide file tree
Changes from 2 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
3 changes: 2 additions & 1 deletion lib/commands/general.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ commands.doSendKeys = async function (params) {
commands.getDeviceTime = async function () {
log.info('Attempting to capture android device date and time');
try {
let out = await this.adb.shell(['date']);
// format: 2018-06-09T16:21:54+0900
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it probably makes sense to mention this in the docstring, that the resulting date string format conforms to ISO-8601 by default.

let out = await this.adb.shell(['date', '+%Y-%m-%dT%T%z']);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return (await this.adb.shell(['date', '+%Y-%m-%dT%T%z'])).trim()

return out.trim();
} catch (err) {
log.errorAndThrow(`Could not capture device date and time: ${err}`);
Expand Down
6 changes: 3 additions & 3 deletions test/unit/commands/general-specs.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ describe('General', function () {
describe('getDeviceTime', function () {
it('should return device time', async function () {
sandbox.stub(driver.adb, 'shell');
driver.adb.shell.returns(' 11:12 ');
await driver.getDeviceTime().should.become('11:12');
driver.adb.shell.calledWithExactly(['date']).should.be.true;
driver.adb.shell.returns(' 2018-06-09T16:21:54+0900 ');
await driver.getDeviceTime().should.become('2018-06-09T16:21:54+0900');
driver.adb.shell.calledWithExactly(['date', '+%Y-%m-%dT%T%z']).should.be.true;
});
it('should thorws error if shell command failed', async function () {
sandbox.stub(driver.adb, 'shell').throws();
Expand Down