Git Product home page Git Product logo

Comments (4)

bretcope avatar bretcope commented on June 22, 2024

I completely agree, and was thinking about that today. Those are definitely the right aliases. Also, implementation should be really simple.

Milliseconds seems like too much and if you actually need a task to run at an exact millisecond, JavaScript may not be the best language to help you out with that anyway.

I was also thinking about adding an interval syntax similar to the cron */2 syntax which would run every two of a time unit (i.e. every two minutes). Or 5-15/2 which runs every two minutes after the fifth minute until the 15th minute.

I already used the / for defining dates, and I don't really want to overload that character, so we need to pick something else. The first idea which comes to mind is % since it's essentially a modulus operation anyway. The syntax would be:

  • minutes(5-15%2) runs at 5,7,9,11,13,15
  • minutes(5%2) runs at 5,7,9, ... 57, 59
  • minutes(%2) runs at 0, 2, 4, 6, ... 56, 58

Thoughts?

from js-schyntax.

rossipedia avatar rossipedia commented on June 22, 2024

👍 on not overloading the / character, keeping the grammar as context free as possible is definitely the right way to go. I'm all for the % op instead.

I really like the syntax, as I think it makes things very terse yet readable. I haven't dug too far into the internals, would the implementation be all that difficult?

from js-schyntax.

bretcope avatar bretcope commented on June 22, 2024

I actually don't think it'll be too difficult to implement. Internally, I turn all arguments into a range. So, minutes(1) actually expands to minutes(1-1) because it simplifies the comparison algorithms. I'll add a modulus property to ranges in the AST, and then the function which does comparison will just have an extra check if the modulus is present. Essentially amounting to: if (current - lowBound % modulusValue === 0)

from js-schyntax.

bretcope avatar bretcope commented on June 22, 2024

Seconds is implemented. That was easy, as expected.

Implementing modulus turned out to be a tremendous pain in the ass, specifically because it has to account for split intervals (such as fri-mon). The way I had originally implemented split intervals (by literally just splitting them into two intervals) wasn't going to work with modulus because it wouldn't have the context of the earlier interval in order to base its count-since-start off of. So I had to refactor the range code and all of the comparison code to handle this situation.

The upside is that once split intervals were generalized (instead of only supported on days of week), it meant that enabling split intervals on everything else was trivial. So stuff like minutes(40-20) is supported now.

Anyway, modulus is now implemented and documented in the readme. It could probably use some more examples, but I don't really feel like adding any right this moment.

Published as 0.3.0.

from js-schyntax.

Related Issues (7)

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.