/**
* Created by PhpStorm.
* User: Morpheus.Lan
* Date: 2017/12/18
* Time: 11:17
*/
error_reporting(0);
function mod($year,$i){
return $year%$i;
}
function isRunYear($year){
if(mod($year,100)==0){
if(mod($year,400)==0){
return true;
}else{
return false;
}
}else{
if(mod($year,4)==0){
return true;
}else{
return false;
}
}
}
function getNewDate($date,$month_num=0,$year_num=0){
$date_arr = explode("-",$date);
$new_year = (int)$date_arr[0]-$year_num;
$new_month=0;
$new_day=0;
$month_limit = mod($month_num,12);
if($month_num>=12){
$year_add=intval(floor($month_num/12));
if($month_limit>=(int)$date_arr[1]){
$new_year = $new_year-($year_add+1);
$new_month = 12+(int)$date_arr[1]-$month_limit;
}else{
$new_year = $new_year-$year_add;
$new_month = (int)$date_arr[1]-$month_limit;
}
}else{
if($month_limit>=(int)$date_arr[1]){
$new_year = $new_year-1;
$new_month = 12+(int)$date_arr[1]-$month_limit;
}else{
$new_month = (int)$date_arr[1]-$month_limit;
}
}
if((int)$date_arr[1]==2){
if(isRunYear($date_arr[0])){
if((int)$date_arr[2]==29){
if(in_array($new_month,array(1,3,5,7,8,10,12))){
$new_day = 31;
}
if(in_array($new_month,array(4,6,9,11))){
$new_day = 30;
}
if($new_month==2){
if(isRunYear($new_year)){
$new_day = 29;
}else{
$new_day = 28;
}
}
}else{
$new_day = $date_arr[2];
}
}else{
if((int)$date_arr[2]==28){
if(in_array($new_month,array(1,3,5,7,8,10,12))){
$new_day = 31;
}
if(in_array($new_month,array(4,6,9,11))){
$new_day = 30;
}
if($new_month==2){
if(isRunYear($new_year)){
$new_day = 29;
}else{
$new_day = 28;
}
}
}else{
$new_day = $date_arr[2];
}
}
}
if(in_array((int)$date_arr[1],array(1,3,5,7,8,10,12))){
if((int)$date_arr[2]==31){
if(in_array($new_month,array(1,3,5,7,8,10,12))){
$new_day = 31;
}
if(in_array($new_month,array(4,6,9,11))){
$new_day = 30;
}
if($new_month==2){
if(isRunYear($new_year)){
$new_day = 29;
}else{
$new_day = 28;
}
}
}else{
$new_day = $date_arr[2];
if(($new_month==2)&&($new_day>28)){
if(isRunYear($new_year)){
$new_day = 29;
}else{
$new_day = 28;
}
}
}
}
if(in_array((int)$date_arr[1],array(4,6,9,11))){
if((int)$date_arr[2]==30){
if(in_array($new_month,array(1,3,5,7,8,10,12))){
$new_day = 31;
}
if(in_array($new_month,array(4,6,9,11))){
$new_day = 30;
}
if($new_month==2){
if(isRunYear($new_year)){
$new_day = 29;
}else{
$new_day = 28;
}
}
}else{
$new_day = $date_arr[2];
if(($new_month==2)&&($new_day>28)){
if(isRunYear($new_year)){
$new_day = 29;
}else{
$new_day = 28;
}
}
}
}
if($new_month<10){
$new_month="0".$new_month;
}
return $new_year."-".$new_month."-".$new_day;
}
//
$date = $_GET['date'];
$year_num = $_GET['year_num']?$_GET['year_num']:0;
$month_num = $_GET['month_num']?$_GET['month_num']:0;
$return = getNewDate($date,$month_num);
echo $return;