Repository: pinojs/pino (js)

Issue:
Invalid time value with prettyPrint and timestamp:false
> node app.js | pino

```
/myp/node_modules/pino/pretty.js:130
    return new Date(time).toISOString()

RangeError: Invalid time value
```

This happens when you set `prettyPrint` true (or pipe the output to pino without timestamps)

Pull request description:
Make pretty() do not crash if there is no timestamp
Fixes #243

Patch:
diff --git a/pretty.js b/pretty.js
index 1cc6a54..87e6de2 100755
--- a/pretty.js
+++ b/pretty.js
@@ -105,8 +105,8 @@ function pretty (opts) {
     }
 
     line = (levelFirst)
-        ? asColoredLevel(value) + ' [' + asISODate(value.time) + ']'
-        : '[' + asISODate(value.time) + '] ' + asColoredLevel(value)
+        ? asColoredLevel(value) + ' ' + formatTime(value)
+        : formatTime(value, ' ') + asColoredLevel(value)
 
     line += ' ('
     if (value.name) {
@@ -130,6 +130,19 @@ function pretty (opts) {
     return new Date(time).toISOString()
   }
 
+  function formatTime (value, after) {
+    after = after || ''
+    try {
+      if (!value || !value.time) {
+        return ''
+      } else {
+        return '[' + asISODate(value.time) + ']' + after
+      }
+    } catch (_) {
+      return ''
+    }
+  }
+
   function asColoredLevel (value) {
     if (levelColors.hasOwnProperty(value.level)) {
       return levelColors[value.level](levels[value.level])


Test patch:
diff --git a/test/pretty.test.js b/test/pretty.test.js
index daa7274..fbb40d5 100644
--- a/test/pretty.test.js
+++ b/test/pretty.test.js
@@ -231,3 +231,21 @@ test('can be enabled via constructor with pretty configuration', function (t) {
     t.notEqual(actual.match(/^INFO.*h/), null)
   })
 })
+
+test('works without time', function (t) {
+  t.plan(4)
+  var prettier = pretty()
+  prettier.pipe(split(function (line) {
+    t.ok(line.match(/.*hello world$/), 'end of line matches')
+    t.ok(line.match(/^INFO.*/), 'includes level')
+    t.ok(line.indexOf('' + process.pid) > 0, 'includes pid')
+    t.ok(line.indexOf('' + hostname) > 0, 'includes hostname')
+    return line
+  }))
+
+  var instance = pino({
+    timestamp: null
+  }, prettier)
+
+  instance.info('hello world')
+})