Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pull] master from techgaun:master #2

Merged
merged 5 commits into from
Feb 5, 2025
Merged
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
1 change: 0 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
<script type="text/javascript" src="https://cdn.datatables.net/1.10.24/js/dataTables.bootstrap4.min.js"></script>
<script type="text/javascript" src="https://cdn.datatables.net/searchbuilder/1.0.1/js/dataTables.searchBuilder.min.js"></script>
<script type="text/javascript" src="https://cdn.datatables.net/searchbuilder/1.0.1/js/searchBuilder.bootstrap4.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.0/moment.min.js"></script>
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/[email protected]/lib/darkmode-js.min.js"></script>

<style>
Expand Down
25 changes: 23 additions & 2 deletions js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,28 @@ function updateDT(data) {
.draw();
}

// Will replace with JavaScript Temporal once supported in major browsers
function howLongAgo(date) {
const relTime = new Intl.RelativeTimeFormat('en', { style: 'long' });
const startDateMilliseconds = Date.parse(date);
const endDateMilliseconds = Date.parse(new Date());

const elapsedSeconds = (endDateMilliseconds - startDateMilliseconds) / 1000;
const elapsedHours = elapsedSeconds / 60 / 60;
const elapsedDays = elapsedHours / 24;
const elapsedMonths = elapsedDays / 30;
const elapsedYears = elapsedDays / 365.25;

if(elapsedHours < 24)
return `${relTime.format(-Math.floor(elapsedHours), 'hour')}`;
else if(elapsedDays < 31)
return `${relTime.format(-Math.floor(elapsedDays, 'day'))}`;
else if(elapsedMonths < 12)
return `${relTime.format(-Math.floor(elapsedMonths, 'month'))}`;
else
return `${relTime.format(-Math.floor(elapsedYears, 'year'))}`;
}

function initDT() {
// Create ordered Object with column name and mapped display name
window.columnNamesMap = [
Expand All @@ -81,7 +103,6 @@ function initDT() {
.indexOf(sortColName);

// Use first index for readable column name
// we use moment's fromNow() if we are rendering for `pushed_at`; better solution welcome
window.forkTable = $('#forkTable').DataTable({
columns: window.columnNamesMap.map(colNM => {
return {
Expand All @@ -90,7 +111,7 @@ function initDT() {
colNM[1] === 'pushed_at'
? (data, type, _row) => {
if (type === 'display') {
return moment(data).fromNow();
return howLongAgo(data);
}
return data;
}
Expand Down