Code Monkey home page Code Monkey logo

Comments (4)

IchHabRecht avatar IchHabRecht commented on June 20, 2024

Hi @I-Pch, hi @Zachatoo,

Thank you very much for this detailed issue description. I can here for a likely related problem. I want to check if the filename is already in a "YYYY-MM-DD" format. If it is, nothing should be changed but if not I want to trigger a selection promt to choose from a couple of options. I'm now using a try/catch statement together with tp.date.now (which throws an error if parsing with the given format fails). Unfortunately there isn't any error for a filename with a number in it and I need to check the year (I added a check if the year is below 2000 it's an invalid date). I tried to use moment with strict mode but as mentioned in the discord conversation templater checks the date itself and shows an error message (and stops the script processing).

Is there any workaround I could use to check the file title according a given date format? I think I will use a regular expression check by now to handle my use case.

from templater.

Zachatoo avatar Zachatoo commented on June 20, 2024

@IchHabRecht You can use moment directly like this:

<%*
if (!moment(tp.file.title, "YYYY-MM-DD", true).isValid()) {
  // do something if filename isn't in YYYY-MM-DD format
}
-%>

from templater.

IchHabRecht avatar IchHabRecht commented on June 20, 2024

Hi @Zachatoo

Thanks for answering so quickly. Unfortunate it seems I don't get a moment object for invalid titles in strict mode. Templater seems to catch that case internally. An error message is shown and the script seems to be stopped.

from templater.

Zachatoo avatar Zachatoo commented on June 20, 2024

@IchHabRecht What's your full template? Or a minimum reproducible example? The example I provided seems to be working for me.

2024-01-17_18-52-25.mp4

from templater.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.