aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/mixin/CommonMixin.js
blob: 0e8ed32e84037454a6a165e40a75ada56976addd (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import {PropTypes} from 'react';
import enUs from '../locale/en_US';
import {getFormatter} from '../util/index';

export default {
  propTypes: {
    prefixCls: PropTypes.string,
    locale: PropTypes.object,
  },

  getDefaultProps() {
    return {
      prefixCls: 'rc-time-picker',
      locale: enUs,
    };
  },

  getFormatter() {
    const formatter = this.props.formatter;
    const locale = this.props.locale;
    if (formatter) {
      if (formatter === this.lastFormatter) {
        return this.normalFormatter;
      }
      this.normalFormatter = getFormatter(formatter, locale);
      this.lastFormatter = formatter;
      return this.normalFormatter;
    }
    if (!this.showSecond) {
      if (!this.notShowSecondFormatter) {
        this.notShowSecondFormatter = getFormatter('HH:mm', locale);
      }
      return this.notShowSecondFormatter;
    }
    if (!this.showHour) {
      if (!this.notShowHourFormatter) {
        this.notShowHourFormatter = getFormatter('mm:ss', locale);
      }
      return this.notShowHourFormatter;
    }
    if (!this.normalFormatter) {
      this.normalFormatter = getFormatter('HH:mm:ss', locale);
    }
    return this.normalFormatter;
  },
};