UNPKG

1.08 kBJavaScriptView Raw
1const expose = require('./expose');
2const DISPLAYSHORT = 2;
3const MONTHCORRECTION = 1;
4
5/**
6 * @param value
7 * @return {string}
8 */
9const padDate = value =>
10 value
11 .toString()
12 .padStart(DISPLAYSHORT, '0');
13
14/**
15 * @param date
16 * @return {Date}
17 */
18const getDate = date =>
19 new Date(date);
20
21/**
22 * Return the date of an ISO formatted dateTime in human readable (dutch) DD:MM:YYYY
23 *
24 * @param iso
25 * @return {string}
26 */
27function 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 * Return the time of an ISO formatted dateTime in human readable HH:MM:SS
38 *
39 * @param iso
40 * @return {string}
41 */
42function 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
51module.exports = expose({
52 createDate,
53 createTime,
54});