Skip to content
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: 4 additions & 2 deletions src/files/format-mtime.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
'use strict'

function formatMtime (mtime) {
if (mtime === undefined) {
if (mtime == null) {
return '-'
}

return new Date(mtime * 1000).toLocaleDateString(Intl.DateTimeFormat().resolvedOptions().locale, {
const date = new Date((mtime.secs * 1000) + Math.round(mtime.nsecs / 1000))

return date.toLocaleDateString(Intl.DateTimeFormat().resolvedOptions().locale, {
year: 'numeric',
month: 'short',
day: 'numeric',
Expand Down
6 changes: 5 additions & 1 deletion test/files/format-mtime.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ const expect = chai.expect

describe('format-mtime', function () {
it('formats mtime', function () {
expect((new Date(formatMtime(0))).getTime()).to.equal(0)
expect(formatMtime({ secs: 100, nsecs: 0 })).to.include('Jan 1, 1970')
})

it('formats empty mtime', function () {
expect(formatMtime()).to.equal('-')
})
})