This commit is contained in:
Igor Dzuro 2020-03-27 04:54:58 +01:00
parent 708fc9ab3c
commit 3f743a0312
2 changed files with 74 additions and 22 deletions

Binary file not shown.

View File

@ -5,32 +5,84 @@
#include<time.h> #include<time.h>
#include<stdlib.h> #include<stdlib.h>
int main() { #define max_yr 9999
char buffer[20]; #define min_yr 1900
struct tm tm = {0};
char *retval = fgets(buffer, sizeof(buffer), stdin); int isleap(int y) {
if (y % 4 != 0) {
return 0;
} else if (y % 100 != 0) {
return 1;
} else if (y % 400 != 0) {
return 0;
}
if (retval == 0) { return 1;
puts("Neplatny datum"); }
return 0;
} int datevalid(int d, int m, int y) {
if(y < min_yr || y > max_yr) {
retval = strptime(buffer, "%e.%m.%-Y", &tm); return 0;
}
if (retval == 0) {
puts("Neplatny datum"); if(m < 1 || m > 12) {
return 0; return 0;
} }
tm.tm_isdst = -1; if(d < 1 || d > 31) {
tm.tm_mday += 7; return 0;
}
mktime(&tm);
if(m == 2) {
strftime(buffer, sizeof(buffer), "%e.%m.%-Y", &tm); if(isleap(y)) {
puts(buffer); if(d <= 29) {
putc('\n', stdout); return 1;
}
return 0; } else {
return 0;
}
}
if ( m == 4 || m == 6 || m == 9 || m == 11 ) {
if(d <= 30) {
return 1;
} else {
return 0;
}
}
return 1;
}
int main() {
char buffer[20];
struct tm tm = {0};
char *retval = fgets(buffer, sizeof(buffer), stdin);
if (retval == 0) {
puts("Neplatny datum");
return 0;
}
retval = strptime(buffer, "%e.%m.%-Y", &tm);
if (retval == 0 || datevalid(tm.tm_mday, tm.tm_mon + 1, tm.tm_year + 1900) == 0) {
puts("Neplatny datum");
return 0;
}
tm.tm_isdst = -1;
tm.tm_mday += 7;
if (mktime(&tm) == -1) {
puts("Neplatny datum");
return 0;
}
strftime(buffer, sizeof(buffer), "%e.%m.%-Y", &tm);
puts(buffer);
putc('\n', stdout);
return 0;
} }