From 67fd66719356aad36c773c6c917be8a14e843905 Mon Sep 17 00:00:00 2001 From: dc-andysign Date: Wed, 24 Jan 2024 11:06:45 +0000 Subject: [PATCH] Moved helper functions outside export default fn in TimeInterval. --- .../components/CertificateTimeInterval.js | 56 +++++++++---------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/src/pages/components/CertificateTimeInterval.js b/src/pages/components/CertificateTimeInterval.js index b89b40c..60cbdd0 100644 --- a/src/pages/components/CertificateTimeInterval.js +++ b/src/pages/components/CertificateTimeInterval.js @@ -3,36 +3,36 @@ import styled from 'styled-components' import StartEndSpacerSVG from '../../assets/images/start-end-spacer-bg.svg' -export default function CertificateTimeInterval({ sTimestamp, eTimestamp }) { - function calcTimeInterval(s, e) { - const i = new Date(e) - new Date(s) - return i - } - function convIntervalToHoursAndMins(i) { - const m = Math.floor(i / (1000 * 60)) % 60 - const h = Math.floor(i / (1000 * 60 * 60)) - const str = `${h.toString().padStart(2, '0')}H ${m.toString().padStart(2, '0')}M` - return str - } - function convIntervalToMonthsAndDays(i) { - let d = Math.floor(i / (1000 * 60 * 60 * 24)) % 30 - let m = Math.floor(i / (1000 * 60 * 60 * 24 * 30)) - let str = `${m.toString().padStart(2, '0')}m ${d.toString().padStart(2, '0')}d` - if (m > 99) { - d = 0 - m = 99 - str = `>${m.toString().padStart(2, '0')}m${d.toString().padStart(2, '0')}d` - } - return str +const calcTimeInterval = (s, e) => { + return new Date(e) - new Date(s) +} +const convIntervalToHoursAndMins = (i) => { + const m = Math.floor(i / (1000 * 60)) % 60 + const h = Math.floor(i / (1000 * 60 * 60)) + const str = `${h.toString().padStart(2, '0')}H ${m.toString().padStart(2, '0')}M` + return str +} +const convIntervalToMonthsAndDays = (i) => { + let d = Math.floor(i / (1000 * 60 * 60 * 24)) % 30 + let m = Math.floor(i / (1000 * 60 * 60 * 24 * 30)) + let str = `${m.toString().padStart(2, '0')}m ${d.toString().padStart(2, '0')}d` + if (m > 99) { + d = 0 + m = 99 + str = `>${m.toString().padStart(2, '0')}m${d.toString().padStart(2, '0')}d` } - function convIntervalToStr(s, e) { - const i = calcTimeInterval(s, e) - if (i > 1000 * 24 * 60 * 60) { - return convIntervalToMonthsAndDays(i) - } else { - return convIntervalToHoursAndMins(i) - } + return str +} +const convIntervalToStr = (s, e) => { + const i = calcTimeInterval(s, e) + if (i > 1000 * 24 * 60 * 60) { + return convIntervalToMonthsAndDays(i) + } else { + return convIntervalToHoursAndMins(i) } +} + +export default function CertificateTimeInterval({ sTimestamp, eTimestamp }) { return ( <>