BusinessDays icon indicating copy to clipboard operation
BusinessDays copied to clipboard

Add lastDayOfWeekOfMonth FilterFactory method

Open iansltx opened this issue 10 years ago • 2 comments

Applicable for days like Memorial Day (last Monday in May).

Roughing things out...

function lastDayOfWeekOfMonth($month, $day_of_week) {
    // input checks go here

    // TODO use correct length for all months
    // check on day-of-month validation may be useful
    $monthLength = 31;

    // first day of the last week of the month
    $lowerBound = $monthLength - 6;

    return function(\DateTimeInterface $dt) use ($month, $lowerBoynd, $day_of_week) {
        $dt->format('m') == $month && $dt->format('d') >= $lowerBound && $dt->format('w') == $day_of_week;
    }
}

Just needs a fix on $monthLength, argument validity checks, and tests.

iansltx avatar Feb 18 '15 17:02 iansltx

I don't understand the question :( . By the way, we don't have memorial day.

harikt avatar Feb 19 '15 01:02 harikt

@harikt The holidays I'm likely to mention in my own feature requests will be US-centric. The nice thing about the library is that you start with no filters, so in areas where the US set of holidays doesn't apply (everywhere other than the US), you can substitute in calculations for what aren't business days in your locale.

My guess is that there are other days than US Memorial Day that follow a similar (last Monday/Saturday/etc. of May/September/etc.) pattern, hence the feature request for a FilterFactory method, vs. the simpler callback that I'm using for this at the moment in my own client code.

iansltx avatar Feb 19 '15 02:02 iansltx