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

Adding default wildcards for Date (ISO 8601), month and day #644

Open
mikkovedru opened this issue Jan 23, 2023 · 1 comment
Open

Adding default wildcards for Date (ISO 8601), month and day #644

mikkovedru opened this issue Jan 23, 2023 · 1 comment

Comments

@mikkovedru
Copy link
Contributor

Currently, Zotfile has different wildcards including the wildcard for a year (%y). It's natural and expected that such a field would exist.

But sadly many other natural and expected wildcards don't exist:

  • Date in ISO 8601 format: YYYY-MM-DD like 2023-01-23.
  • Month (at least the double digits, even though other formats are also welcomed)
  • Day (at least the double digits, even though other formats are also welcomed)

To get those one has to work with the unsupported user-defined wildcards using replace functions, regex, etc. This is a very hard and tedious thing to do for those who know how to do it and it's basically impossible for those who don't.

Could you please add those fields? Are patches welcome or going to be ignored?

@joshleitzel
Copy link

joshleitzel commented Sep 24, 2023

In case this is helpful for anyone in the future, I needed this functionality as well so I designed a custom wildcard to output the ISO format. Here it is:

{
    "z": {
        "field": "date",
        "operations": [
            {
                "function": "replace",
                "regex": "([^\\d]*)(\\d{1,2})([^\\d]*)(\\d{1,2})([^\\d]*)(\\d{4})",
                "replacement": "$6-0$2-0$4",
                "flags": "g"
            },
            {
                "function": "replace",
                "regex": "(\\d{4})-\\d?(\\d{2})-\\d?(\\d{2})",
                "replacement": "$1-$2-$3",
                "flags": "g"
            }
        ]
    }
}

You can set this up by following the instructions in the docs:

  1. Open your Zotero settings
  2. Go to Advanced > Config Editor
  3. Search for "wildcard" and double-click the extensions.zotfile.wildcards.user item
  4. In the popup-box that appears, paste the code snippet I posted above

Now you can use the wildcard %z anywhere you want the date to appear.

For the programming-minded who may be curious about the strange regexes, I discovered that Zotero seems to use some invisible characters in between the digits in the dates. So it's necessary to isolate them using the ^\\d sequences. The second replace operation removes the leading 0 from the month and day that was added in the first operation, in case it doesn't need one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants