public function dateTo(string $date): Date
    {
        $dates = explode('-', $date);
        if (count($dates) != 3) {
            throw new \InvalidArgumentException(
                    'Given date "' . $date . '" does not follow required format YYYY-MM-DD'
            );
        }

        list($year, $month, $day) = $dates;
        if (!ctype_digit($year)) {
            throw new \InvalidArgumentException(
                    'Given value ' . $year . ' for year not suitable for changing the date.'
            );
        }

        if (!ctype_digit($month) || 1 > $month || 12 < $month) {
            throw new \InvalidArgumentException(
                    'Given value ' . $month . ' for month not suitable for changing the date.'
            );
        }

        if (!ctype_digit($day) || 1 > $day || 31 < $day) {
            throw new \InvalidArgumentException(
                    'Given value ' . $day . ' for day not suitable for changing the date.'
            );
        }

        return $this->createNewDateWithExistingTime((int) $year, (int) $month, (int) $day);
    }
public function dateTo(string $date): Date
    {
        $dates = explode('-', $date);
        if (count($dates) != 3) {
            throw new \InvalidArgumentException(
                    'Given date "' . $date . '" does not follow required format YYYY-MM-DD'
            );
        }

        list($year, $month, $day) = $dates;
        if (!ctype_digit($year)) {
            throw new \InvalidArgumentException(
                    'Given value ' . $year . ' for year not suitable for changing the date.'
            );
        }

        if (!ctype_digit($month) || 1 > $month || 12 < $month) {
            throw new \InvalidArgumentException(
                    'Given value ' . $month . ' for month not suitable for changing the date.'
            );
        }

        if (!ctype_digit($day) || 1 > $day || 31 < $day) {
            throw new \InvalidArgumentException(
                    'Given value ' . $day . ' for day not suitable for changing the date.'
            );
        }

        return $this->createNewDateWithExistingTime((int) $year, (int) $month, (int) $day);
    }
public function dateTo ( string $ date ) : Date { $ dates = explode ( '-' , $ date ) ; if ( count ( $ dates ) != 3 ) { throw new \ InvalidArgumentException ( 'Given date "' . $ date . '" does not follow required format YYYY-MM-DD' ) ; } list ( $ year , $ month , $ day ) = $ dates ; if ( ! ctype_digit ( $ year ) ) { throw new \ InvalidArgumentException ( 'Given value ' . $ year . ' for year not suitable for changing the date.' ) ; } if ( ! ctype_digit ( $ month ) || 1 > $ month || 12 < $ month ) { throw new \ InvalidArgumentException ( 'Given value ' . $ month . ' for month not suitable for changing the date.' ) ; } if ( ! ctype_digit ( $ day ) || 1 > $ day || 31 < $ day ) { throw new \ InvalidArgumentException ( 'Given value ' . $ day . ' for day not suitable for changing the date.' ) ; } return $ this -> createNewDateWithExistingTime ( ( int ) $ year , ( int ) $ month , ( int ) $ day ) ; }
returns a new date instance with changed date but same time

@api
@param   string  $date  date representation in format YYYY-MM-DD
@return  \stubbles\date\Date
@throws  \InvalidArgumentException
returns a new date instance with changed date but same time