X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=src%2Fprint_ddate.c;h=453e5a270efebfe52f74e056ce1972e37df7e2c4;hb=67ad80f0050fba9c1a57a70d1a277925805ed560;hp=6f971471ae354b238bc7704f65d295f7fdf61188;hpb=93ea987f84c528c8405c3fe388b0f3f2b79d61b4;p=i3%2Fi3status diff --git a/src/print_ddate.c b/src/print_ddate.c index 6f97147..453e5a2 100644 --- a/src/print_ddate.c +++ b/src/print_ddate.c @@ -143,12 +143,12 @@ int format_output(char *format, struct disc_time *dt) { printf("St. Tib's Day"); } else { /* ...or parse the substring between %{ and %} ... */ - *i = '\0'; + *tibs_end = '\0'; if (!format_output(i + 2, dt)) return 0; - *i = '%'; + *tibs_end = '%'; } /* ...and continue with the rest */ - i = tibs_end + 2; + i = tibs_end; break; case '}': i++; @@ -164,15 +164,10 @@ int format_output(char *format, struct disc_time *dt) { } /* Get the current date and convert it to discordian */ -struct disc_time *get_ddate() { - time_t current_time; - struct tm *current_tm; +struct disc_time *get_ddate(struct tm *current_tm) { static struct disc_time dt; - if ((current_time = time(NULL)) == (time_t)-1) - return NULL; - - if ((current_tm = localtime(¤t_time)) == NULL) + if (current_tm == NULL) return NULL; /* We have to know, whether we have to insert St. Tib's Day, so whether it's a leap @@ -197,10 +192,10 @@ struct disc_time *get_ddate() { return &dt; } -void print_ddate(const char *format) { +void print_ddate(const char *format, struct tm *current_tm) { static char *form = NULL; struct disc_time *dt; - if ((dt = get_ddate()) == NULL) + if ((dt = get_ddate(current_tm)) == NULL) return; if (form == NULL) if ((form = malloc(strlen(format) + 1)) == NULL)