diff --git a/assets/src/bundles/add_forge/create-request.js b/assets/src/bundles/add_forge/create-request.js --- a/assets/src/bundles/add_forge/create-request.js +++ b/assets/src/bundles/add_forge/create-request.js @@ -5,7 +5,8 @@ * See top-level LICENSE file for more information */ -import {handleFetchError, removeUrlFragment, csrfPost} from 'utils/functions'; +import {handleFetchError, removeUrlFragment, csrfPost, + displayHumanReadableDate} from 'utils/functions'; let requestBrowseTable; @@ -93,7 +94,8 @@ columns: [ { data: 'submission_date', - name: 'submission_date' + name: 'submission_date', + render: displayHumanReadableDate }, { data: 'forge_type', diff --git a/assets/src/bundles/add_forge/moderation-dashboard.js b/assets/src/bundles/add_forge/moderation-dashboard.js --- a/assets/src/bundles/add_forge/moderation-dashboard.js +++ b/assets/src/bundles/add_forge/moderation-dashboard.js @@ -5,6 +5,8 @@ * See top-level LICENSE file for more information */ +import {displayHumanReadableDate} from 'utils/functions'; + export function onModerationPageLoad() { populateModerationList(); } @@ -36,7 +38,7 @@ { data: 'submission_date', name: 'submission_date', - render: $.fn.dataTable.render.text() + render: displayHumanReadableDate }, { data: 'forge_type', diff --git a/assets/src/bundles/admin/origin-save.js b/assets/src/bundles/admin/origin-save.js --- a/assets/src/bundles/admin/origin-save.js +++ b/assets/src/bundles/admin/origin-save.js @@ -1,11 +1,12 @@ /** - * Copyright (C) 2018-2021 The Software Heritage developers + * Copyright (C) 2018-2022 The Software Heritage developers * See the AUTHORS file at the top-level directory of this distribution * License: GNU Affero General Public License version 3, or any later version * See top-level LICENSE file for more information */ -import {handleFetchError, csrfPost, htmlAlert} from 'utils/functions'; +import {handleFetchError, csrfPost, htmlAlert, + displayHumanReadableDate} from 'utils/functions'; import {swhSpinnerSrc} from 'utils/constants'; let authorizedOriginTable; @@ -64,13 +65,7 @@ { data: 'save_request_date', name: 'request_date', - render: (data, type, row) => { - if (type === 'display') { - const date = new Date(data); - return date.toLocaleString(); - } - return data; - } + render: displayHumanReadableDate }, { data: 'visit_type', diff --git a/assets/src/bundles/save/index.js b/assets/src/bundles/save/index.js --- a/assets/src/bundles/save/index.js +++ b/assets/src/bundles/save/index.js @@ -1,12 +1,12 @@ /** - * Copyright (C) 2018-2021 The Software Heritage developers + * Copyright (C) 2018-2022 The Software Heritage developers * See the AUTHORS file at the top-level directory of this distribution * License: GNU Affero General Public License version 3, or any later version * See top-level LICENSE file for more information */ import {csrfPost, handleFetchError, isGitRepoUrl, htmlAlert, removeUrlFragment, - getCanonicalOriginURL} from 'utils/functions'; + getCanonicalOriginURL, displayHumanReadableDate} from 'utils/functions'; import {swhSpinnerSrc} from 'utils/constants'; import artifactFormRowTemplate from './artifact-form-row.ejs'; @@ -160,13 +160,7 @@ { data: 'save_request_date', name: 'request_date', - render: (data, type, row) => { - if (type === 'display') { - const date = new Date(data); - return date.toLocaleString(); - } - return data; - } + render: displayHumanReadableDate }, { data: 'visit_type', diff --git a/assets/src/utils/functions.js b/assets/src/utils/functions.js --- a/assets/src/utils/functions.js +++ b/assets/src/utils/functions.js @@ -143,3 +143,14 @@ return originUrl; } + +export function displayHumanReadableDate(data, type, row) { + // Display iso format date string into a human readable date + // This is expected to be used by date field in datatable listing views + // Example: 3/24/2022, 10:31:08 AM + if (type === 'display') { + const date = new Date(data); + return date.toLocaleString(); + } + return data; +}