tags:

views:

66

answers:

2

I started to write a module for scheduling perl jobs with more readable syntax than a cron job, but wondered if there was already one available.

I'm after something that can be run from a perl script, not a crontab file. This syntax has got to be easily readable. For example :-

every Monday morning
every other Tuesday at 3:30pm
every night
once only on 14th August 2010 at 2pm

..if there was something even remotely similar to that it would be great. I had a quick look on CPAN but couldn't find what I was after.

+3  A: 

It looks like DateTime::Format::Natural at CPAN does this. Unfortunately the documentation barely exists. Culling from the module self-test files I find:

{ '9 in the evening'                => '24.11.2006 21:00:00' },
{ 'monday 6 in the morning'         => '20.11.2006 06:00:00' },
{ 'monday 4 in the afternoon'       => '20.11.2006 16:00:00' },
{ 'monday 9 in the evening'         => '20.11.2006 21:00:00' },
{ 'last sunday at 21:45'            => '19.11.2006 21:45:00' },
{ 'monday last week'                => '13.11.2006 00:00:00' },
{ '6th day last week'               => '18.11.2006 00:00:00' },
{ '6th day this week'               => '25.11.2006 00:00:00' },
{ '6th day next week'               => '02.12.2006 00:00:00' },
{ '12th day last month'             => '12.10.2006 00:00:00' },
{ '12th day this month'             => '12.11.2006 00:00:00' },
{ '12th day next month'             => '12.12.2006 00:00:00' },
{ '1st day last year'               => '01.01.2005 00:00:00' },
{ '1st day this year'               => '01.01.2006 00:00:00' },
{ '1st day next year'               => '01.01.2007 00:00:00' },

which looks promising.

msw
Thanks, although this looks like it's only the date formatting side of things. Not the scheduler that looks at this format.
dalton
The documentation looks good to me: http://search.cpan.org/~schubiger/DateTime-Format-Natural/lib/DateTime/Format/Natural/Lang/EN.pm
Kinopiko
@Kinopiko: agreed, that was not the page I saw as I am no longer JAPH. :/ Thanks for the proper link.
msw
A: 

Schedule::Cron does what you're looking for.

Ether
it doesn't have the natural date formatting, just the normal crontab dates.
dalton
@dalton: yes, you'd have to use some other module (like something in the DateTime::Format family, as msw showed).
Ether