📜  php 代码示例中的 12 个月服务到期

📅  最后修改于: 2022-03-11 14:54:16.001000             🧑  作者: Mango

代码示例1
setDate(2021, 2, 10)->setTime(7, 0);

// First reminder (yellow) sent 3 months before expiration date.
// DateInterval() accepts a formatted string which decodes here to:
// P = Period of
// 3 = 3
// M = Months
// Use sub() to get the period offset from the final payment date ($noticeOfDefault)
$firstReminderAt = (clone $noticeOfDefaultAt)->sub(new DateInterval('P3M'));
// Second reminder (orange) sent 1 month before expiration date.
$secondReminderAt = (clone $noticeOfDefaultAt)->sub(new DateInterval('P1M'));

// Default to transparent if within payment period.
$bgColor = 'transparent';

if ($today >= $firstReminderAt && $today < $secondReminderAt)
    // Today is within grace period of first reminder.
    $bgColor = 'yellow';

if ($today >= $secondReminderAt && $today < $noticeOfDefaultAt)
    // Today is within grace period of second reminder.
    $bgColor = 'orange';
    
if ($today >= $noticeOfDefaultAt)
    // We have a really sh*tty customer. Send legal team.
    $bgColor = 'red';

// Change the color names to any rgb-hex value you want and use them in your "style" attribute.
echo $bgColor;