File tree Expand file tree Collapse file tree 2 files changed +9
-3
lines changed Expand file tree Collapse file tree 2 files changed +9
-3
lines changed Original file line number Diff line number Diff line change 11'use strict'
22
33function formatMtime ( mtime ) {
4- if ( mtime === undefined ) {
4+ if ( mtime == null ) {
55 return '-'
66 }
77
8- return new Date ( mtime * 1000 ) . toLocaleDateString ( Intl . DateTimeFormat ( ) . resolvedOptions ( ) . locale , {
8+ const date = new Date ( ( mtime . secs * 1000 ) + Math . round ( mtime . nsecs / 1000 ) )
9+
10+ return date . toLocaleDateString ( Intl . DateTimeFormat ( ) . resolvedOptions ( ) . locale , {
911 year : 'numeric' ,
1012 month : 'short' ,
1113 day : 'numeric' ,
Original file line number Diff line number Diff line change @@ -10,6 +10,10 @@ const expect = chai.expect
1010
1111describe ( 'format-mtime' , function ( ) {
1212 it ( 'formats mtime' , function ( ) {
13- expect ( ( new Date ( formatMtime ( 0 ) ) ) . getTime ( ) ) . to . equal ( 0 )
13+ expect ( formatMtime ( { secs : 100 , nsecs : 0 } ) ) . to . include ( 'Jan 1, 1970' )
14+ } )
15+
16+ it ( 'formats empty mtime' , function ( ) {
17+ expect ( formatMtime ( ) ) . to . equal ( '-' )
1418 } )
1519} )
You can’t perform that action at this time.
0 commit comments