Cronos
Cronos copied to clipboard
CronExpression.ToString is not parseable anymore
It looks like a ToString method is not symetric - what I mean by that is that one would expect from CronExpression to pass through Parse→ToString→Parse cycle to produce an equivalent expression as in the first parse.
The motivation for that is that stringified cron expression may be i.e. serialized and restored later.
Simple example to reproduce an issue:
var expr = CronExpression.Parse("*/5 * * * *");
var serialized = expr.ToString(); // 0 0,5,10,15,20,25,30,35,40,45,50,55 * * * *
var expr2 = CronExpression.Parse(serialized);
/*
Cronos.CronFormatException
Days of month: Value must be a number between 1 and 31 (all inclusive).
at Cronos.CronExpression.ThrowFormatException(CronField field, String format, Object[] args)
at Cronos.CronExpression.ParseDayOfMonth(Char*& pointer, CronExpressionFlag& flags, Byte& lastDayOffset)
at Cronos.CronExpression.Parse(String expression, CronFormat format)
*/
I think, the easiest way to solve this, would be to attach original cron expression string as an extra field of the CronExpression class:
- Expression strings are small and usually written by humans, so keeping them arround won't occupy much memory.
- This would make ToString method much faster (useful i.e. for logging).
- The whole class would still be under 64 bytes, therefore fit into CPU cache line.