http://www.perlmonks.org?node_id=536698

merzy has asked for the wisdom of the Perl Monks concerning the following question:

I love Time::Period and use it all over the place in various perverted ways. One thing has always bugged me about it, though:

I can't find an efficient way to calculate overlaps of a period and a time range.

For example, if I have a period "wd {mo-fr} hr {09-05}" that could be named the SLA and a time range (1124424000 to 1140807162) we'll, hypothetically, call the Outage.

How do I determine how many seconds of the Outage fall during the SLA period? I've come up with some hackish ways over the years, but they all come down to stepping through the entire time range with various step sizes and doing an inPeriod. Really slow. Is there a better way?