I need to implement a kind-of advanced time processing feature and I get lost in dozens of PHP's time functions. I've got a TimeUnit class that represents time unit, which is a tuple: from, to and period type, where period_type is month, week or day. Example timeunit is: from: 1st January 2013, to: 28th February 2013, period type: month - which represents two months. 01.01.2013-28.02.2013-month is not the same as 01.01.2013-28.02.2013-day - the latter one is segmented by days and has 59 elements in fact (31 days + 28 days), whereas the former one has 2 elements (just two months).
I need to implement the following: I dump the TimeUnit into the day-scale period type (either from months or from weeks). I need to return sequence of segment sizes, which is a list of sizes. For example I've got 3 weeks TimeUnit and I dump it to days, so I expect to have 7,7,7. If I have 4 months (Jun, Jul, Aug, Sep) I'll get (30,31,31,30).
So far I'm using DateInterval, but it seems there'll be quite a lot of code (different for weeks and different for months) and maybe someone here has a better solution, maybe a built-in PHP function for that?
Yep, this sounds like a job for the DateInterval
class. I'm not fully sure about your exact requirements (you should show some code), but if the DateInterval
class will not do the job completely then you may extend or decorate it.