Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
export const SCHEDULING_INFO_REGEX =
/^---\n((?:.*\n)*)sr-due: (.+)\nsr-interval: (\d+)\nsr-ease: (\d+)\n((?:.*\n)?)---/;
/^---\n((?:.*\n)*)sr-due: (.+)\nsr-interval: ([\d\.]+)\nsr-ease: ([\d\.]+)\n((?:.*\n)?)---/;
export const YAML_FRONT_MATTER_REGEX = /^---\n((?:.*\n)*?)---/;

export const MULTI_SCHEDULING_EXTRACTOR = /!([\d-]+),(\d+),(\d+)/gm;
export const LEGACY_SCHEDULING_EXTRACTOR = /<!--SR:([\d-]+),(\d+),(\d+)-->/gm;
export const MULTI_SCHEDULING_EXTRACTOR = /!([\d-]+),([\d\.]+),([\d\.]+)/gm;
export const LEGACY_SCHEDULING_EXTRACTOR = /<!--SR:([\d-]+),([\d\.]+),([\d\.]+)-->/gm;

export const IMAGE_FORMATS = [
"jpg",
Expand Down
4 changes: 3 additions & 1 deletion src/flashcard-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,9 @@ export class FlashcardModal extends Modal {
return;
}

const dueString: string = due.format("YYYY-MM-DD");
const dueString: string = due.format("YYYY-MM-DD-HH-mm");
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't the YYYY-MM-DD HH:mm format better and more readable?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would probably suggest using one of the ISO 8601 formats, e.g. YYYY-MM-DDTHH:mm (i.e. the literal T between the date and time)


// const dueString: string = due.format("YYYY-MM-DD");

let fileText: string = await this.app.vault.read(this.currentCard.note);
const replacementRegex = new RegExp(escapeRegexString(this.currentCard.cardText), "gm");
Expand Down
4 changes: 4 additions & 0 deletions src/lang/locale/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@ export default {
EASY_BONUS_DESC:
"The easy bonus allows you to set the difference in intervals between answering Good and Easy on a flashcard/note (minimum = 100%).",
EASY_BONUS_MIN_WARNING: "The easy bonus must be at least 100.",
REVIEW_BEFORE_DUE: "Review Flashnotes Before Due",
REVIEW_BEFORE_DUE_DESC:
"The review before due allows you to review flashnote before due.",
REVIEW_BEFORE_DUE_MIN_WARNING: "The review before due must be at least 0.",
MAX_INTERVAL: "Maximum Interval",
MAX_INTERVAL_DESC: "Allows you to place an upper limit on the interval (default = 100 years).",
MAX_INTERVAL_MIN_WARNING: "The maximum interval must be at least 1 day.",
Expand Down
12 changes: 6 additions & 6 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ export default class SRPlugin extends Plugin {
};

const now = window.moment(Date.now());
const todayDate: string = now.format("YYYY-MM-DD");
const todayDate: string = now.format("YYYY-MM-DD-HH-mm");
// clear bury list if we've changed dates
if (todayDate !== this.data.buryDate) {
this.data.buryDate = todayDate;
Expand Down Expand Up @@ -364,7 +364,7 @@ export default class SRPlugin extends Plugin {
}

const dueUnix: number = window
.moment(frontmatter["sr-due"], ["YYYY-MM-DD", "DD-MM-YYYY", "ddd MMM DD YYYY"])
.moment(frontmatter["sr-due"], ["YYYY-MM-DD-HH-mm", "YYYY-MM-DD", "DD-MM-YYYY", "ddd MMM DD YYYY"])
.valueOf();

for (const matchedNoteTag of matchedNoteTags) {
Expand Down Expand Up @@ -511,7 +511,7 @@ export default class SRPlugin extends Plugin {
delayBeforeReview =
now -
window
.moment(frontmatter["sr-due"], ["YYYY-MM-DD", "DD-MM-YYYY", "ddd MMM DD YYYY"])
.moment(frontmatter["sr-due"], ["YYYY-MM-DD-HH-mm", "YYYY-MM-DD", "DD-MM-YYYY", "ddd MMM DD YYYY"])
.valueOf();
}

Expand All @@ -527,7 +527,7 @@ export default class SRPlugin extends Plugin {
ease = schedObj.ease;

const due = window.moment(now + interval * 24 * 3600 * 1000);
const dueString: string = due.format("YYYY-MM-DD");
const dueString: string = due.format("YYYY-MM-DD-HH-mm");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest that the time component is only included if necessary. This would keep the HTML commands in the current format, and only the longer format when needed.


// check if scheduling info exists
if (SCHEDULING_INFO_REGEX.test(fileText)) {
Expand Down Expand Up @@ -815,7 +815,7 @@ export default class SRPlugin extends Plugin {
this.deckTree.insertFlashcard([...deckPath], cardObj);
} else if (i < scheduling.length) {
const dueUnix: number = window
.moment(scheduling[i][1], ["YYYY-MM-DD", "DD-MM-YYYY"])
.moment(scheduling[i][1], ["YYYY-MM-DD-HH-mm", "YYYY-MM-DD", "DD-MM-YYYY"])
.valueOf();
const nDays: number = Math.ceil((dueUnix - now) / (24 * 3600 * 1000));
if (!Object.prototype.hasOwnProperty.call(this.dueDatesFlashcards, nDays)) {
Expand Down Expand Up @@ -847,7 +847,7 @@ export default class SRPlugin extends Plugin {
continue;
}

if (dueUnix <= now) {
if (dueUnix <= now + this.data.settings.reviewBeforeDue * 24 * 3600 * 1000) {
cardObj.interval = interval;
cardObj.ease = ease;
cardObj.delayBeforeReview = now - dueUnix;
Expand Down
8 changes: 7 additions & 1 deletion src/scheduling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ export function schedule(

// replaces random fuzz with load balancing over the fuzz interval
if (dueDates !== undefined) {
// conserve the decimal part
const interval_decimal = interval - Math.round(interval);

interval = Math.round(interval);
if (!Object.prototype.hasOwnProperty.call(dueDates, interval)) {
dueDates[interval] = 0;
Expand All @@ -94,8 +97,11 @@ export function schedule(
}

dueDates[interval]++;
}

// add the decimal part
interval = interval + interval_decimal;
}

interval = Math.min(interval, settingsObj.maximumInterval);

return { interval: Math.round(interval * 10) / 10, ease };
Expand Down
40 changes: 40 additions & 0 deletions src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export interface SRSettings {
easyBonus: number;
maximumInterval: number;
maxLinkFactor: number;
reviewBeforeDue: number;
// logging
showDebugMessages: boolean;
}
Expand Down Expand Up @@ -80,6 +81,7 @@ export const DEFAULT_SETTINGS: SRSettings = {
easyBonus: 1.3,
maximumInterval: 36525,
maxLinkFactor: 1.0,
reviewBeforeDue: 0.0,
// logging
showDebugMessages: false,
};
Expand Down Expand Up @@ -656,6 +658,44 @@ export class SRSettingTab extends PluginSettingTab {
});
});


new Setting(containerEl)
.setName(t("REVIEW_BEFORE_DUE"))
.setDesc(t("REVIEW_BEFORE_DUE_DESC"))
.addText((text) =>
text
.setValue((this.plugin.data.settings.reviewBeforeDue).toString())
.onChange((value) => {
applySettingsUpdate(async () => {
const numValue: number = Number.parseFloat(value);
if (!isNaN(numValue)) {
if (numValue < 0.0) {
new Notice(t("REVIEW_BEFORE_DUE_MIN_WARNING"));
text.setValue(
(this.plugin.data.settings.reviewBeforeDue * 100).toString()
);
return;
}

this.plugin.data.settings.reviewBeforeDue = Math.floor(numValue * 100) / 100;
await this.plugin.savePluginData();
} else {
new Notice(t("VALID_NUMBER_WARNING"));
}
});
})
)
.addExtraButton((button) => {
button
.setIcon("reset")
.setTooltip(t("RESET_DEFAULT"))
.onClick(async () => {
this.plugin.data.settings.reviewBeforeDue = DEFAULT_SETTINGS.reviewBeforeDue;
await this.plugin.savePluginData();
this.display();
});
});

new Setting(containerEl)
.setName(t("MAX_INTERVAL"))
.setDesc(t("MAX_INTERVAL_DESC"))
Expand Down