Skip to content

Commit

Permalink
Use UTC time, dynamically format time in test
Browse files Browse the repository at this point in the history
  • Loading branch information
Maaaartin committed May 18, 2024
1 parent 917a8d7 commit c25f35d
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 12 deletions.
12 changes: 11 additions & 1 deletion __tests__/adbClient/touch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,18 @@ beforeAll(() => {
return '1-2-3-4-5';
});
});
function formatDate(date: Date): string {
const year = date.getUTCFullYear();
const month = ('0' + (date.getUTCMonth() + 1)).slice(-2);
const day = ('0' + date.getUTCDate()).slice(-2);
const hours = ('0' + date.getUTCHours()).slice(-2);
const minutes = ('0' + date.getUTCMinutes()).slice(-2);
const seconds = ('0' + date.getUTCSeconds()).slice(-2);
const milliseconds = ('00' + date.getUTCMilliseconds()).slice(-3);
return `${year}${month}${day}${hours}${minutes}.${seconds}${milliseconds}`;
}
const date = new Date('2022-12-13T12:41:42.418Z');
const formattedTime = '202212131341.42418';
const formattedTime = formatDate(date);
describe('Touch OKAY tests', () => {
it('Should execute without parameters', async () => {
const adbMock = new AdbMock([
Expand Down
14 changes: 7 additions & 7 deletions src/commands/host-transport/fileSystem/touch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import FileSystemCommand from '../../abstract/fileSystem';
*/
const formatToTimeFlag = (value: Date | string): string => {
const date = new Date(value);
const year = date.getFullYear().toString();
const month = (date.getMonth() + 1).toString().padStart(2, '0');
const day = date.getDate().toString().padStart(2, '0');
const hours = date.getHours().toString().padStart(2, '0');
const minutes = date.getMinutes().toString().padStart(2, '0');
const seconds = date.getSeconds().toString().padStart(2, '0');
const milliseconds = date.getMilliseconds().toString().padStart(3, '0');
const year = date.getUTCFullYear().toString();
const month = (date.getUTCMonth() + 1).toString().padStart(2, '0');
const day = date.getUTCDate().toString().padStart(2, '0');
const hours = date.getUTCHours().toString().padStart(2, '0');
const minutes = date.getUTCMinutes().toString().padStart(2, '0');
const seconds = date.getUTCSeconds().toString().padStart(2, '0');
const milliseconds = date.getUTCMilliseconds().toString().padStart(3, '0');

return `${year}${month}${day}${hours}${minutes}.${seconds}${milliseconds}`;
};
Expand Down
9 changes: 5 additions & 4 deletions src/util/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -322,23 +322,24 @@ export interface MkDirOptions {

export interface TouchOptions extends SymlinkFSoption {
/**
* Adds `-a` flag. Changes access time.
* Adds `-a` flag. Changes access time. UTC time.
*/
aTime?: boolean;
/**
* Adds `-m` flag. Changes modification time.
* Adds `-m` flag. Changes modification time. UTC time.
*/
mTime?: boolean;
/**
* Adds `-m` flag. Does not create file. Does not create file.
*/
noCreate?: boolean;
// TODO add test to ensure UTC
/**
* Adds `-d <date>` flag.
* Adds `-d <date>` flag. UTC time.
*/
date?: Date | string;
/**
* Adds `-t <time>` flag.
* Adds `-t <time>` flag. UTC time.
*/
time?: Date | string;
/**
Expand Down

0 comments on commit c25f35d

Please sign in to comment.