Skip to content

Commit

Permalink
Adding clip duration to event details (#4133)
Browse files Browse the repository at this point in the history
* Adding clip length in s to Events View

* added function returning human readable length

* switched to date-fns functions for formatting

* fixed switched start/end time, changed length to duration
  • Loading branch information
banthungprong authored Nov 2, 2022
1 parent 8163afc commit 552638d
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions web/src/routes/Events.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import CalendarIcon from '../icons/Calendar';
import Calendar from '../components/Calendar';
import Button from '../components/Button';
import Dialog from '../components/Dialog';
import { fromUnixTime, intervalToDuration, formatDuration } from 'date-fns';

const API_LIMIT = 25;

Expand All @@ -37,6 +38,16 @@ const monthsAgo = (num) => {
return new Date(date.getFullYear(), date.getMonth(), date.getDate()).getTime() / 1000;
};

const clipDuration = (start_time, end_time) => {
const start = fromUnixTime(start_time);
const end = fromUnixTime(end_time);
let duration = 'In Progress';
if (end_time) {
duration = formatDuration(intervalToDuration({ start, end }));
}
return duration;
}

export default function Events({ path, ...props }) {
const apiHost = useApiHost();
const [searchParams, setSearchParams] = useState({
Expand Down Expand Up @@ -459,7 +470,7 @@ export default function Events({ path, ...props }) {
</div>
<div className="text-sm">
{new Date(event.start_time * 1000).toLocaleDateString()}{' '}
{new Date(event.start_time * 1000).toLocaleTimeString()}
{new Date(event.start_time * 1000).toLocaleTimeString()} ({clipDuration(event.start_time, event.end_time)})
</div>
<div className="capitalize text-sm flex align-center mt-1">
<Camera className="h-5 w-5 mr-2 inline" />
Expand Down Expand Up @@ -522,9 +533,9 @@ export default function Events({ path, ...props }) {
],
}}
seekOptions={{ forward: 10, back: 5 }}
onReady={() => {}}
onReady={() => { }}
/>
) : null }
) : null}

{((eventDetailType == 'image') || !event.has_clip) ? (
<div className="flex justify-center">
Expand All @@ -538,7 +549,7 @@ export default function Events({ path, ...props }) {
alt={`${event.label} at ${(event.top_score * 100).toFixed(0)}% confidence`}
/>
</div>
) : null }
) : null}
</div>
</div>
</div>
Expand Down

0 comments on commit 552638d

Please sign in to comment.