From 2bde9453ed81a1536dce6bc686893dd3abf9b461 Mon Sep 17 00:00:00 2001 From: Sebastien Helleu Date: Thu, 10 Oct 2013 19:42:11 +0200 Subject: core: use one date format when day changes from day to day+1 --- src/gui/curses/gui-curses-chat.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'src/gui/curses/gui-curses-chat.c') diff --git a/src/gui/curses/gui-curses-chat.c b/src/gui/curses/gui-curses-chat.c index 434395a90..8bdbd52e4 100644 --- a/src/gui/curses/gui-curses-chat.c +++ b/src/gui/curses/gui-curses-chat.c @@ -600,11 +600,35 @@ gui_chat_display_day_changed (struct t_gui_window *window, int simulate) { char temp_message[1024], message[1024], *message_with_color; + int year1, year1_last_yday; if (simulate || (!simulate && (window->win_chat_cursor_y >= window->win_chat_height))) return; + /* + * if date1 is given, compare date1 and date2; if date2 is date1 + 1 day, + * do not display date1 (so wee keep date1 if date2 is > date1 + 1 day) + */ + if (date1) + { + if (date1->tm_year == date2->tm_year) + { + if (date1->tm_yday == date2->tm_yday - 1) + date1 = NULL; + } + else if ((date1->tm_year == date2->tm_year - 1) && (date2->tm_yday == 0)) + { + /* date2 is 01/01, then check if date1 is 31/12 */ + year1 = date1->tm_year + 1900; + year1_last_yday = (((year1 % 400) == 0) + || (((year1 % 4) == 0) && ((year1 % 100) != 0))) ? + 365 : 364; + if (date1->tm_yday == year1_last_yday) + date1 = NULL; + } + } + /* build the message to display */ if (date1) { -- cgit v1.2.3