+ my $mend;
+ my $mstart;
+ # select the first cutoff day that's on or after the current day
+ my $cutoff_day = min( grep { $_ >= $mday } @cutoff_days );
+ # if today is after the last cutoff, choose the first one
+ $cutoff_day ||= $cutoff_days[0];
+
+ # then, if today is on or after the selected day, set period to
+ # (cutoff day this month) - (cutoff day next month)
+ if ( $mday >= $cutoff_day ) {
+ $mend =
+ timelocal_nocheck(0,0,0,$cutoff_day,$mon == 11 ? 0 : $mon + 1,$year+($mon==11));
+ $mstart =
+ timelocal_nocheck(0,0,0,$cutoff_day,$mon,$year);
+ }
+ # otherwise, set period to (cutoff day last month) - (cutoff day this month)
+ else {
+ $mend =
+ timelocal_nocheck(0,0,0,$cutoff_day,$mon,$year);
+ $mstart =
+ timelocal_nocheck(0,0,0,$cutoff_day,$mon == 0 ? 11 : $mon - 1,$year-($mon==0));
+ }
+ return ($mnow, $mend, $mstart);