X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=resources%2Fjs%2Fhelpers%2FResult.js;h=205a42b27325050800c4fe55f728f43de1d0c8c0;hb=0a4af7267374d1a750ed07e9c4b491fea42490af;hp=633294de1d051574c46f52fc3b64490ce7780125;hpb=edd0e97bfdc544114f30bf4c13a929631c44a555;p=alttp.git
diff --git a/resources/js/helpers/Result.js b/resources/js/helpers/Result.js
index 633294d..205a42b 100644
--- a/resources/js/helpers/Result.js
+++ b/resources/js/helpers/Result.js
@@ -1,3 +1,6 @@
+import React from 'react';
+import Icon from '../components/common/Icon';
+
export const formatTime = result => {
const hours = `${Math.floor(result.time / 60 / 60)}`;
let minutes = `${Math.floor((result.time / 60) % 60)}`;
@@ -11,6 +14,46 @@ export const formatTime = result => {
return `${hours}:${minutes}:${seconds}`;
};
+export const getIcon = (result, maySee) => {
+ if (!result || !result.has_finished) {
+ return ;
+ }
+ if (result.forfeit && maySee) {
+ return ;
+ }
+ if (result.placement === 1 && maySee) {
+ return ;
+ }
+ if (result.placement === 2 && maySee) {
+ return ;
+ }
+ if (result.placement === 3 && maySee) {
+ return ;
+ }
+ return ;
+};
+
+export const getTime = (result, maySee) => {
+ if (!result || !maySee) {
+ return null;
+ }
+ if (result.time) {
+ return formatTime(result);
+ }
+ if (result.forfeit) {
+ return 'DNF';
+ }
+ return '?';
+};
+
+export const parseTime = str => {
+ if (!str) return null;
+ return `${str}`.split(/[-.: ]+/).reduce((acc,time) => (60 * acc) + +time, 0);
+};
+
export default {
formatTime,
+ getIcon,
+ getTime,
+ parseTime,
};