Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Comment thread
andreilakatos marked this conversation as resolved.
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,57 @@ export const durationInWords = (

const numberWithDelimiter = x =>
x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',');

export const isDelayed = ({ startAt, startedAt }) => {
if (
startAt == null ||
startedAt == null ||
startAt === '' ||
startedAt === ''
) {
return false;
}

const a = new Date(startAt);
const b = new Date(startedAt);

if (Number.isNaN(a.getTime()) || Number.isNaN(b.getTime())) {
return false;
}

a.setMilliseconds(0);
b.setMilliseconds(0);

return a.getTime() !== b.getTime();
};

export const parseUsernameLinkHref = usernamePath => {
if (!usernamePath || typeof usernamePath !== 'string') {
return null;
}

const match = usernamePath.match(/href=(["'])(.*?)\1/i);

return match ? match[2] : null;
};

export const formatTaskDuration = (startedAtStr, endedAtStr, state) => {
if (state !== 'stopped' || !startedAtStr || !endedAtStr) {
return __('N/A');
}

const startMs = new Date(startedAtStr).getTime();
const endMs = new Date(endedAtStr).getTime();

if (Number.isNaN(startMs) || Number.isNaN(endMs) || endMs < startMs) {
return __('N/A');
}

const duration = durationInWords(startedAtStr, endedAtStr);

if (typeof duration === 'string') {
return duration;
}

return duration.text;
};
Loading
Loading