12

I am looking for a parser that converts a cron expression like 45 17 7 6 * * into Every year, on June 7th at 17:45 The parser should be adjustable to other languages. German for the first step.

Is there a library for a

  • JAVA based Android project
  • Objective-C based Iphone project.

See here for the usecase.

Community
  • 1
  • 1
OneWorld
  • 17,512
  • 21
  • 86
  • 136
  • 2
    sounds a little like a "do my work for me" question... Try removing things like "I need a...", "we need it for...", "it needs to be..." and try replacing them with things like "I am looking for..." – Jasarien Dec 17 '10 at 09:55
  • Thx! Sorry, I'm forgetting my "social" english. I vocation in an english speaking country! ;) But still, I dont want to reinvent the wheel. Therefore I'm looking for already developed and tested existing solutions for my problems on this platform. – OneWorld Dec 17 '10 at 10:52
  • 1
    possible duplicate of [Cron to human readable string](http://stackoverflow.com/questions/1235532/cron-to-human-readable-string) – Mauricio Scheffer Jan 11 '12 at 02:28

3 Answers3

9
cronTrigger.getExpressionSummary()

Example:

    CronTrigger t = new CronTrigger();
    t.setCronExpression("0 30 10-13 ? * WED,FRI");
    System.out.println(""+t.getExpressionSummary());

Output:

seconds: 0
minutes: 30
hours: 10,11,12,13
daysOfMonth: ?
months: *
daysOfWeek: 4,6
lastdayOfWeek: false
nearestWeekday: false
NthDayOfWeek: 0
lastdayOfMonth: false
years: *
jmj
  • 237,923
  • 42
  • 401
  • 438
  • 1
    Ok, that seems to be kind of a dump for the developer. Thx, for showing me the class which is a good way to hold the string as object. I'm investigating there a little more. However, I can't present this dump to an Android user. – OneWorld Dec 17 '10 at 11:20
  • `I can't present this dump to an Android user.` didn't get this point, you want a lib specific to android ? – jmj Dec 17 '10 at 11:22
  • 1
    No. But imagine you see this dump on a small smartphone screen. – OneWorld Dec 17 '10 at 12:37
  • You can accommodate this dump scrollable table view, I don't know much about andriod programming otherwise I would have suggested you the component – jmj Dec 17 '10 at 13:00
  • 1
    My designer is going to kill me if I do that ;) This output is not human readable or at least "customer readable", "designer readable" ;) – OneWorld Dec 17 '10 at 14:32
  • Naah.. you can customize this output so that even an illiterate can understand i guess :) – jmj Dec 17 '10 at 14:33
  • @JigarJoshi How to convert these to timesInMillis?! – Dr.jacky May 11 '15 at 12:44
  • quartz doesn't support millisecond in cron expression – jmj May 11 '15 at 17:14
4

You may find cron-utils useful for this task, since provides human readable descriptions in various languages and does not require a fully fledged scheduler to provide them. Supports multiple cron formats. Below a code snippet from the docs:

//create a descriptor for a specific Locale
CronDescriptor descriptor = CronDescriptor.instance(Locale.UK);

//parse some expression and ask descriptor for description
String description = descriptor.describe(parser.parse("*/45 * * * * *"));
//description will be: "every 45 seconds"
sashimi
  • 1,224
  • 2
  • 15
  • 23
1

In Java, have a look into cron4j http://www.sauronsoftware.it/projects/cron4j/

You will find the parser you need but then you have to write your code to print the string as you need it. Start by creating a SchedulingPattern object:

new SchedulingPattern("0 30 10-13 ? * 1,2,5")
robsf
  • 1,713
  • 3
  • 14
  • 26