/**
  * Calculates the first day of the given period depending on the given date.
  *
  * For period Weeks: Last day of a week is always sunday
  *
  * @param class_date_period_enum $objPeriod
  * @param class_date $objDate
  *
  * @return class_date
  */
 public function lastDayOfThis(class_date_period_enum $objPeriod, class_date $objDate)
 {
     $strRelativeString = "";
     if ($objPeriod->equals(class_date_period_enum::YEAR())) {
         $strRelativeString = "last day of december";
     } else {
         if ($objPeriod->equals(class_date_period_enum::HALFYEAR())) {
             $intMonth = $objDate->getIntMonth();
             if ($intMonth < 7) {
                 $strRelativeString = "last day of june";
             } else {
                 $strRelativeString = "last day of december";
             }
         } else {
             if ($objPeriod->equals(class_date_period_enum::QUARTER())) {
                 $intMonth = $objDate->getIntMonth();
                 if ($intMonth < 4) {
                     $strRelativeString = "last day of march";
                 } elseif ($intMonth > 3 && $intMonth < 7) {
                     $strRelativeString = "last day of june";
                 } elseif ($intMonth > 6 && $intMonth < 10) {
                     $strRelativeString = "last day of september";
                 } elseif ($intMonth > 9) {
                     $strRelativeString = "last day of december";
                 }
             } else {
                 if ($objPeriod->equals(class_date_period_enum::MONTH())) {
                     $strRelativeString = "last day of this month";
                 } else {
                     if ($objPeriod->equals(class_date_period_enum::WEEK())) {
                         if ($objDate->getIntDayOfWeek() == 0) {
                             $strRelativeString = "now";
                         } else {
                             //check if correct?
                             $strRelativeString = "sunday this week";
                         }
                     }
                 }
             }
         }
     }
     $objNewDate = self::calcDateRelativeFormatString($objDate, $strRelativeString);
     $objNewDate->setIntHour($objDate->getIntHour());
     $objNewDate->setIntMin($objDate->getIntMin());
     $objNewDate->setIntSec($objDate->getIntSec());
     return $objNewDate;
 }
 public function test_lastDayOfNext()
 {
     $objHelper = new class_date_helper();
     $arrDates = array();
     $arrDates[] = array("period" => class_date_period_enum::YEAR(), "basedate" => 20150101000001, "expecteddate" => 20161231000001);
     $arrDates[] = array("period" => class_date_period_enum::YEAR(), "basedate" => 20151001000001, "expecteddate" => 20161231000001);
     $arrDates[] = array("period" => class_date_period_enum::HALFYEAR(), "basedate" => 20150401000001, "expecteddate" => 20151231000001);
     $arrDates[] = array("period" => class_date_period_enum::HALFYEAR(), "basedate" => 20150601000001, "expecteddate" => 20151231000001);
     $arrDates[] = array("period" => class_date_period_enum::HALFYEAR(), "basedate" => 20150701000001, "expecteddate" => 20160630000001);
     $arrDates[] = array("period" => class_date_period_enum::HALFYEAR(), "basedate" => 20151001000001, "expecteddate" => 20160630000001);
     $arrDates[] = array("period" => class_date_period_enum::QUARTER(), "basedate" => 20150101000001, "expecteddate" => 20150630000001);
     //jan
     $arrDates[] = array("period" => class_date_period_enum::QUARTER(), "basedate" => 20150201000001, "expecteddate" => 20150630000001);
     //feb
     $arrDates[] = array("period" => class_date_period_enum::QUARTER(), "basedate" => 20150301000001, "expecteddate" => 20150630000001);
     //march
     $arrDates[] = array("period" => class_date_period_enum::QUARTER(), "basedate" => 20150401000001, "expecteddate" => 20150930000001);
     //apr
     $arrDates[] = array("period" => class_date_period_enum::QUARTER(), "basedate" => 20150501000001, "expecteddate" => 20150930000001);
     //may
     $arrDates[] = array("period" => class_date_period_enum::QUARTER(), "basedate" => 20150601000001, "expecteddate" => 20150930000001);
     //jun
     $arrDates[] = array("period" => class_date_period_enum::QUARTER(), "basedate" => 20150701000001, "expecteddate" => 20151231000001);
     //jul
     $arrDates[] = array("period" => class_date_period_enum::QUARTER(), "basedate" => 20150801000001, "expecteddate" => 20151231000001);
     //aug
     $arrDates[] = array("period" => class_date_period_enum::QUARTER(), "basedate" => 20150901000001, "expecteddate" => 20151231000001);
     //sep
     $arrDates[] = array("period" => class_date_period_enum::QUARTER(), "basedate" => 20151001000001, "expecteddate" => 20160331000001);
     //oct
     $arrDates[] = array("period" => class_date_period_enum::QUARTER(), "basedate" => 20151101000001, "expecteddate" => 20160331000001);
     //nov
     $arrDates[] = array("period" => class_date_period_enum::QUARTER(), "basedate" => 20151201000001, "expecteddate" => 20160331000001);
     //dec
     $arrDates[] = array("period" => class_date_period_enum::MONTH(), "basedate" => 20150201000001, "expecteddate" => 20150331000001);
     $arrDates[] = array("period" => class_date_period_enum::MONTH(), "basedate" => 20151201000001, "expecteddate" => 20160131000001);
     $arrDates[] = array("period" => class_date_period_enum::MONTH(), "basedate" => 20151223000001, "expecteddate" => 20160131000001);
     $arrDates[] = array("period" => class_date_period_enum::WEEK(), "basedate" => 20150202000001, "expecteddate" => 20150215000001);
     //mon
     $arrDates[] = array("period" => class_date_period_enum::WEEK(), "basedate" => 20150203000001, "expecteddate" => 20150215000001);
     //tue
     $arrDates[] = array("period" => class_date_period_enum::WEEK(), "basedate" => 20150204000001, "expecteddate" => 20150215000001);
     //wed
     $arrDates[] = array("period" => class_date_period_enum::WEEK(), "basedate" => 20150205000001, "expecteddate" => 20150215000001);
     //thu
     $arrDates[] = array("period" => class_date_period_enum::WEEK(), "basedate" => 20150206000001, "expecteddate" => 20150215000001);
     //fri
     $arrDates[] = array("period" => class_date_period_enum::WEEK(), "basedate" => 20150207000001, "expecteddate" => 20150215000001);
     //sat
     $arrDates[] = array("period" => class_date_period_enum::WEEK(), "basedate" => 20150208000001, "expecteddate" => 20150215000001);
     //sun
     foreach ($arrDates as $arrDate) {
         $objDate = new class_date($arrDate["basedate"]);
         $objCalcDate = $objHelper->lastDayOfNext($arrDate["period"], $objDate);
         $this->assertEquals($arrDate["expecteddate"], $objCalcDate->getLongTimestamp(), $arrDate["period"] . " " . $arrDate["basedate"] . " " . $arrDate["expecteddate"]);
     }
 }