Skip to content
This repository has been archived by the owner on Oct 9, 2024. It is now read-only.

Commit

Permalink
Moved helper functions outside export default fn in TimeInterval.
Browse files Browse the repository at this point in the history
  • Loading branch information
dc-andysign committed Jan 24, 2024
1 parent 0d329aa commit 67fd667
Showing 1 changed file with 28 additions and 28 deletions.
56 changes: 28 additions & 28 deletions src/pages/components/CertificateTimeInterval.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<>
<FixedWidthSmallDiv>
Expand Down

0 comments on commit 67fd667

Please sign in to comment.