Skip to content

Commit aa200cb

Browse files
committed
use rc2, also use pregenerated function for formatting
1 parent f348f9e commit aa200cb

File tree

4 files changed

+13
-15
lines changed

4 files changed

+13
-15
lines changed

lib/constants.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@
77
*/
88

99
module.exports = {
10-
DATE_FORMAT: 'yyyy-mm-dd HH:MM:ss.l o',
11-
DATE_FORMAT_SIMPLE: 'HH:MM:ss.l',
12-
1310
/**
1411
* @type {K_ERROR_LIKE_KEYS}
1512
*/

lib/utils/format-time.js

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,18 @@
22

33
module.exports = formatTime
44

5-
const {
6-
DATE_FORMAT,
7-
DATE_FORMAT_SIMPLE
8-
} = require('../constants')
9-
10-
const { dateFormat: dateformat, DateFormatter } = require('@pinojs/dateformat')
5+
const { dateformat, DateFormatter } = require('@pinojs/dateformat')
116
const createDate = require('./create-date')
127
const isValidDate = require('./is-valid-date')
138

14-
const dateFormatterSimple = new DateFormatter(DATE_FORMAT_SIMPLE)
15-
const dateFormatter = new DateFormatter(DATE_FORMAT)
9+
// 'HH:MM:ss.l'
10+
const simpleDateFormatter = new DateFormatter(function simple (date) {
11+
return `${this.HH(date)}:${this.MM(date)}:${this.ss(date)}.${this.l(date)}`
12+
})
13+
// 'yyyy-mm-dd HH:MM:ss.l o'
14+
const standardDateFormatter = new DateFormatter(function standard (date) {
15+
return `${this.yyyy(date)}-${this.mm(date)}-${this.dd(date)} ${this.HH(date)}:${this.MM(date)}:${this.ss(date)}.${this.l(date)} ${this.o(date)}`
16+
})
1617

1718
/**
1819
* Checks if the given format string is a UTC format.
@@ -97,7 +98,7 @@ function formatTime (epoch, translateTime = false) {
9798
}
9899

99100
if (translateTime === true) {
100-
return dateFormatterSimple.format(instant)
101+
return simpleDateFormatter.format(instant)
101102
}
102103

103104
if (translateTime[3] !== ':') {
@@ -106,7 +107,7 @@ function formatTime (epoch, translateTime = false) {
106107

107108
if (isSYS(translateTime)) {
108109
if (isSysStandard(translateTime)) {
109-
return dateFormatter.format(instant)
110+
return standardDateFormatter.format(instant)
110111
}
111112
return dateformat(instant, translateTime.slice(4))
112113
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
"test"
3535
],
3636
"dependencies": {
37-
"@pinojs/dateformat": "^1.0.0-rc.1",
37+
"@pinojs/dateformat": "^1.0.0-rc.2",
3838
"colorette": "^2.0.7",
3939
"fast-copy": "^3.0.2",
4040
"fast-safe-stringify": "^2.1.1",

test/basic.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const os = require('node:os')
77
const { describe, test, beforeEach, afterEach } = require('node:test')
88
const match = require('@jsumners/assert-match')
99
const pino = require('pino')
10-
const { dateFormat: dateformat } = require('@pinojs/dateformat')
10+
const { dateformat } = require('@pinojs/dateformat')
1111
const rimraf = require('rimraf')
1212
const { join } = require('node:path')
1313
const fs = require('node:fs')

0 commit comments

Comments
 (0)