/* POSIX arvelie.c * * a simple program to convert dates to arvelie. * read more: https://wiki.xxiivv.com/site/arvelie.html */ #include #include #include #include #include void usage(); int main(int argc, char* argv[]); void usage() { fprintf(stderr, "usage: arvelie [-d YYYY-MM-DD]\n"); exit(EXIT_FAILURE); } int main(int argc, char* argv[]) { time_t t = -1; char* inputDate = NULL; int opt; while ((opt = getopt(argc, argv, ":d:")) != -1) { switch (opt) { case 'd': inputDate = optarg; break; case '?': usage(); break; case ':': usage(); break; default: usage(); } } if (inputDate != NULL) { struct tm tm = {0}; strptime(inputDate, "%Y-%m-%d", &tm); t = mktime(&tm); } else { t = time(NULL); } struct tm* date = localtime(&t); int yday = date->tm_yday; int year = date->tm_year % 100; char month = (yday < 364) ? (char)65 + (yday / 14) : '+'; int day = yday % 14; printf("%02d%c%02d\n", year, month, day); exit(EXIT_SUCCESS); }