98 lines
2.3 KiB
C
98 lines
2.3 KiB
C
#define _XOPEN_SOURCE
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <time.h>
|
|
|
|
int ValidateTime(int dd , int mm , int yy)
|
|
{
|
|
|
|
//check month
|
|
if(mm>=1 && mm<=12)
|
|
{
|
|
//check days
|
|
if((dd>=1 && dd<=31) && (mm==1 || mm==3 || mm==5 || mm==7 || mm==8 || mm==10 || mm==12))
|
|
return 1;
|
|
else if((dd>=1 && dd<=30) && (mm==4 || mm==6 || mm==9 || mm==11))
|
|
return 1;
|
|
else if((dd>=1 && dd<=28) && (mm==2))
|
|
return 1;
|
|
else if(dd==29 && mm==2 && (yy%400==0 ||(yy%4==0 && yy%100!=0)))
|
|
return 1;
|
|
else
|
|
return 0;
|
|
}
|
|
else
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
|
|
}
|
|
|
|
int main()
|
|
{
|
|
|
|
char dateStr[11];
|
|
struct tm t;
|
|
int dd = 0, mm = 0, yy = 0;
|
|
|
|
fgets(dateStr, 11, stdin);
|
|
sscanf(dateStr , "%d.%d.%d" , &dd,&mm,&yy);
|
|
if(!ValidateTime(dd,mm,yy)){
|
|
printf("Nespravny datum\n");
|
|
return 0;
|
|
}
|
|
char* res = strptime(dateStr, "%d.%m.%Y", &t);
|
|
if (res == NULL) {
|
|
printf("Nespravny datum\n");
|
|
return 0;
|
|
}
|
|
|
|
t.tm_mday += 7;
|
|
t.tm_sec = 0;
|
|
t.tm_min = 0;
|
|
t.tm_hour = 0;
|
|
|
|
time_t mid = mktime(&t);
|
|
struct tm* t2 = localtime(&mid);
|
|
|
|
|
|
if(t2->tm_mday < 10){
|
|
if(t2->tm_mon + 1 < 10){
|
|
printf(" %d.0%d.%d\n\n", t2->tm_mday, t2->tm_mon + 1, t2->tm_year + 1900);
|
|
} else{
|
|
printf(" %d.%d.%d\n\n", t2->tm_mday, t2->tm_mon + 1, t2->tm_year + 1900);
|
|
}
|
|
} else{
|
|
if(t2->tm_mon + 1 < 10){
|
|
printf("%d.0%d.%d\n\n", t2->tm_mday, t2->tm_mon + 1, t2->tm_year + 1900);
|
|
} else{
|
|
printf("%d.%d.%d\n\n", t2->tm_mday, t2->tm_mon + 1, t2->tm_year + 1900);
|
|
}
|
|
}
|
|
|
|
return 0;
|
|
/*if (time == (time_t)-1) {
|
|
printf("fails with error: can't convert date to time!\n");
|
|
return 1;
|
|
}*/
|
|
|
|
//t2 = localtime(&sec);
|
|
|
|
/*time(&timer);
|
|
double seconds = difftime(timer,mktime(&t));
|
|
printf("%.f", seconds);
|
|
return 0;
|
|
if(t.tm_mon + 1 < 10){
|
|
printf(" %d.0%d.%d\n\n", t.tm_mday, t.tm_mon + 1, t.tm_year + 1900);
|
|
} else{
|
|
printf(" %d.%d.%d\n\n", t.tm_mday, t.tm_mon + 1, t.tm_year + 1900);
|
|
}
|
|
|
|
|
|
exit(EXIT_SUCCESS);
|
|
|
|
return 0;*/
|
|
}
|