use new glib datetime api (replaces deprecated)

This commit is contained in:
Eric House 2020-08-31 17:16:14 -07:00
parent 53563236e4
commit 58dfc32a6e
4 changed files with 25 additions and 8 deletions

View file

@ -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;

View file

@ -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" );
}

View file

@ -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 */

View file

@ -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