UNPKG

976 BJavaScriptView Raw
1import _typeof from 'babel-runtime/helpers/typeof';
2function formatIt(date, form) {
3 var pad = function pad(n) {
4 return n < 10 ? '0' + n : n;
5 };
6 var dateStr = date.getFullYear() + '-' + pad(date.getMonth() + 1) + '-' + pad(date.getDate());
7 var timeStr = pad(date.getHours()) + ':' + pad(date.getMinutes());
8 if (form === 'YYYY-MM-DD') {
9 return dateStr;
10 }
11 if (form === 'HH:mm') {
12 return timeStr;
13 }
14 return dateStr + ' ' + timeStr;
15}
16export function formatFn(instance, value) {
17 var formatsEnum = {
18 date: 'YYYY-MM-DD',
19 time: 'HH:mm',
20 datetime: 'YYYY-MM-DD HH:mm'
21 };
22 var format = instance.props.format;
23
24 var type = typeof format === 'undefined' ? 'undefined' : _typeof(format);
25 if (type === 'string') {
26 return formatIt(value, format);
27 }
28 if (type === 'function') {
29 return format(value);
30 }
31 return formatIt(value, formatsEnum[instance.props.mode]);
32}
\No newline at end of file