Skip to content

Commit

Permalink
remove buggy parseStartDate option
Browse files Browse the repository at this point in the history
  • Loading branch information
Ebonsignori committed Dec 24, 2023
1 parent c618ca6 commit 518335f
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 62 deletions.
11 changes: 4 additions & 7 deletions src/codeblock-autofill.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,7 @@ export function codeblockAutofillPlugin(
private processMatchingCodeBlock(match: RegExpMatchArray): void {
const beforeCodeBlockContents = match?.[1] || "";
const innerIndex =
<number>match.index +
4 +
settings.blockVariableName.length +
beforeCodeBlockContents.length;
<number>match.index + 4 + settings.blockVariableName.length + beforeCodeBlockContents.length;
let hasChanges = false;

const innerContents = match?.[3];
Expand Down Expand Up @@ -170,20 +167,20 @@ export function codeblockAutofillPlugin(
}

// Replace all [time] blocks or empty lines with the correct time
const isEarlyFinishBlock =
textBlock === this.endBlockName && i < 2;
const isEarlyFinishBlock = textBlock === this.endBlockName && i < 2;
if (isEarlyFinishBlock) {
textAfterColon = "";
}
if (
!textBlock ||
isEarlyFinishBlock ||
isEarlyFinishBlock ||
textBlock !== this.endBlockName
) {
let nextDate = moment(startTime);
if (elapsedMs) {
nextDate = nextDate.add(elapsedMs, "millisecond");
}
console.log(nextDate.format(settings.eventDateFormat))
const timeBlockString = `[${nextDate.format(
settings.eventDateFormat
)}]:`;
Expand Down
15 changes: 7 additions & 8 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ export default class TimelineSchedule extends Plugin {
}

if (this.settings.enableCodeblockTextAutofill) {
this.activeExtension = [codeblockAutofillPlugin(this.app, this.settings)];
this.activeExtension = [
codeblockAutofillPlugin(this.app, this.settings),
];
this.registerEditorExtension(this.activeExtension);
this.registerEvent(
this.app.workspace.on(
Expand Down Expand Up @@ -69,7 +71,9 @@ export default class TimelineSchedule extends Plugin {
updateEditorProcessors() {
if (this.activeExtension?.length) {
this.activeExtension.length = 0;
this.activeExtension.push(codeblockAutofillPlugin(this.app, this.settings));
this.activeExtension.push(
codeblockAutofillPlugin(this.app, this.settings)
);
this.app.workspace.updateOptions();
}
}
Expand All @@ -89,12 +93,7 @@ export default class TimelineSchedule extends Plugin {
settings[key] === null ||
settings[key] === ""
) {
// Special case, we fallback to startDateFormat if parseStartDateFormat is empty
if (key == "parseStartDateFormat" && !settings[key]) {
(<any>this.settings)[key] = this.settings.startDateFormat;
} else {
(<any>this.settings)[key] = (<any>DEFAULT_SETTINGS)[key];
}
(<any>this.settings)[key] = (<any>DEFAULT_SETTINGS)[key];
}
}
}
Expand Down
39 changes: 0 additions & 39 deletions src/settings/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ export interface TimelineScheduleSettings {
startDateFormat: string;
endDateFormat: string;
eventDateFormat: string;
parseStartDateFormat: string;
}

export const DEFAULT_SETTINGS: TimelineScheduleSettings = {
Expand All @@ -28,7 +27,6 @@ export const DEFAULT_SETTINGS: TimelineScheduleSettings = {
startDateFormat: "MM/DD/YY - hh:mm A",
endDateFormat: "MM/DD/YY - hh:mm A",
eventDateFormat: "h:mm A",
parseStartDateFormat: "hh:mm A",
};

export class SettingsTab extends PluginSettingTab {
Expand Down Expand Up @@ -281,43 +279,6 @@ export class SettingsTab extends PluginSettingTab {
this.display();
});
});

const parseStartDateFormatDesc = document.createDocumentFragment();
parseStartDateFormatDesc.append(
"If you write your start dates in a different format from the display format, you can specify the format here.",
parseStartDateFormatDesc.createEl("br"),
`For instance, Start: ${moment().format(
this.plugin.settings.parseStartDateFormat ||
DEFAULT_SETTINGS.parseStartDateFormat
)}`
);
const parseStartDateFormat = new Setting(this.containerEl)
.setName("Start date format for parsing")
.setDesc(parseStartDateFormatDesc)
.addMomentFormat((format) => {
format
.setDefaultFormat(DEFAULT_SETTINGS.parseStartDateFormat)
.setPlaceholder(DEFAULT_SETTINGS.parseStartDateFormat)
.setValue(this.plugin.settings.parseStartDateFormat)
.onChange(async (value: string) => {
this.plugin.settings.parseStartDateFormat = value;
await this.plugin.saveSettings();
});
format.inputEl.onblur = () => {
this.display();
};
});
parseStartDateFormat.addExtraButton((button) => {
button
.setIcon("reset")
.setTooltip("Reset to default")
.onClick(async () => {
this.plugin.settings.parseStartDateFormat =
DEFAULT_SETTINGS.parseStartDateFormat;
await this.plugin.saveSettings();
this.display();
});
});
}

async validate() {
Expand Down
10 changes: 2 additions & 8 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,9 @@ import { moment } from "obsidian";
// Parse user date string for start date
export function getStartDateFromUserString(
dateString: string,
settings: { startDateFormat: string; parseStartDateFormat: string }
settings: { startDateFormat: string; }
) {
let startDate = moment();
if (dateString) {
startDate = moment(dateString);
}
if (settings.parseStartDateFormat && !startDate?.isValid()) {
startDate = moment(dateString, settings.parseStartDateFormat);
}
let startDate = moment(dateString);
if (!startDate?.isValid()) {
startDate = moment(dateString, settings.startDateFormat);
}
Expand Down

0 comments on commit 518335f

Please sign in to comment.