-
Notifications
You must be signed in to change notification settings - Fork 189
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add new function of datetime calculator
- Loading branch information
1 parent
268a35e
commit cdda0c0
Showing
4 changed files
with
44 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,28 @@ | ||
function calculator(startedAt = '2021-12-07') { | ||
const dateValue = startedAt; | ||
const date = Math.abs((new Date(dateValue).getTime() / 1000).toFixed(0)); | ||
const currentDate = Math.abs((new Date().getTime() / 1000).toFixed(0)); | ||
const buildDateCaltulator = document.getElementById('calculatorData'); | ||
const buildLoading = document.getElementById('build-loading'); | ||
const buildSuccess = document.getElementById('build-success'); | ||
const buildFail = document.getElementById('build-fail'); | ||
|
||
export default function calculatorBuildInfo(data) { | ||
const startedAt = data.startedAt; | ||
const stoppedAt = data.stoppedAt; | ||
const result = data.result; | ||
|
||
if (result == 0 && stoppedAt != 'null') { | ||
buildSuccess.removeAttribute('hidden'); | ||
} else if (result != 0 && stoppedAt != 'null') { | ||
buildFail.removeAttribute('hidden'); | ||
} else { | ||
buildLoading.removeAttribute('hidden'); | ||
} | ||
|
||
const date = Math.abs((new Date(startedAt).getTime() / 1000).toFixed(0)); | ||
const currentDate = Math.abs((new Date(stoppedAt).getTime() / 1000).toFixed(0)); | ||
|
||
const diff = currentDate - date; | ||
const hours = Math.floor(diff / 3600) % 24; | ||
const minutes = Math.floor(diff / 60) % 60; | ||
const seconds = diff % 60; | ||
|
||
document.getElementById('calculatorData').innerHTML = `${hours} h ${minutes} m ${seconds} s`; | ||
buildDateCaltulator.innerText = `${hours} h ${minutes} m ${seconds} s`; | ||
} | ||
|
||
setInterval(calculator, 1000); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,9 @@ | ||
import checkForBuild from '../build-log/check-for-build.js'; | ||
import calculatorBuildInfo from '../build-log/datetime-calculator.js'; | ||
|
||
window.addEventListener('load', () => { | ||
checkForBuild(); | ||
calculatorBuildInfo(); | ||
setInterval(calculatorBuildInfo, 1000); | ||
setInterval(checkForBuild, 5000); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters