/*
* If we're called with 1 arg, it's a u_long timestamp.
* If we're called with 3 args, we're expecting YYYY MM DD,
* and MM must be 6 or 12, and DD must be 28,
* If we're called with 2 args, we're expecting YYYY MM, and
* MM mst be 6 or 12, and we assume DD is 28.
*/
int
main(
int argc, /* command line options */
char **argv /* poiniter to list of tokens */
)
{
int err = 0;
vint64 expires;
unsigned int year = 0;
unsigned int mon = 0;
unsigned int dom = 0;
int scount;
char *ep;
struct calendar cal = {0};
progname = argv[0];
switch(argc) {
case 2: /* 1 arg, must be a string of digits */
expires = strtouv64(argv[1], &ep, 10);
if (0 == *ep) {
ntpcal_ntp64_to_date(&cal, &expires);
exit(0);
} else {
printf("1 arg, but not a string of digits: <%s>\n",
argv[1]);
err = 1;
}
break;
;;
case 3: /* 2 args, must be YY MM, where MM is 6 or 12 */
dom = 28;
scount = sscanf(argv[1], "%u", &year);
if (1 == scount) {
// printf("2 args: year %u\n", year);
} else {
printf("2 args, but #1 is not a string of digits: <%s>\n", argv[1]);
err = 1;
}
scount = sscanf(argv[2], "%u", &mon);
if (1 == scount) {
if (6 == mon || 12 == mon) {
// printf("2 args: month %u\n", mon);
} else {
printf("2 arg, but #2 is not 6 or 12: <%d>\n", mon);
err = 1;
}
} else {
printf("2 arg, but #2 is not a string of digits: <%s>\n", argv[2]);
err = 1;
}
break;
;;
case 4: /* 3 args, YY MM DD, where MM is 6 or 12, DD is 28 */
scount = sscanf(argv[1], "%u", &year);
if (1 == scount) {
// printf("3 args: year %u\n", year);
} else {
printf("3 args, but #1 is not a string of digits: <%s>\n", argv[1]);
err = 1;
}
scount = sscanf(argv[2], "%u", &mon);
if (1 == scount) {
if (6 == mon || 12 == mon) {
// printf("3 args: month %u\n", mon);
} else {
printf("3 arg, but #2 is not 6 or 12: <%d>\n", mon);
err = 1;
}
} else {
printf("3 arg, but #2 is not a string of digits: <%s>\n", argv[2]);
err = 1;
}
scount = sscanf(argv[3], "%u", &dom);
if (1 == scount) {
if (28 == dom) {
// printf("3 args: dom %u\n", dom);
} else {
printf("3 arg, but #3 is not 28: <%d>\n", dom);
err = 1;
}
} else {
printf("3 arg, but #3 is not a string of digits: <%s>\n", argv[2]);
err = 1;
}
void
test_WraparoundDateIn2036(void) {
// 2036-02-07 06:28:16
// This is (one) wrapping boundary where we go from ULONG_MAX to 0.
struct calendar input = {2036, 0, 2, 7, 6, 28, 16};