diff --git a/xwords4/linux/curgamlistwin.c b/xwords4/linux/curgamlistwin.c index a3cbfbea4..bcb7afdfd 100644 --- a/xwords4/linux/curgamlistwin.c +++ b/xwords4/linux/curgamlistwin.c @@ -26,6 +26,7 @@ #include "linuxmain.h" #include "device.h" #include "strutils.h" +#include "linuxutl.h" struct CursGameList { WINDOW* window; @@ -265,8 +266,9 @@ cgl_draw( CursGameList* cgl ) data[line][col++] = g_strdup_printf( "%d", gi->nMoves ); data[line][col++] = g_strdup_printf( "%d", gi->turn ); data[line][col++] = g_strdup_printf( "%d", gi->nPending ); - GTimeVal timerVal = { tv_sec: gi->dupTimerExpires, tv_usec: 0 }; - data[line][col++] = g_time_val_to_iso8601( &timerVal ); + gchar buf[64]; + formatSeconds( gi->dupTimerExpires, buf, VSIZE(buf) ); + data[line][col++] = g_strdup( buf ); XP_ASSERT( col == VSIZE(data[line]) ); ++line; diff --git a/xwords4/linux/gtkmain.c b/xwords4/linux/gtkmain.c index 8c30ad1c5..291ab28d2 100644 --- a/xwords4/linux/gtkmain.c +++ b/xwords4/linux/gtkmain.c @@ -244,10 +244,11 @@ add_to_list( GtkWidget* list, sqlite3_int64 rowid, XP_Bool isNew, gchar* localString = 0 <= gib->turn ? gib->turnLocal ? "YES" : "NO" : ""; - GTimeVal timeval = { tv_sec: gib->lastMoveTime, tv_usec: 0 }; - gchar* timeStr = g_time_val_to_iso8601( &timeval ); - GTimeVal timerVal = { tv_sec: gib->dupTimerExpires, tv_usec: 0 }; - gchar* timerStr = g_time_val_to_iso8601( &timerVal ); + gchar timeStr[64]; + formatSeconds( gib->lastMoveTime, timeStr, VSIZE(timeStr) ); + gchar timerStr[64]; + formatSeconds( gib->dupTimerExpires, timerStr, VSIZE(timeStr) ); + gtk_list_store_set( store, &iter, ROW_ITEM, rowid, ROW_THUMB, gib->snap, @@ -267,7 +268,6 @@ add_to_list( GtkWidget* list, sqlite3_int64 rowid, XP_Bool isNew, LASTTURN_ITEM, timeStr, DUPTIMER_ITEM, timerStr, -1 ); - g_free( timeStr ); XP_LOGF( "DONE adding" ); } diff --git a/xwords4/linux/linuxutl.c b/xwords4/linux/linuxutl.c index 8176cbc47..0eb0e9674 100644 --- a/xwords4/linux/linuxutl.c +++ b/xwords4/linux/linuxutl.c @@ -603,7 +603,20 @@ formatTimerText( gchar* buf, int bufLen, int secondsLeft ) int minutes = secondsLeft / 60; int seconds = secondsLeft % 60; XP_SNPRINTF( buf, bufLen, "% 1d:%02d", minutes, seconds ); -} /* gtkFormatTimerText */ +} + +void +formatSeconds( int unixSeconds, gchar* buf, int bufLen ) +{ + GDateTime* timeval = g_date_time_new_from_unix_local( unixSeconds ); + gchar* str = g_date_time_format_iso8601 ( timeval ); + int len = strlen( str ); + if ( len < bufLen ) { + XP_MEMCPY( buf, str, len + 1 ); + } + g_date_time_unref( timeval ); + g_free( str ); +} #ifdef TEXT_MODEL /* This is broken for UTF-8, even Spanish */ diff --git a/xwords4/linux/linuxutl.h b/xwords4/linux/linuxutl.h index 1f6091d44..4785ec4bd 100644 --- a/xwords4/linux/linuxutl.h +++ b/xwords4/linux/linuxutl.h @@ -59,4 +59,6 @@ XP_U32 linux_getCurSeconds(); void formatTimerText( gchar* buf, int bufLen, int secondsLeft ); +void formatSeconds( int unixSeconds, gchar* buf, int bufLen ); + #endif