MCPcopy Index your code
hub / github.com/kenberkeley/react-demo / dataTimeFormatter

Function dataTimeFormatter

src/utils/dateTimeFormatter.js:19–40  ·  view source on GitHub ↗
(time, type)

Source from the content-addressed store, hash-verified

17 * @return {String}
18 */
19export default function dataTimeFormatter(time, type) {
20 let date = new Date(time)
21 let year = date.getFullYear()
22 let month = date.getMonth() + 1
23 let day = date.getDate()
24 let hours = date.getHours()
25 let minutes = date.getMinutes()
26 let second = date.getSeconds()
27
28 switch (type) {
29 case 0: // 01-05
30 return `${zerofill(month)}-${zerofill(day)}`
31 case 1: // 11:12
32 return `${zerofill(hours)}-${zerofill(minutes)}`
33 case 2: // 2015-01-05
34 return `${year}-${zerofill(month)}-${zerofill(day)}`
35 case 3: // 2015-01-05 11:12
36 return `${year}-${zerofill(month)}-${zerofill(day)} ${zerofill(hours)}:${zerofill(minutes)}`
37 default: // 2015-01-05 11:12:13
38 return `${year}-${zerofill(month)}-${zerofill(day)} ${zerofill(hours)}:${zerofill(minutes)}:${zerofill(second)}`
39 }
40}

Callers

nothing calls this directly

Calls 1

zerofillFunction · 0.85

Tested by

no test coverage detected