Exemplo n.º 1
0
 public static function formatByUnit(Gpf_DateTime $date, $unitType)
 {
     switch ($unitType) {
         case Gpf_Common_DateUtils::DAY:
             return $date->toLocaleDate();
         case Gpf_Common_DateUtils::MONTH:
             return $date->format('M Y');
         case Gpf_Common_DateUtils::YEAR:
             return $date->getYear();
         case Gpf_Common_DateUtils::WEEK:
             return $date->getWeekStart()->toLocaleDate() . " - " . $date->getWeekEnd()->toLocaleDate();
         default:
             return $date->toLocaleDate();
     }
 }
    /**
     * @return boolean
     */
    protected function isWeeklySendDay($dateFrom) {
        $weeklyDay = $this->accountSettings->get(Pap_Settings::NOTIFICATION_WEEKLY_REPORT_SENT_ON);

        if (!$this->wasCronStopped($dateFrom)) {
            return date('w', $this->time) == $weeklyDay;
        }

        $dateFromTimestamp = Gpf_Common_DateUtils::getTimestamp($dateFrom);

        $dateStart = new Gpf_DateTime($dateFromTimestamp);
        $dateStart->addWeek(-1);
        $dateEnd = new Gpf_DateTime($dateFromTimestamp);
        $lastWeek = Gpf_Common_DateUtils::addDateUnitToTimestamp($this->time, -1, Gpf_Common_DateUtils::WEEK);

        if ($lastWeek < $dateStart->getWeekStart()->toDateTime() ||
        $lastWeek > $dateEnd->getWeekEnd()->toDateTime()) {
            return false;
        }

        if ($lastWeek >= $dateStart->getWeekStart()->toDateTime() &&
        $lastWeek <= $dateStart->getWeekEnd()->toDateTime() &&
        date('w', $dateFromTimestamp) >= $weeklyDay) {
            return false;
        }

        if (date('w', $this->time) < $weeklyDay) {
            return false;
        }
        return true;
    }