remove moment deps in Countdown (#21108)

This commit is contained in:
Teng YANG 2020-01-27 10:08:02 +08:00 committed by 二货机器人
parent bf56026809
commit 8f5ea54cc7
2 changed files with 3 additions and 7 deletions

View File

@ -1,6 +1,4 @@
import * as React from 'react';
import * as moment from 'moment';
import interopDefault from '../_util/interopDefault';
import Statistic, { StatisticProps } from './Statistic';
import { formatCountdown, countdownValueType, FormatConfig } from './utils';
@ -13,7 +11,7 @@ interface CountdownProps extends StatisticProps {
}
function getTime(value?: countdownValueType) {
return interopDefault(moment)(value).valueOf();
return new Date(value as any).getTime();
}
class Countdown extends React.Component<CountdownProps, {}> {

View File

@ -1,7 +1,5 @@
import * as React from 'react';
import * as moment from 'moment';
import padStart from 'lodash/padStart';
import interopDefault from '../_util/interopDefault';
export type valueType = number | string;
export type countdownValueType = valueType | string;
@ -64,8 +62,8 @@ export function formatTimeStr(duration: number, format: string) {
export function formatCountdown(value: countdownValueType, config: CountdownFormatConfig) {
const { format = '' } = config;
const target = interopDefault(moment)(value).valueOf();
const current = interopDefault(moment)().valueOf();
const target = new Date(value).getTime();
const current = Date.now();
const diff = Math.max(target - current, 0);
return formatTimeStr(diff, format);