Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FR]: Date Range Filters #604

Closed
Stilts15ak opened this issue Nov 17, 2022 · 17 comments
Closed

[FR]: Date Range Filters #604

Stilts15ak opened this issue Nov 17, 2022 · 17 comments
Assignees
Labels
documentation Improvements or additions to documentation enhancement New feature or request

Comments

@Stilts15ak
Copy link

Contact Details

Stilts15ak@gmail.com

Present your request

It would be nice when filtering for dates if hard coded ranges could be implemented. (i.e. "Yesterday", "Today", "Tomorrow", "(#) Days", "This Week", "Next Week", "This Month", "Next Month", "This Year", "Future")

For which platform do you request this request??

Cross

@Stilts15ak Stilts15ak added enhancement New feature or request triage Issue not tagged yet. talking to the user labels Nov 17, 2022
@RafaelGB
Copy link
Owner

Hello @Stilts15ak,
Generate custom filters in function of the tupe could be interesting.

There are two ways.

  • A search per column (just like the global search with custom inputs)
  • Inside the filters

I think the first one is more interesting and easier to maintain.

@Stilts15ak
Copy link
Author

Could this also be achievable (in the short term) with using a formula and using relative dates (i.e. "Today", "This Week", etc.)?

@RafaelGB
Copy link
Owner

You can already use Luxon formulas

https://rafaelgb.github.io/obsidian-db-folder/features/Formulas/

Screenshot 2022-11-17 at 15 46 16

https://moment.github.io/luxon/api-docs/index.html#datetimetorelative

${row.column1. toRelativeCalendar()}

@Stilts15ak
Copy link
Author

Thanks! I'll play around with it.

@RafaelGB
Copy link
Owner

Also I saw a problem with the formula. It should be refreshed after any change of the row.

Will be fixed with the next version =) Commit b331dbd

@Stilts15ak
Copy link
Author

Yup! That's what I'm getting.

I think this is a nice solution. Whether it's short or long term.

However, it looks like DB will not filter a formula column.

@RafaelGB
Copy link
Owner

to allow the filters you need to persist the value (a toggle inside the column config)

@Stilts15ak
Copy link
Author

Not sure I understand. Can you elaborate further?

@RafaelGB
Copy link
Owner

Screen.Recording.2022-11-17.at.16.35.40.mov

@Stilts15ak
Copy link
Author

Thank you! Works like a charm now.

Can I make a suggestion to where it says "Only persisted formulas could be searchable and sortable" to add "and filtered" as well? And perhaps include this in the documentation too?

@RafaelGB
Copy link
Owner

We can improve the documentation, of course.

It's a young plugin and the changes are constant. So the documentation is hardly to maintain

@RafaelGB RafaelGB added documentation Improvements or additions to documentation and removed triage Issue not tagged yet. talking to the user labels Nov 17, 2022
@javiavid
Copy link

In the video example, Is it possible to use with the Created column (date from file created)?

@RafaelGB
Copy link
Owner

Yeah, it is possible

@javiavid
Copy link

It appears empty

image

image

@RafaelGB
Copy link
Owner

RafaelGB commented Dec 13, 2022

All metadata fields need __<id>__ wrapping

Try with ${row.__created__.toRelativeCalendar()}

@javiavid
Copy link

Now it works, thanks Rafa!

@RafaelGB RafaelGB self-assigned this Mar 1, 2023
@RafaelGB
Copy link
Owner

RafaelGB commented Apr 9, 2023

a new feature for calendar/calendar time will be added for the next version

If you add an @ to some words like today or next weekwill be applied to your filter in function of the actual date

import { DateTime } from "luxon";
const valueToCalendarConverter = new Map<string, DateTime>([
    ["today", DateTime.local().startOf("day")],
    ["yesterday", DateTime.local().minus({ days: 1 }).startOf("day")],
    ["tomorrow", DateTime.local().plus({ days: 1 }).startOf("day")],
    ["thisweek", DateTime.local().startOf("week")],
    ["lastweek", DateTime.local().minus({ weeks: 1 }).startOf("week")],
    ["nextweek", DateTime.local().plus({ weeks: 1 }).startOf("week")],
    ["thismonth", DateTime.local().startOf("month")],
    ["lastmonth", DateTime.local().minus({ months: 1 }).startOf("month")],
    ["nextmonth", DateTime.local().plus({ months: 1 }).startOf("month")],
    ["thisyear", DateTime.local().startOf("year")],
    ["lastyear", DateTime.local().minus({ years: 1 }).startOf("year")],
    ["nextyear", DateTime.local().plus({ years: 1 }).startOf("year")],
    ["thisquarter", DateTime.local().startOf("quarter")],
    ["lastquarter", DateTime.local().minus({ quarters: 1 }).startOf("quarter")],
    ["nextquarter", DateTime.local().plus({ quarters: 1 }).startOf("quarter")],
]);

export default class FilterValuesMapper {
    public static toCalendarValue(filterValue: string): DateTime {
        if (filterValue.startsWith("@")) {
            const potentialDate = valueToCalendarConverter.get(filterValue.slice(1).toLowerCase());
            return potentialDate ? potentialDate : DateTime.local();
        }

        const potentialDate = DateTime.fromISO(filterValue);
        return potentialDate.isValid ? potentialDate : DateTime.local();
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation enhancement New feature or request
Projects
Status: Done
Development

No branches or pull requests

3 participants