import React from 'react';
import Text from 'antd/es/typography/Text';
import moment, { Moment } from 'moment';

const DEFAULT_FORMAT = 'YYYY-MM-DD HH:mm:ss';

export interface TimeTextProps {
  value?: Moment;
  format?: string;
}

/**
 * 时间文本
 *
 */
const TimeText: React.FC<TimeTextProps> = (props) => {
  const { value, format } = props;
  const txtFormat = format ? format : DEFAULT_FORMAT;
  const txt = value ? moment(value).format(txtFormat) : '-';
  return <Text>{txt}</Text>;
};

export default TimeText;
