mirror of
https://github.com/ant-design/ant-design.git
synced 2025-01-19 06:43:16 +08:00
remove moment deps in Countdown (#21108)
This commit is contained in:
parent
bf56026809
commit
8f5ea54cc7
@ -1,6 +1,4 @@
|
|||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
import * as moment from 'moment';
|
|
||||||
import interopDefault from '../_util/interopDefault';
|
|
||||||
import Statistic, { StatisticProps } from './Statistic';
|
import Statistic, { StatisticProps } from './Statistic';
|
||||||
import { formatCountdown, countdownValueType, FormatConfig } from './utils';
|
import { formatCountdown, countdownValueType, FormatConfig } from './utils';
|
||||||
|
|
||||||
@ -13,7 +11,7 @@ interface CountdownProps extends StatisticProps {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function getTime(value?: countdownValueType) {
|
function getTime(value?: countdownValueType) {
|
||||||
return interopDefault(moment)(value).valueOf();
|
return new Date(value as any).getTime();
|
||||||
}
|
}
|
||||||
|
|
||||||
class Countdown extends React.Component<CountdownProps, {}> {
|
class Countdown extends React.Component<CountdownProps, {}> {
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
import * as moment from 'moment';
|
|
||||||
import padStart from 'lodash/padStart';
|
import padStart from 'lodash/padStart';
|
||||||
import interopDefault from '../_util/interopDefault';
|
|
||||||
|
|
||||||
export type valueType = number | string;
|
export type valueType = number | string;
|
||||||
export type countdownValueType = valueType | string;
|
export type countdownValueType = valueType | string;
|
||||||
@ -64,8 +62,8 @@ export function formatTimeStr(duration: number, format: string) {
|
|||||||
|
|
||||||
export function formatCountdown(value: countdownValueType, config: CountdownFormatConfig) {
|
export function formatCountdown(value: countdownValueType, config: CountdownFormatConfig) {
|
||||||
const { format = '' } = config;
|
const { format = '' } = config;
|
||||||
const target = interopDefault(moment)(value).valueOf();
|
const target = new Date(value).getTime();
|
||||||
const current = interopDefault(moment)().valueOf();
|
const current = Date.now();
|
||||||
const diff = Math.max(target - current, 0);
|
const diff = Math.max(target - current, 0);
|
||||||
|
|
||||||
return formatTimeStr(diff, format);
|
return formatTimeStr(diff, format);
|
||||||
|
Loading…
Reference in New Issue
Block a user