generated from obsidianmd/obsidian-sample-plugin
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from oeN/fix/use-new-suggest-api
Support the Live Preview editor
- Loading branch information
Showing
7 changed files
with
488 additions
and
437 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,41 +1,41 @@ | ||
import { addDays, format, subDays } from 'date-fns'; | ||
|
||
import { BaseFilter, BaseFilterProps } from './base_filter'; | ||
|
||
export default class DateFiler extends BaseFilter { | ||
originalFilter: Function; | ||
|
||
constructor(props: BaseFilterProps) { | ||
super({ ...props, filterName: 'date' }); | ||
this.originalFilter = this.engine.filters.get('date'); | ||
} | ||
|
||
handler = (givenValue: number | string, dateFormat?: string): string | number => { | ||
const dateToFormat = (typeof givenValue === 'number') | ||
? givenValue | ||
: this.parseDate(givenValue) | ||
const formatToUse = dateFormat || this.plugin.settings.dateFormat; | ||
|
||
// TODO: improve or remove me: keep backwards compatibility with the current 0.1.5 version | ||
if (formatToUse.includes('%')) { | ||
// TODO: send a notification when using this function | ||
return this.originalFilter(givenValue, dateFormat); | ||
} | ||
|
||
try { | ||
return format(dateToFormat, formatToUse) | ||
} catch (e) { | ||
if (!(e instanceof RangeError)) throw e; | ||
} | ||
|
||
return givenValue; | ||
} | ||
|
||
parseDate = (stringToParse: string): Date => { | ||
if(['now', 'today'].includes(stringToParse)) return new Date; | ||
if(stringToParse === 'yesterday') return subDays(Date.now(), 1); | ||
if(stringToParse === 'tomorrow') return addDays(Date.now(), 1); | ||
// try to parse the given string | ||
return new Date(Date.parse(stringToParse)); | ||
} | ||
} | ||
import { addDays, format, subDays } from 'date-fns'; | ||
|
||
import { BaseFilter, BaseFilterProps } from './base_filter'; | ||
|
||
export default class DateFiler extends BaseFilter { | ||
originalFilter: Function; | ||
|
||
constructor(props: BaseFilterProps) { | ||
super({ ...props, filterName: 'date' }); | ||
this.originalFilter = this.engine.filters.get('date'); | ||
} | ||
|
||
handler = (givenValue: number | string, dateFormat?: string): string | number => { | ||
const dateToFormat = (typeof givenValue === 'number') | ||
? givenValue | ||
: this.parseDate(givenValue) | ||
const formatToUse = dateFormat || this.plugin.settings.dateFormat; | ||
|
||
// TODO: improve or remove me: keep backwards compatibility with the current 0.1.5 version | ||
if (formatToUse.includes('%')) { | ||
// TODO: send a notification when using this function | ||
return this.originalFilter(givenValue, dateFormat); | ||
} | ||
|
||
try { | ||
return format(dateToFormat, formatToUse) | ||
} catch (e) { | ||
if (!(e instanceof RangeError)) throw e; | ||
} | ||
|
||
return givenValue; | ||
} | ||
|
||
parseDate = (stringToParse: string): Date => { | ||
if(['now', 'today'].includes(stringToParse)) return new Date; | ||
if(stringToParse === 'yesterday') return subDays(Date.now(), 1); | ||
if(stringToParse === 'tomorrow') return addDays(Date.now(), 1); | ||
// try to parse the given string | ||
return new Date(Date.parse(stringToParse)); | ||
} | ||
} |
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,11 +1,11 @@ | ||
import { addDays } from 'date-fns'; | ||
|
||
import { BaseFilter, BaseFilterProps } from './base_filter'; | ||
|
||
export default class DaysAfter extends BaseFilter { | ||
constructor(props: BaseFilterProps) { | ||
super({ ...props, filterName: 'days_after' }); | ||
} | ||
|
||
handler = (daysToSub: number): Date => addDays(Date.now(), daysToSub); | ||
} | ||
import { addDays } from 'date-fns'; | ||
|
||
import { BaseFilter, BaseFilterProps } from './base_filter'; | ||
|
||
export default class DaysAfter extends BaseFilter { | ||
constructor(props: BaseFilterProps) { | ||
super({ ...props, filterName: 'days_after' }); | ||
} | ||
|
||
handler = (daysToAdd: number): Date => addDays(Date.now(), daysToAdd); | ||
} |
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
Oops, something went wrong.