Git Product home page Git Product logo

parse-cron's Introduction

Parse-Cron

Parse crontab syntax to determine scheduled run times Build Status

The goal of this gem is to parse a crontab timing specification and determine when the job should be run. It is not a scheduler, it does not run the jobs.

API example

cron_parser = CronParser.new('30 * * * *')

# Next occurrence
next_time = cron_parser.next(Time.now)

# Last occurrence
most_recent_time = cron_parser.last(Time.now)

parse-cron's People

Contributors

bjornblomqvist avatar bramswenson avatar carlosms avatar jney avatar lmc avatar meesterdude avatar mperham avatar npickens avatar pjungwir avatar siebertm avatar zserafinimckesson avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

parse-cron's Issues

License of parse-cron?

I wasn't able to identify the license for parse-cron. :(

Could you let me know which license applies?

Reverse lookup

Hey, guys!

Is it possible to perform reversed lookup? Like, lets find nearest date in the past. Thx!

CronParser#last gives incorrect time

The following produces an incorrect last time:

cron_parser = CronParser.new('* * * * *')
p "Now: #{Time.now}"
p "Last: #{cron_parser.last}"
p "Next: #{cron_parser.next}"

The output is

"Now: 2014-05-12 13:15:42 -0600"
"Last: 2014-05-12 13:14:00 -0600"
"Next: 2014-05-12 13:16:00 -0600"

But would expect the output to be (notice 13:15:00 in the "Last:" line)

"Now: 2014-05-12 13:15:42 -0600"
"Last: 2014-05-12 13:15:00 -0600"
"Next: 2014-05-12 13:16:00 -0600"

Is this still maintained?

I know the last commit is some time ago, but is there a chance this is still maintained?
There are some issues and I am wondering if I should report or fork and fix on my own.

Bad calculation

There is a bad calculation if I set more complex crontab. Here is an example.

2.2.4 :001 > require 'cron_parser'
=> true
2.2.4 :002 > require 'time'
=> true
2.2.4 :003 > cron_parser = CronParser.new('1 2 8-15 * 4')
=> #<CronParser:0x000000009644e8 @source="1 2 8-15 * 4", @time_source=Time>
2.2.4 :004 > cron_parser.next(Time.parse('2016-03-01 00:00'))
=> 2016-03-03 02:01:00 +0100

It should be '2016-03-10 02:01:00' I think.

Version update

Would you be able to push a version update so I can get the new changes with a gem update command?
Thanks!

Please include License file in the gem

I am packaging your gem for Fedora (being used in OpenNebula) and one minor issue is there is no License file in the gem.

Can you please include it this would be very appreciated.

Thanks,
Shawn

Error when expression = "15-59/15 * * * *"

Hi,

CronParser#next is failing with some expressions. One example:

expression = "15-59/15 * * * *"
cron_parser = CronParser.new(expression)
next_execution_time = cron_parser.next(Time.now)

Trace:
ArgumentError: argument out of range
from /usr/lib/ruby/gems/1.9.1/gems/parse-cron-0.1.2/lib/cron_parser.rb:22:in local' from /usr/lib/ruby/gems/1.9.1/gems/parse-cron-0.1.2/lib/cron_parser.rb:22:into_time'
from /usr/lib/ruby/gems/1.9.1/gems/parse-cron-0.1.2/lib/cron_parser.rb:80:in next' from (irb):9 from /usr/lib/ruby/gems/1.9.1/gems/railties-3.0.5/lib/rails/commands/console.rb:44:instart'
from /usr/lib/ruby/gems/1.9.1/gems/railties-3.0.5/lib/rails/commands/console.rb:8:in start' from /usr/lib/ruby/gems/1.9.1/gems/railties-3.0.5/lib/rails/commands.rb:23:in<top (required)>'
from script/rails:6:in require' from script/rails:6:in

Thanks
Deepanshu Dialani

cron string with list like '3-3' is treated like '3-4'

jruby-1.7.19 :001 > p = CronParser.new('0 5 * * 3-3',Time)
 => #<CronParser:0x52b28256 @source="0 5 * * 3-3", @time_source=Time> 
jruby-1.7.19 :002 > t=Time.utc(2016,"feb",21,0,0,0)
 => 2016-02-21 00:00:00 UTC 
jruby-1.7.19 :003 > t2 = p.next(t)
 => 2016-02-24 05:00:00 -0800 
jruby-1.7.19 :004 > p.next(t2)
 => 2016-02-25 05:00:00 -0800 

minor issue since whatever generates 3-3 is doing something weird to begin with but also kind of odd. most cron string parsers seem to collapse this into one entry.

DOM doesn't recognise "?"

I think following is a valid cron expression:
"50 21 ? * 3,6"

But cron-parser throws exception for it.

At the same time
50 21 * * 3,6

is invalid, but goes through without any exception.

require 'set'

need a require "set" somewhere

ruby 1.9.3p327 (2012-11-10 revision 37606) [x86_64-linux]
>> require 'cron_parser'
=> true
>> parser = CronParser.new('')
=> #<CronParser:0x000000021fc1e0 @source="">
>> e =  parser.parse_element('*', (Time.now..(Time.now + 60 * 60)))
NameError: uninitialized constant CronParser::Set
    from /home/jney/.gem/ruby/1.9.1/gems/parse-cron-0.1.1/lib/cron_parser.rb:124:in `parse_element'
    from (irb):4
    from /usr/bin/irb:12:in `<main>'

should submit a patch ?

Error parsing flag L

The gem gives error when parsing 30 7 1-L/2 * *, in this case stands for last day of month.

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.