updated function

This commit is contained in:
Jack 2021-09-10 14:44:59 +01:00
parent a4d8efad1a
commit c09dd2018a
4 changed files with 23 additions and 20 deletions

View file

@ -13,7 +13,11 @@ export function update() {
// let tm = Math.floor((DB.getSnapshot().globalStats.time % 3600) / 60);
// let ts = Math.floor((DB.getSnapshot().globalStats.time % 3600) % 60);
$(".pageAccount .globalTimeTyping .val").text(
Misc.secondsToString(Math.round(DB.getSnapshot().globalStats.time), true)
Misc.secondsToString(
Math.round(DB.getSnapshot().globalStats.time),
true,
true
)
);
}
if (DB.getSnapshot().globalStats.started != undefined) {

View file

@ -360,6 +360,7 @@ export let accountActivity = new Chart(
if (tooltipItem.datasetIndex === 0) {
return `Time Typing: ${Misc.secondsToString(
Math.round(resultData.y),
true,
true
)}\nTests Completed: ${resultData.amount}`;
} else if (tooltipItem.datasetIndex === 1) {

View file

@ -509,7 +509,7 @@ export function getGibberish() {
return ret;
}
export function secondsToString(sec, full = false) {
export function secondsToString(sec, fullMinutes = false, fullHours = false) {
const hours = Math.floor(sec / 3600);
const minutes = Math.floor((sec % 3600) / 60);
const seconds = roundTo2((sec % 3600) % 60);
@ -518,13 +518,13 @@ export function secondsToString(sec, full = false) {
let secondsString;
hours < 10 ? (hoursString = "0" + hours) : (hoursString = hours);
minutes < 10 ? (minutesString = "0" + minutes) : (minutesString = minutes);
seconds < 10 && (minutes > 0 || hours > 0 || full)
seconds < 10 && (minutes > 0 || hours > 0 || fullMinutes)
? (secondsString = "0" + seconds)
: (secondsString = seconds);
let ret = "";
if (hours > 0 || full) ret += hoursString + ":";
if (minutes > 0 || hours > 0 || full) ret += minutesString + ":";
if (hours > 0 || fullHours) ret += hoursString + ":";
if (minutes > 0 || hours > 0 || fullMinutes) ret += minutesString + ":";
ret += secondsString;
return ret;
}

View file

@ -1,29 +1,28 @@
import * as Misc from './misc';
import * as DB from './db';
import * as Misc from "./misc";
import * as DB from "./db";
let seconds = 0;
let addedAllToday = false;
let dayToday = null;
export function addSeconds(s){
if (addedAllToday){
export function addSeconds(s) {
if (addedAllToday) {
let nowDate = new Date();
nowDate = nowDate.getDate();
if(nowDate > dayToday){
if (nowDate > dayToday) {
seconds = s;
return
return;
}
}
seconds += s;
}
export function getString(){
let secString = Misc.secondsToString(Math.round(seconds), true);
export function getString() {
let secString = Misc.secondsToString(Math.round(seconds), true, true);
return secString + (addedAllToday === true ? " today" : " session");
}
export async function addAllFromToday(){
export async function addAllFromToday() {
let todayDate = new Date();
todayDate.setSeconds(0);
todayDate.setMinutes(0);
@ -37,7 +36,6 @@ export async function addAllFromToday(){
let results = await DB.getSnapshot().results;
results.forEach((result) => {
let resultDate = new Date(result.timestamp);
resultDate.setSeconds(0);
resultDate.setMinutes(0);
@ -45,11 +43,11 @@ export async function addAllFromToday(){
resultDate.setMilliseconds(0);
resultDate = resultDate.getTime();
if(resultDate >= todayDate){
seconds += result.testDuration + result.incompleteTestSeconds - result.afkDuration;
if (resultDate >= todayDate) {
seconds +=
result.testDuration + result.incompleteTestSeconds - result.afkDuration;
}
});
addedAllToday = true;
}
}