1 | const expose = require('./expose');
|
2 | const DISPLAYSHORT = 2;
|
3 | const MONTHCORRECTION = 1;
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 | const padDate = value =>
|
10 | value
|
11 | .toString()
|
12 | .padStart(DISPLAYSHORT, '0');
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 | const getDate = date =>
|
19 | new Date(date);
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 | function createDate(iso) {
|
28 | const date = getDate(iso);
|
29 | const year = date.getFullYear();
|
30 | const month = padDate(date.getMonth() + MONTHCORRECTION);
|
31 | const day = padDate(date.getDate());
|
32 |
|
33 | return `${day}-${month}-${year}`;
|
34 | }
|
35 |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 |
|
41 |
|
42 | function createTime (iso) {
|
43 | const date = getDate(iso);
|
44 | const hours = padDate(date.getHours());
|
45 | const minutes = padDate(date.getMinutes());
|
46 | const seconds = padDate(date.getSeconds());
|
47 |
|
48 | return `${hours}:${minutes}:${seconds}`;
|
49 | }
|
50 |
|
51 | module.exports = expose({
|
52 | createDate,
|
53 | createTime,
|
54 | });
|