chore(CountDown): extract useCountDown

This commit is contained in:
chenjiahan
2020-10-06 09:22:54 +08:00
parent 38334b4158
commit 8e5c8f2f89
5 changed files with 203 additions and 167 deletions
+4 -32
View File
@@ -1,37 +1,9 @@
import { padZero } from '../utils';
import { CurrentTime } from './use-count-down';
export type TimeData = {
days: number;
hours: number;
minutes: number;
seconds: number;
milliseconds: number;
};
const SECOND = 1000;
const MINUTE = 60 * SECOND;
const HOUR = 60 * MINUTE;
const DAY = 24 * HOUR;
export function parseTimeData(time: number): TimeData {
const days = Math.floor(time / DAY);
const hours = Math.floor((time % DAY) / HOUR);
const minutes = Math.floor((time % HOUR) / MINUTE);
const seconds = Math.floor((time % MINUTE) / SECOND);
const milliseconds = Math.floor(time % SECOND);
return {
days,
hours,
minutes,
seconds,
milliseconds,
};
}
export function parseFormat(format: string, timeData: TimeData): string {
const { days } = timeData;
let { hours, minutes, seconds, milliseconds } = timeData;
export function parseFormat(format: string, currentTime: CurrentTime): string {
const { days } = currentTime;
let { hours, minutes, seconds, milliseconds } = currentTime;
if (format.indexOf('DD') === -1) {
hours += days * 24;