//prints a live countdown relative to given date void printCountdown (State *s) { s->next = NULL; TDate *date = parse(s->argv[2]); if (!date) { printf("Could not parse date. Check formatting\n"); return; } TDate *now = currentDate(NULL); countdown (toJulian(now), toJulian(date)); }
//prints difference between stored date and present void printDiff (State *s) { s->next = NULL; FILE *in = fopen(makeFilePath(), "rb"); if (in == NULL) { printf("No date stored. Try to store one by calling \"ctd -s [date]\"\n"); return; } double jstored; fread(&jstored, sizeof(double), 1, in); fclose(in); TDate *present = currentDate(NULL); double jpresent = toJulian(present); TDateDiff *diff = tdiff(jstored, jpresent); printDateDiff(diff); printf("\n"); free(present); free(diff); }
//store given date void storeDate (State *s) { s->next = NULL; //check if folder exists struct stat fStat; char *dirName = makeDirPath(); if (stat(dirName, &fStat) == -1) { if (mkdir(dirName, 0700) == -1) { printf("Could not create directory to store data. Check privileges\n"); return; } } TDate *date = parse(s->argv[2]); if (!date) { printf("Could not parse date. Check formatting\n"); return; } FILE *out = fopen(strcat(dirName, "date"), "wb"); if (!out) { printf("Could not open file to store data. Check privileges\n"); return; } double jvalue = toJulian(date); fwrite(&jvalue, sizeof(double), 1, out); fclose(out); free(date); }
UTimeDate::UTimeDate(int day, int year) { U_TRACE_REGISTER_OBJECT(0, UTimeDate, "%d,%d", day, year) julian = toJulian(1,1,year) - 1 + day; fromJulian(julian); }
//prints differnce between the 2 given dates void print2Diff (State *s) { s->next = NULL; TDate *date1 = parse(s->argv[1]); TDate *date2 = parse(s->argv[2]); if (!date1 || !date2) { printf("Could not parse dates. Check formatting\n"); return; } TDateDiff *diff = tdiff(toJulian(date2), toJulian(date1)); printDateDiff(diff); printf("\n"); free(diff); free(date1); free(date2); }
//prints a live countdown relative to stored date void printCountdownStored (State *s) { s->next = NULL; FILE *in = fopen(makeFilePath(), "rb"); if (!in) { printf("No date stored. Try to store one by calling \"ctd -s [date]\"\n"); return; } double jdate; fread(&jdate, sizeof(double), 1, in); fclose(in); TDate *now = currentDate(NULL); double jnow = toJulian(now); countdown (jnow, jdate); }