1
0
mirror of https://github.com/Tha14/toxic.git synced 2024-11-12 23:33:03 +01:00

easier way to format timestamps

This commit is contained in:
Jfreegman 2014-03-12 03:08:13 -04:00
parent 5e377639c8
commit ce76896eb3
2 changed files with 9 additions and 10 deletions

View File

@ -51,10 +51,9 @@ void init_logging_session(uint8_t *name, uint8_t *key, struct chatlog *log)
sprintf(&ident[2], "%02X", key[2] & 0xff);
ident[KEY_IDENT_DIGITS*2+1] = '\0';
} else {
struct tm *tminfo = get_time();
snprintf(ident, sizeof(ident),
"%04d-%02d-%02d[%d:%02d:%02d]", tminfo->tm_year+1900,tminfo->tm_mon+1, tminfo->tm_mday,
tminfo->tm_hour, tminfo->tm_min, tminfo->tm_sec);
uint8_t s[MAX_STR_SIZE];
strftime(s, MAX_STR_SIZE, "%Y-%m-%d[%H:%M:%S]", get_time());
snprintf(ident, sizeof(ident), "%s", s);
path_len += strlen(ident) + 1;
}
@ -96,10 +95,9 @@ void write_to_log(uint8_t *msg, uint8_t *name, struct chatlog *log, bool event)
else
snprintf(name_frmt, sizeof(name_frmt), "%s:", name);
struct tm *tminfo = get_time();
fprintf(log->file,"%04d/%02d/%02d [%d:%02d:%02d] %s %s\n", tminfo->tm_year+1900,
tminfo->tm_mon+1, tminfo->tm_mday, tminfo->tm_hour, tminfo->tm_min,
tminfo->tm_sec, name_frmt, msg);
uint8_t s[MAX_STR_SIZE];
strftime(s, MAX_STR_SIZE, "%Y/%m/%d [%H:%M:%S]", get_time());
fprintf(log->file,"%s %s %s\n", s, name_frmt, msg);
uint64_t curtime = (uint64_t) time(NULL);

View File

@ -67,10 +67,11 @@ struct tm *get_time(void)
/* Prints the time to given window */
void print_time(WINDOW *window)
{
struct tm *timeinfo = get_time();
uint8_t s[MAX_STR_SIZE];
strftime(s, MAX_STR_SIZE, "[%H:%M] ", get_time());
wattron(window, COLOR_PAIR(BLUE));
wprintw(window, "[%d:%02d:%02d] ", timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec);
wprintw(window, "%s", s);
wattroff(window,COLOR_PAIR(BLUE));
}