From 67cb6aaffee12f058e6245e9a98ec39d6131ff5f Mon Sep 17 00:00:00 2001 From: Lucas Henrique <lhs_azevedo@hotmail.com> Date: Fri, 30 Oct 2020 21:27:40 -0300 Subject: [PATCH] Convert common time helpers to Typescript (#2391) --- .../js/src/common/helpers/{fullTime.js => fullTime.tsx} | 8 ++++---- .../js/src/common/helpers/{humanTime.js => humanTime.tsx} | 7 +++---- framework/core/js/src/common/utils/humanTime.ts | 3 +++ 3 files changed, 10 insertions(+), 8 deletions(-) rename framework/core/js/src/common/helpers/{fullTime.js => fullTime.tsx} (67%) rename framework/core/js/src/common/helpers/{humanTime.js => humanTime.tsx} (78%) diff --git a/framework/core/js/src/common/helpers/fullTime.js b/framework/core/js/src/common/helpers/fullTime.tsx similarity index 67% rename from framework/core/js/src/common/helpers/fullTime.js rename to framework/core/js/src/common/helpers/fullTime.tsx index 4229df81b..00bae7a9c 100644 --- a/framework/core/js/src/common/helpers/fullTime.js +++ b/framework/core/js/src/common/helpers/fullTime.tsx @@ -1,11 +1,11 @@ +import dayjs from 'dayjs'; +import * as Mithril from 'mithril'; + /** * The `fullTime` helper displays a formatted time string wrapped in a <time> * tag. - * - * @param {Date} time - * @return {Object} */ -export default function fullTime(time) { +export default function fullTime(time: Date): Mithril.Vnode { const d = dayjs(time); const datetime = d.format(); diff --git a/framework/core/js/src/common/helpers/humanTime.js b/framework/core/js/src/common/helpers/humanTime.tsx similarity index 78% rename from framework/core/js/src/common/helpers/humanTime.js rename to framework/core/js/src/common/helpers/humanTime.tsx index 1c6ffb77b..c71f58258 100644 --- a/framework/core/js/src/common/helpers/humanTime.js +++ b/framework/core/js/src/common/helpers/humanTime.tsx @@ -1,14 +1,13 @@ +import dayjs from 'dayjs'; +import * as Mithril from 'mithril'; import humanTimeUtil from '../utils/humanTime'; /** * The `humanTime` helper displays a time in a human-friendly time-ago format * (e.g. '12 days ago'), wrapped in a <time> tag with other information about * the time. - * - * @param {Date} time - * @return {Object} */ -export default function humanTime(time) { +export default function humanTime(time: Date): Mithril.Vnode { const d = dayjs(time); const datetime = d.format(); diff --git a/framework/core/js/src/common/utils/humanTime.ts b/framework/core/js/src/common/utils/humanTime.ts index 79216aa8a..6586658ba 100644 --- a/framework/core/js/src/common/utils/humanTime.ts +++ b/framework/core/js/src/common/utils/humanTime.ts @@ -1,3 +1,6 @@ +import dayjs from 'dayjs'; +import 'dayjs/plugin/relativeTime'; + /** * The `humanTime` utility converts a date to a localized, human-readable time- * ago string.