1 | import { datejs } from '../util';
|
2 | import { DATE_INPUT_TYPE } from './constant';
|
3 |
|
4 | export function setTime(targetVal, sourceVal) {
|
5 | if (sourceVal && targetVal) {
|
6 | return targetVal.hour(sourceVal.hour()).minute(sourceVal.minute()).second(sourceVal.second()).millisecond(sourceVal.millisecond());
|
7 | }
|
8 | return targetVal;
|
9 | }
|
10 |
|
11 | export function switchInputType(inputType) {
|
12 | var BEGIN = DATE_INPUT_TYPE.BEGIN,
|
13 | END = DATE_INPUT_TYPE.END;
|
14 |
|
15 | return inputType === BEGIN ? END : BEGIN;
|
16 | }
|
17 |
|
18 | export function mode2unit(mode) {
|
19 | return mode === 'date' ? 'day' : mode;
|
20 | }
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 | export function fmtValue(value, fmt) {
|
29 | var formater = function formater(v, idx) {
|
30 | var _fmt = fmt;
|
31 |
|
32 | if (Array.isArray(fmt)) {
|
33 | _fmt = fmt[idx];
|
34 | }
|
35 |
|
36 | return v ? typeof _fmt === 'function' ? _fmt(v) : v.format(_fmt) : '';
|
37 | };
|
38 |
|
39 | return Array.isArray(value) ? value.map(function (v, idx) {
|
40 | return formater(v, idx);
|
41 | }) : formater(value);
|
42 | }
|
43 |
|
44 |
|
45 |
|
46 |
|
47 |
|
48 |
|
49 |
|
50 | export function isValueChanged(newValue, oldValue) {
|
51 | return Array.isArray(newValue) ? isValueChanged(newValue[0], oldValue && oldValue[0]) || isValueChanged(newValue[1], oldValue && oldValue[1]) : newValue !== oldValue && !datejs(newValue).isSame(oldValue);
|
52 | } |
\ | No newline at end of file |