How to compute the number of occurrences of a cron schedule over a time span?

For example, given a cron schedule such as: 0 * 1 7 6 and a time span, like the next year, can you directly compute the number of times the schedule will fire? It can be brute forced pretty trivially but I’d like to use this to sort a list so I’d rather not just brute force it. It’s pretty easy to compute the trivial cron patterns:

fn('* * * * *', 1 day) -> 60 * 24 fn('0,30 * * * *', 1 day) -> 2 * 24 

It’s easy up until the calendar gets involved with different length months and then you have to worry about days or the week coinciding with days of the month.