Skip to content

Commit

Permalink
correct time for cooldown
Browse files Browse the repository at this point in the history
  • Loading branch information
saertna committed Oct 17, 2023
1 parent 72511e7 commit 5c5efaf
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 6 deletions.
16 changes: 13 additions & 3 deletions main.js

Large diffs are not rendered by default.

20 changes: 17 additions & 3 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1163,7 +1163,7 @@ function isMinutesPassed(inputDate: Moment, minutesPassed: number): boolean {
return inputDate.isSameOrBefore(minutesAgo);
}

function hoursUntilMinutesPassed(inputDate: Moment, minutesPassed: number): number {
/*function hoursUntilMinutesPassed(inputDate: Moment, minutesPassed: number): number {
const currentTime = window.moment(); // Get the current time
const targetTime = inputDate.clone().add(minutesPassed, 'minutes'); // Calculate target time
Expand All @@ -1173,10 +1173,23 @@ function hoursUntilMinutesPassed(inputDate: Moment, minutesPassed: number): numb
const timeDiff = targetTime.diff(currentTime, 'hours', true); // Calculate the difference in hours
return Math.ceil(timeDiff);
}*/

function hoursUntilMinutesPassed(inputDate: Moment, minutesToPass: number): number {
const currentTime = window.moment(); // Get the current time
const targetTime = inputDate.clone().add(minutesToPass, 'minutes'); // Calculate the target time

if (targetTime.isAfter(currentTime)) {
const hoursRemaining = targetTime.diff(currentTime, 'hours');
return hoursRemaining;
} else {
return 0;
}
}




async function createAvatarFile(app: App, fileName: string): Promise<void> {
//settings: GamificationPluginSettings;
// Define the file name and content
Expand Down Expand Up @@ -1401,9 +1414,10 @@ class MultiSelectModal extends Modal {
console.log(`Booster ${labelText} is still in cooldown for ${window.moment(this.gamificationInstance.getSetting(this.getBoosterDateFromName(labelText)), 'YYYY-MM-DD HH:mm:ss'),this.getBoosterCooldownFromName(labelText)/60} hours`)
label.innerHTML = `${labelText} : (${stock})`;
//const useButton = document.createElement('button');
useButton.innerText = `cooldown ${window.moment(this.gamificationInstance.getSetting(this.getBoosterDateFromName(labelText)), 'YYYY-MM-DD HH:mm:ss'),this.getBoosterCooldownFromName(labelText)/60} hours`;
useButton.innerText = `cooldown ${hoursUntilMinutesPassed(window.moment(this.gamificationInstance.getSetting(this.getBoosterDateFromName(labelText)), 'YYYY-MM-DD HH:mm:ss'),this.getBoosterCooldownFromName(labelText))} hours`;

useButton.onclick = () => {
new ModalInformationbox(this.app, `${labelText} is for ${window.moment(this.gamificationInstance.getSetting(this.getBoosterDateFromName(labelText)), 'YYYY-MM-DD HH:mm:ss'),this.getBoosterCooldownFromName(labelText)/60} hours in cooldown and can only then be used again.`).open();
new ModalInformationbox(this.app, `${labelText} is for ${hoursUntilMinutesPassed(window.moment(this.gamificationInstance.getSetting(this.getBoosterDateFromName(labelText)), 'YYYY-MM-DD HH:mm:ss'),this.getBoosterCooldownFromName(labelText))} hours in cooldown and can only then be used again.`).open();
};
} else {
label.innerHTML = `${labelText} : (${stock})`;
Expand Down

0 comments on commit 5c5efaf

Please sign in to comment.