1 import React from 'react';
2 import Icon from '../components/common/Icon';
4 export const formatTime = result => {
5 const hours = `${Math.floor(result.time / 60 / 60)}`;
6 let minutes = `${Math.floor((result.time / 60) % 60)}`;
7 let seconds = `${Math.floor(result.time % 60)}`;
8 while (minutes.length < 2) {
9 minutes = `0${minutes}`;
11 while (seconds.length < 2) {
12 seconds = `0${seconds}`;
14 return `${hours}:${minutes}:${seconds}`;
17 export const getIcon = (result, maySee) => {
18 if (!result || !result.has_finished) {
19 return <Icon.PENDING className="text-muted" size="lg" />;
21 if (result.forfeit && maySee) {
22 return <Icon.FORFEIT className="text-danger" size="lg" />;
24 if (result.placement === 1 && maySee) {
25 return <Icon.FIRST_PLACE className="text-gold" size="lg" />;
27 if (result.placement === 2 && maySee) {
28 return <Icon.SECOND_PLACE className="text-silver" size="lg" />;
30 if (result.placement === 3 && maySee) {
31 return <Icon.THIRD_PLACE className="text-bronze" size="lg" />;
33 return <Icon.FINISHED className="text-success" size="lg" />;
36 export const getTime = (result, maySee) => {
37 if (!result || !maySee) {
41 return formatTime(result);
49 export const parseTime = str => {
50 if (!str) return null;
51 return `${str}`.split(/[-.: ]+/).reduce((acc,time) => (60 * acc) + +time, 0);