Skip to content
This repository has been archived by the owner on Jul 17, 2023. It is now read-only.

Commit

Permalink
fix error if date is undefined
Browse files Browse the repository at this point in the history
  • Loading branch information
SerayaEryn committed Apr 22, 2019
1 parent 9e907e2 commit 18539e1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
5 changes: 4 additions & 1 deletion DateFormatter.js
Expand Up @@ -111,7 +111,10 @@ const knownFormats = {
if (options.cache) {
generator.add(`
if (!this.cache) {
this.cache = now ? now.getTime() + '' : Date.now() + ''
if (!now) {
now = new Date()
}
this.cache = now.getTime() + ''
setTimeout(this._clearCache, 1000 - now.getMilliseconds())
}
return this.cache
Expand Down
13 changes: 13 additions & 0 deletions test/base.test.js
Expand Up @@ -30,6 +30,19 @@ test('x', (t) => {
t.strictEquals(formatted, '951879845001')
})

test('x', (t) => {
t.plan(2)
var dateFormatter = new DateFormatter({
dateFormat: 'x',
cache: true
})

var formatted = dateFormatter.format()

t.ok(dateFormatter.cache, '951879845001')
t.ok(formatted, '951879845001')
})

test('YYYYMMDD', (t) => {
t.plan(1)
var date = new Date(2000, 2, 1, 3, 4, 5, 1)
Expand Down

0 comments on commit 18539e1

Please sign in to comment.