File tree Expand file tree Collapse file tree 3 files changed +25
-12
lines changed
Filter options
Expand file tree Collapse file tree 3 files changed +25
-12
lines changed
Original file line number Diff line number Diff line change @@ -647,19 +647,20 @@ Available options:
647
647
+ ` -a ` : Change only the access time
648
648
+ ` -c ` : Do not create any files
649
649
+ ` -m ` : Change only the modification time
650
- + ` -d DATE ` : Parse ` DATE ` and use it instead of current time
651
- + ` -r FILE ` : Use ` FILE ` 's times instead of current time
650
+ + ` {'-d': date} ` : Use ` date ` (instance of ` Date ` ) instead of current time
651
+ + ` {'-r': file} ` : Use ` file ` 's times instead of current time
652
652
653
653
Examples:
654
654
655
655
``` javascript
656
656
touch (' source.js' );
657
- touch (' -c' , ' /path/to/some/dir/source.js' );
658
- touch ({ ' -r' : FILE }, ' /path/to/some/dir/source.js' );
657
+ touch (' -c' , ' path/to/file.js' );
658
+ touch ({ ' -r' : ' referenceFile.txt' }, ' path/to/file.js' );
659
+ touch ({ ' -d' : new Date (' December 17, 1995 03:24:00' ) }, ' path/to/file.js' );
659
660
```
660
661
661
- Update the access and modification times of each ` FILE ` to the current time.
662
- A ` FILE ` argument that does not exist is created empty, unless ` -c ` is supplied.
662
+ Update the access and modification times of each file to the current time.
663
+ A file argument that does not exist is created empty, unless ` -c ` is supplied.
663
664
This is a partial implementation of [ ` touch(1) ` ] ( http://linux.die.net/man/1/touch ) .
664
665
665
666
Original file line number Diff line number Diff line change @@ -20,19 +20,20 @@ common.register('touch', _touch, {
20
20
//@ + `-a`: Change only the access time
21
21
//@ + `-c`: Do not create any files
22
22
//@ + `-m`: Change only the modification time
23
- //@ + `-d DATE `: Parse `DATE` and use it instead of current time
24
- //@ + `-r FILE `: Use `FILE `'s times instead of current time
23
+ //@ + `{'-d': date} `: Use `date` (instance of `Date`) instead of current time
24
+ //@ + `{'-r': file} `: Use `file `'s times instead of current time
25
25
//@
26
26
//@ Examples:
27
27
//@
28
28
//@ ```javascript
29
29
//@ touch('source.js');
30
- //@ touch('-c', '/path/to/some/dir/source.js');
31
- //@ touch({ '-r': FILE }, '/path/to/some/dir/source.js');
30
+ //@ touch('-c', 'path/to/file.js');
31
+ //@ touch({ '-r': 'referenceFile.txt' }, 'path/to/file.js');
32
+ //@ touch({ '-d': new Date('December 17, 1995 03:24:00') }, 'path/to/file.js');
32
33
//@ ```
33
34
//@
34
- //@ Update the access and modification times of each `FILE` to the current time.
35
- //@ A `FILE` argument that does not exist is created empty, unless `-c` is supplied.
35
+ //@ Update the access and modification times of each file to the current time.
36
+ //@ A file argument that does not exist is created empty, unless `-c` is supplied.
36
37
//@ This is a partial implementation of [`touch(1)`](http://linux.die.net/man/1/touch).
37
38
function _touch ( opts , files ) {
38
39
if ( ! files ) {
Original file line number Diff line number Diff line change @@ -119,6 +119,17 @@ test('uses a reference file for mtime', t => {
119
119
) ;
120
120
} ) ;
121
121
122
+ test ( 'accepts -d flag' , t => {
123
+ const testFile = tmpFile ( t ) ;
124
+ const oldStat = resetUtimes ( testFile ) ;
125
+ const date = new Date ( 'December 17, 1995 03:24:00' ) ;
126
+ const result = shell . touch ( { '-d' : date } , testFile ) ;
127
+ t . is ( result . code , 0 ) ;
128
+ // Compare getTime(), because Date can't be compared with triple-equals.
129
+ t . is ( common . statFollowLinks ( testFile ) . mtime . getTime ( ) , date . getTime ( ) ) ;
130
+ t . is ( common . statFollowLinks ( testFile ) . atime . getTime ( ) , date . getTime ( ) ) ;
131
+ } ) ;
132
+
122
133
test ( 'sets mtime and atime by default' , t => {
123
134
const testFile = tmpFile ( t ) ;
124
135
const oldStat = resetUtimes ( testFile ) ;
You can’t perform that action at this time.
0 commit comments