# HG changeset patch
# User rosfran
# Date 1165946387 0
# Node ID 254e85c4326998b6706979a603c242fedfec2be1
# Parent  631f2cf13501c3c53cfc197b85db8df26085a7a4
[svn r215] Use the GTimeVal GLib date/time structure, instead of using the time_t from libc.

diff -r 631f2cf13501 -r 254e85c43269 gmyth/src/gmyth_common.h
--- a/gmyth/src/gmyth_common.h	Fri Dec 08 23:16:15 2006 +0000
+++ b/gmyth/src/gmyth_common.h	Tue Dec 12 17:59:47 2006 +0000
@@ -58,13 +58,13 @@
     GString *chanid;
     
     /** The program start time. */
-    time_t startts;
+    GTimeVal* startts;
     /** The program end time. */
-    time_t endts;
+    GTimeVal* endts;
     /** The recording schedule start time. */
-    time_t recstartts;
+    GTimeVal* recstartts;
     /** The recording schedule end time */
-    time_t recendts;
+    GTimeVal* recendts;
     
     /** The program title. */
     GString *title;
@@ -97,9 +97,9 @@
     double stars;
     int repeat;
     
-    time_t originalAirDate;
-    time_t lastmodified;
-    time_t lastInUseTime;
+    GTimeVal* originalAirDate;
+    GTimeVal* lastmodified;
+    GTimeVal* lastInUseTime;
     
     gboolean hasAirDate;
 
diff -r 631f2cf13501 -r 254e85c43269 gmyth/src/gmyth_epg.c
--- a/gmyth/src/gmyth_epg.c	Fri Dec 08 23:16:15 2006 +0000
+++ b/gmyth/src/gmyth_epg.c	Tue Dec 12 17:59:47 2006 +0000
@@ -161,7 +161,7 @@
         while ((row = mysql_fetch_row (msql_res)) != NULL){
 
         	channel_info = g_new0(GMythChannelInfo, 1);
-            channel_info->channel_ID = atoi (row[0]);
+            channel_info->channel_ID = g_ascii_strtoull (row[0], NULL, 10);
             channel_info->channel_name = g_string_new (row[1]);
        
 #if 0
@@ -189,8 +189,8 @@
 gmyth_epg_get_program_list (GMythEPG *gmyth_epg, GList **proglist,
 		const gint chan_num, time_t starttime, time_t endtime)
 {
-    GString *startts = gmyth_util_time_to_string(starttime);
-    GString *endts = gmyth_util_time_to_string(endtime);
+    gchar *startts = gmyth_util_time_to_string_from_time_val(starttime);
+    gchar *endts = gmyth_util_time_to_string_from_time_val(endtime);
     MYSQL_ROW row;
     GString *querystr;
     
@@ -219,7 +219,7 @@
         "  AND program.endtime >= '%s' "
         "  AND program.starttime <= '%s' "
         "  AND program.manualid = 0 ",
-        chan_num, startts->str, endts->str);
+        chan_num, startts, endts);
 
     if (!g_strrstr(querystr->str, " GROUP BY "))
         querystr = g_string_append(querystr,
@@ -243,8 +243,8 @@
         GMythProgramInfo *p = g_new0 (GMythProgramInfo, 1);
         p->chanid = g_string_new (row[0]);
 
-        p->startts = gmyth_util_string_to_time (g_string_new (row[1]));
-        p->endts = gmyth_util_string_to_time (g_string_new (row[2]));
+        p->startts = gmyth_util_string_to_time_val (row[1]);
+        p->endts = gmyth_util_string_to_time_val (row[2]);
                                                      
         p->recstartts = p->startts;
         p->recendts = p->endts;
@@ -257,19 +257,19 @@
         p->chanstr = g_string_new (row[7]);
         p->chansign = g_string_new (row[8]);
         p->channame = g_string_new (row[9]);
-        p->repeat = atoi(row[10]);
-        p->chancommfree = atoi(row[11]);
+        p->repeat = g_ascii_strtoull(row[10], NULL, 10);
+        p->chancommfree = g_ascii_strtoull(row[11], NULL, 10);
         p->chanOutputFilters = g_string_new (row[12]);
         p->seriesid = g_string_new (row[13]);
         p->programid = g_string_new (row[14]);
         p->year = g_string_new (row[15]);
-        p->stars = atof(row[16]);
+        p->stars = g_ascii_strtod(row[16], NULL);
 
         if (!row[17] || !strcmp(row[17], "")) {
             p->originalAirDate = 0;
             p->hasAirDate = FALSE;
         } else {
-            p->originalAirDate = gmyth_util_string_to_time (g_string_new (row[17]));
+            p->originalAirDate = gmyth_util_string_to_time_val (row[17]);
             p->hasAirDate = TRUE;
         }
         
diff -r 631f2cf13501 -r 254e85c43269 gmyth/src/gmyth_marshal.list
--- a/gmyth/src/gmyth_marshal.list	Fri Dec 08 23:16:15 2006 +0000
+++ b/gmyth/src/gmyth_marshal.list	Tue Dec 12 17:59:47 2006 +0000
@@ -1,1 +1,2 @@
-VOID:INT,STRING
+VOID:INT,STRING,POINTER
+VOID:INT,POINTER
diff -r 631f2cf13501 -r 254e85c43269 gmyth/src/gmyth_query.h
--- a/gmyth/src/gmyth_query.h	Fri Dec 08 23:16:15 2006 +0000
+++ b/gmyth/src/gmyth_query.h	Tue Dec 12 17:59:47 2006 +0000
@@ -74,7 +74,7 @@
 
 GMythQuery* gmyth_query_new ( );
 MYSQL_RES * gmyth_query_process_statement 
-                (GMythQuery *gmyth_query, char *stmt_str);
+                (GMythQuery *gmyth_query, gchar *stmt_str);
 
 gboolean gmyth_query_connect (GMythQuery *gmyth_query, GMythBackendInfo *backend_info);
 gboolean gmyth_query_disconnect (GMythQuery *gmyth_query);
diff -r 631f2cf13501 -r 254e85c43269 gmyth/src/gmyth_scheduler.c
--- a/gmyth/src/gmyth_scheduler.c	Fri Dec 08 23:16:15 2006 +0000
+++ b/gmyth/src/gmyth_scheduler.c	Tue Dec 12 17:59:47 2006 +0000
@@ -30,10 +30,11 @@
 #include "config.h"
 #endif
 
-#include "gmyth_scheduler.h"
- 
 #include <assert.h>
 
+#include <glib/gprintf.h>
+
+#include "gmyth_scheduler.h"
 #include "gmyth_util.h"
 #include "gmyth_query.h"
 #include "gmyth_socket.h"
@@ -191,7 +192,7 @@
     ScheduleInfo *schedule;
     MYSQL_RES *msql_res;
     GString *query_str = g_string_new ("");
-    GString *date_time = g_string_new ("");
+    gchar *date_time = NULL;
     
     assert(scheduler);
     
@@ -220,14 +221,14 @@
             schedule->channel_id = g_ascii_strtoull (row[2], NULL, 10);
             
             /* generate a time_t from a time and a date db field */
-            g_string_printf (date_time, "%s %s", row[4], row[3]);
+            g_sprintf (date_time, "%sT%s", row[4], row[3]);
             
-            schedule->start_time = gmyth_util_string_to_time (date_time);
+            schedule->start_time = gmyth_util_string_to_time_val (date_time);
             
             /* generate a time_t from a time and a date db field */
-            g_string_printf (date_time, "%s %s", row[6], row[5]);
+            g_sprintf (date_time, "%sT%s", row[6], row[5]);
             
-            schedule->end_time = gmyth_util_string_to_time (date_time);
+            schedule->end_time = gmyth_util_string_to_time_val (date_time);
 
             schedule->title = g_string_new (row[7]);
             schedule->subtitle = g_string_new (row[8]);
@@ -240,7 +241,7 @@
 
     mysql_free_result (msql_res);
     g_string_free(query_str, TRUE);
-    g_string_free(date_time, TRUE);
+    g_free(date_time);
 
     return (*schedule_list == NULL) ? 0 : g_list_length (*schedule_list);
 }
@@ -257,7 +258,7 @@
     RecordedInfo *record;
     MYSQL_RES *msql_res;
     GString *query_str = g_string_new ("");
-    GString *date_time = g_string_new ("");
+    gchar *date_time = NULL;
 	
     assert(scheduler);
     
@@ -290,17 +291,17 @@
              * we are not using the date field */
             /* generate a time_t from a time and a date db field */
             /* g_string_printf (date_time, "%s %s", row[4], row[3]); */
-            g_string_printf (date_time, "%s", row[3]); 
+            g_sprintf (date_time, "%s", row[3]); 
             
-            record->start_time = gmyth_util_string_to_time (date_time);
+            record->start_time = gmyth_util_string_to_time_val (date_time);
 
             /* the db field time already contains the date. therefore
              * we are not using the date field */
             /* generate a time_t from a time and a date db field */
             /* g_string_printf (date_time, "%s %s", row[6], row[5]); */
-            g_string_printf (date_time, "%s", row[5]); 
+            g_sprintf (date_time, "%s", row[5]); 
 
-            record->end_time = gmyth_util_string_to_time (date_time);
+            record->end_time = gmyth_util_string_to_time_val (date_time);
 	
             record->title = g_string_new (row[7]);
             record->subtitle = g_string_new (row[8]);
@@ -315,7 +316,7 @@
     
     mysql_free_result (msql_res);
     g_string_free(query_str, TRUE);
-    g_string_free(date_time, TRUE);
+    g_free(date_time);
 
     return (*recorded_list == NULL) ? 0 : g_list_length (*recorded_list);
 }
@@ -332,30 +333,21 @@
 gmyth_scheduler_add_schedule (GMythScheduler *scheduler,
                         	  ScheduleInfo *schedule_info)
 {
-    struct tm start_tm;
-    struct tm end_tm;
+    //GTimeVal *start_tm;
+    //GTimeVal *end_tm;
 
     MYSQL_RES *msql_res;
     GString *query_str = g_string_new ("");
-
+    
+    gchar *date_time = NULL; 
+    
     assert(scheduler);
     
     if (scheduler->msqlquery == NULL) {
 	g_warning ("[%s] Scheduler db connection not initialized", __FUNCTION__);
-	return 0;
+	return FALSE;
     }
 	
-	/* manipulating time */
-    if(localtime_r(&schedule_info->start_time, &start_tm) == NULL) {
-        g_warning ("localtime_r error in libgmyth scheduler!\n");
-        return FALSE;                 
-    }
-        
-    if(localtime_r(&schedule_info->end_time, &end_tm) == NULL) {
-        g_warning ("localtime_r error in libgmyth scheduler!\n");
-        return FALSE;
-    }	
-	
     //TODO: verify if this funtion realy does what it should do!
     g_string_printf (query_str, "REPLACE INTO record "
 	    "(recordid, type, chanid, starttime, "
@@ -366,26 +358,25 @@
 	    "autocommflag, findday, findtime, findid, "
 	    "search, autotranscode, transcoder, tsdefault, "
 	    "autouserjob1, autouserjob2, autouserjob3, autouserjob4) "
-	    " values ( %d, 1, %d, \"%02d:%02d:00\","	//recordid, type, chanid, starttime
-	    " \"%d-%02d-%02d\", \"%02d:%02d:00\", \"%04d-%02d-%02d\", \"%s\","
+	    " values ( %d, 1, %d, \"%s\","	//recordid, type, chanid, starttime
+	    " \"%s\", \"%s\", \"%s\", \"%s\","
         //startdate, endtime, enddate, title
 	    "DEFAULT, 0, 0, 0, "	//profile, recpriority, maxnewest, inactive
 	    "0, 1, 0, 0, "			//maxepisodes, autoexpire, startoffset, endoffset
 	    "DEFAULT, 6, 15, %d, " 	//recgroup, dupmethod, dupin, station
-	    "1, %d, \"%02d:%02d:00\", %d, "	//autocommflag, findday, findtime, findid
+	    "1, %d, \"%s\", %d, "	//autocommflag, findday, findtime, findid
 	    "5, 0, 29, 1, "			//search, autotranscode, transcoder, tsdefault
 	    "0, 0, 0, 0 );",		//autouserjob1, autouserjob2, autouserjob3, autouserjob4
 	    schedule_info->record_id, schedule_info->channel_id,
-        start_tm.tm_hour, start_tm.tm_min,
-	    start_tm.tm_year+1900, start_tm.tm_mon+1, 
-        start_tm.tm_mday,
-        end_tm.tm_hour, end_tm.tm_min,
-        end_tm.tm_year+1900, end_tm.tm_mon+1, 
-        end_tm.tm_mday, schedule_info->title->str, //title
+        gmyth_util_time_to_string_only_time( schedule_info->start_time ),
+	    	gmyth_util_time_to_string_only_date( schedule_info->start_time ),
+        gmyth_util_time_to_string_only_time( schedule_info->end_time ),
+        gmyth_util_time_to_string_only_date( schedule_info->end_time ), 
+        schedule_info->title->str, //title
     	schedule_info->channel_id,//station
-    	start_tm.tm_wday+1, //findday
-   		start_tm.tm_hour, start_tm.tm_min, //findtime
-   		(gint)(schedule_info->start_time/60/60/24 + 719528)//findid
+    	g_date_get_weekday( gmyth_util_time_val_to_date( schedule_info->start_time ) ), //findday
+   		gmyth_util_time_to_string_only_time( schedule_info->start_time ), //findtime
+   		(gint)(schedule_info->start_time->tv_sec/60/60/24 + 719528)//findid
     );
 
     msql_res = gmyth_query_process_statement (scheduler->msqlquery, query_str->str);
@@ -495,12 +486,12 @@
  */
 GMythProgramInfo*
 gmyth_scheduler_get_recorded (GMythScheduler *scheduler, 
-                              GString *channel, time_t starttime)
+                              GString *channel, GTimeVal* starttime)
 {
 	MYSQL_RES *msql_res;
 	GMythProgramInfo *proginfo = NULL;
 	GString *query_str = g_string_new("");
-	GString *time_str = gmyth_util_time_to_string (starttime);
+	gchar *time_str = gmyth_util_time_to_string_from_time_val (starttime);
 
     assert(scheduler);
     
@@ -521,7 +512,7 @@
                   "ON recorded.chanid = channel.chanid "
                   "WHERE recorded.chanid = \"%s\" "
                   "AND starttime = \"%s\" ;",
-                  channel->str, time_str->str);
+                  channel->str, time_str);
 
     msql_res = gmyth_query_process_statement (scheduler->msqlquery, query_str->str);
 
@@ -533,10 +524,10 @@
     		proginfo = g_new0 (GMythProgramInfo, 1);
     	
 	        proginfo->chanid = g_string_new (msql_row[0]);
-	        proginfo->startts = gmyth_util_string_to_time (g_string_new (msql_row[23]));
-	        proginfo->endts = gmyth_util_string_to_time (g_string_new (msql_row[24]));
-	        proginfo->recstartts = gmyth_util_string_to_time (g_string_new (msql_row[1]));
-	        proginfo->recendts = gmyth_util_string_to_time (g_string_new (msql_row[2]));
+	        proginfo->startts = gmyth_util_string_to_time_val (msql_row[23]);
+	        proginfo->endts = gmyth_util_string_to_time_val (msql_row[24]);
+	        proginfo->recstartts = gmyth_util_string_to_time_val (msql_row[1]);
+	        proginfo->recendts = gmyth_util_string_to_time_val (msql_row[2]);
 	        proginfo->title = g_string_new (msql_row[3]);
 	        proginfo->subtitle = g_string_new (msql_row[4]);
 	        proginfo->description = g_string_new (msql_row[5]);
@@ -550,7 +541,7 @@
 	        proginfo->programid = g_string_new (msql_row[12]);
 	        proginfo->filesize = g_ascii_strtoull (msql_row[13], NULL, 10);
 	
-	        proginfo->lastmodified = gmyth_util_string_to_time (g_string_new (msql_row[14]));
+	        proginfo->lastmodified = gmyth_util_string_to_time_val (msql_row[14]);
 	        
 	        proginfo->stars = g_ascii_strtod (msql_row[15], NULL);
 	        proginfo->repeat = g_ascii_strtoull (msql_row[16], NULL, 10);
@@ -559,7 +550,7 @@
 	            proginfo->originalAirDate = 0;
 	            proginfo->hasAirDate = FALSE;
 	        } else {
-	            proginfo->originalAirDate = gmyth_util_string_to_time (g_string_new (msql_row[17]));
+	            proginfo->originalAirDate = gmyth_util_string_to_time_val (msql_row[17]);
 	            proginfo->hasAirDate = TRUE;
 	        }
 	        
@@ -582,7 +573,7 @@
 
 	mysql_free_result (msql_res);
     g_string_free(query_str, TRUE);
-    g_string_free(time_str, TRUE);
+    g_free(time_str);
 
     return proginfo;
 }
diff -r 631f2cf13501 -r 254e85c43269 gmyth/src/gmyth_scheduler.h
--- a/gmyth/src/gmyth_scheduler.h	Fri Dec 08 23:16:15 2006 +0000
+++ b/gmyth/src/gmyth_scheduler.h	Tue Dec 12 17:59:47 2006 +0000
@@ -102,8 +102,8 @@
 	gint    program_id;
 	gint    channel_id;
 	
-    time_t start_time;
-	time_t end_time;
+  GTimeVal* start_time;
+	GTimeVal* end_time;
     
 	GString *title;
 	GString *subtitle;
@@ -117,8 +117,8 @@
     guint    program_id;
     guint    channel_id;
 
-    time_t start_time;
-    time_t end_time;
+    GTimeVal*  start_time;
+    GTimeVal*  end_time;
 
     GString *title;
     GString *subtitle;
@@ -144,7 +144,7 @@
                                                    GList **rec_list);
 
 GMythProgramInfo* gmyth_scheduler_get_recorded (GMythScheduler *scheduler, 
-                                        		GString *channel, time_t starttime);
+                                        		GString *channel, GTimeVal* starttime);
 
 gint            gmyth_scheduler_add_schedule(GMythScheduler *scheduler, 
                                              ScheduleInfo *schedule_info);
diff -r 631f2cf13501 -r 254e85c43269 gmyth/src/gmyth_tvchain.c
--- a/gmyth/src/gmyth_tvchain.c	Fri Dec 08 23:16:15 2006 +0000
+++ b/gmyth/src/gmyth_tvchain.c	Tue Dec 12 17:59:47 2006 +0000
@@ -71,7 +71,7 @@
 	tvchain->tvchain_id = NULL;
 
 	tvchain->cur_chanid = g_string_new ("");
-	tvchain->cur_startts = 0;
+	tvchain->cur_startts = NULL;
 }
 
 static void
@@ -130,19 +130,20 @@
     hostname = gmyth_backend_info_get_hostname (backend_info);
     
     if (tvchain->tvchain_id == NULL) {
-	    GString *isodate;
-    	time_t cur_time;
+	    gchar *isodate = NULL;
+    	GTimeVal *cur_time = g_new0( GTimeVal, 1 );
 
-	    time(&cur_time);
-    	isodate = gmyth_util_time_to_isoformat (cur_time);
+	    g_get_current_time(cur_time);
+    	isodate = gmyth_util_time_to_isoformat_from_time_val (cur_time);
 
-	    tvchain->tvchain_id = g_string_sized_new (7 + strlen (hostname) + isodate->len);
+	    tvchain->tvchain_id = g_string_sized_new (7 + strlen (hostname) + strlen(isodate));
     	g_string_printf(tvchain->tvchain_id, 
-	    	"live-%s-%s", hostname, isodate->str);
+	    	"live-%s-%s", hostname, isodate);
 
     	gmyth_debug ("[%s] tv_chain_id: %s", __FUNCTION__, tvchain->tvchain_id->str);
 
-	    g_string_free(isodate, TRUE);
+			if (isodate)
+	    	g_free(isodate);
     } else {
     	g_warning ("[%s] TVchain already initialized", __FUNCTION__);
     }
@@ -214,8 +215,8 @@
 		while ((msql_row = mysql_fetch_row (msql_res)) != NULL) {
 			struct LiveTVChainEntry *entry = g_new0 (struct LiveTVChainEntry, 1);
 			entry->chanid = g_string_new (msql_row[0]);
-			entry->starttime = gmyth_util_string_to_time (g_string_new ((gchar*)msql_row[1]));
-			entry->endtime = gmyth_util_string_to_time (g_string_new (msql_row[2]));
+			entry->starttime = gmyth_util_string_to_time_val ((gchar*)msql_row[1]);
+			entry->endtime = gmyth_util_string_to_time_val (msql_row[2]);
 			entry->discontinuity = atoi (msql_row[3]) != 0;
 			entry->hostprefix = g_string_new (msql_row[5]);
 			entry->cardtype = g_string_new (msql_row[6]);
@@ -275,10 +276,10 @@
  * @param chanid The channel id.
  * @param startts The program start time.
  */
-int
-gmyth_tvchain_program_is_at (GMythTVChain *tvchain, GString *chanid, time_t startts)
+gint
+gmyth_tvchain_program_is_at (GMythTVChain *tvchain, GString *chanid, GTimeVal* startts)
 {
-	int count = 0;
+	gint count = 0;
 	struct LiveTVChainEntry *entry;
 	GList *tmp_list = tvchain->tvchain_list;
 	guint list_size = g_list_length (tvchain->tvchain_list);
@@ -288,8 +289,8 @@
 	for (; tmp_list && ( count < list_size ); tmp_list = tvchain->tvchain_list->next, count++)
 	{
 		entry = (struct LiveTVChainEntry*) tmp_list->data;
-		if (!g_strncasecmp (entry->chanid->str, chanid->str, chanid->len)
-				&& entry->starttime == startts)
+		if ( !g_strncasecmp (entry->chanid->str, chanid->str, chanid->len)
+				&& entry->starttime == startts )
 		{
 			g_static_mutex_unlock( &mutex );
 			return count;
@@ -307,7 +308,7 @@
  * @return The program info structure.
  */
 GMythProgramInfo*
-gmyth_tvchain_get_program_at (GMythTVChain *tvchain, int index)
+gmyth_tvchain_get_program_at (GMythTVChain *tvchain, gint index)
 {
 	struct LiveTVChainEntry *entry;
 
@@ -326,7 +327,7 @@
  * @return The LiveTVchainEntry structure.
  */
 struct LiveTVChainEntry*
-gmyth_tvchain_get_entry_at (GMythTVChain *tvchain, int index)
+gmyth_tvchain_get_entry_at (GMythTVChain *tvchain, gint index)
 {
 	struct LiveTVChainEntry* chain_entry = NULL;
 
@@ -334,8 +335,8 @@
 	
 	g_static_mutex_lock( &mutex );
 	
-	int size = g_list_length (tvchain->tvchain_list);
-	int new_index = (index < 0 || index >= size) ? size - 1 : index;
+	gint size = g_list_length (tvchain->tvchain_list);
+	gint new_index = (index < 0 || index >= size) ? size - 1 : index;
 
 	if (new_index >= 0) 
 		chain_entry = (struct LiveTVChainEntry*) g_list_nth_data (tvchain->tvchain_list, new_index);
@@ -380,7 +381,7 @@
 	if (proginfo) {
 		proginfo->pathname = g_string_prepend (proginfo->pathname, entry->hostprefix->str);
 	} else {
-		g_warning ("tvchain_entry_to_program(%s, %ld) failed!", entry->chanid->str, entry->starttime);
+		g_warning ("tvchain_entry_to_program( chan id = %s, starttime = %ld) failed!", entry->chanid->str, entry->starttime);
 	}
 
 	return proginfo;
diff -r 631f2cf13501 -r 254e85c43269 gmyth/src/gmyth_tvchain.h
--- a/gmyth/src/gmyth_tvchain.h	Fri Dec 08 23:16:15 2006 +0000
+++ b/gmyth/src/gmyth_tvchain.h	Tue Dec 12 17:59:47 2006 +0000
@@ -53,8 +53,8 @@
 {
     GString *chanid;
 
-    time_t starttime;
-    time_t endtime;
+    GTimeVal* starttime;
+    GTimeVal* endtime;
     
     gboolean discontinuity; // if true, can't play smooth from last entry
     GString *hostprefix;
@@ -79,9 +79,9 @@
 	GString *tvchain_id;
 	GList   *tvchain_list;
 	
-	time_t  cur_startts;
+	GTimeVal*  cur_startts;
 	GString *cur_chanid;
-	int     cur_pos;
+	gint     cur_pos;
 
     GMythBackendInfo *backend_info;
 };
@@ -93,8 +93,8 @@
                                          GMythBackendInfo *backend_info);
 gboolean    gmyth_tvchain_reload_all    (GMythTVChain *tvchain);
 GString*    gmyth_tvchain_get_id        (GMythTVChain *tvchain);
-int         gmyth_tvchain_program_is_at (GMythTVChain *tvchain, 
-                                         GString *chanid, time_t startts);
+gint         gmyth_tvchain_program_is_at (GMythTVChain *tvchain, 
+                                         GString *chanid, GTimeVal* startts);
 
 struct LiveTVChainEntry* gmyth_tvchain_get_entry_at (GMythTVChain *tvchain, 
                                                      gint index);
diff -r 631f2cf13501 -r 254e85c43269 gmyth/src/gmyth_util.c
--- a/gmyth/src/gmyth_util.c	Fri Dec 08 23:16:15 2006 +0000
+++ b/gmyth/src/gmyth_util.c	Tue Dec 12 17:59:47 2006 +0000
@@ -29,17 +29,17 @@
 #include "config.h"
 #endif
 
-#include "gmyth_util.h"
+#define _XOPEN_SOURCE
+#define _XOPEN_SOURCE_EXTENDED
 
 #include <glib.h>
 #include <glib/gprintf.h>
+#include <time.h>
+#include <sys/time.h>
 
-#include "gmyth_backendinfo.h"
-#include "gmyth_socket.h"
-#include "gmyth_programinfo.h"
-#include "gmyth_common.h"
-#include "gmyth_debug.h"
+#include "gmyth.h"
 
+static GStaticMutex mutex = G_STATIC_MUTEX_INIT;
 
 /** Converts a time_t struct in a GString at ISO standard format 
  * (e.g. 2006-07-20T09:56:41).
@@ -56,7 +56,10 @@
 	struct tm tm_time;
 	GString *result;
 	
+	g_static_mutex_lock ( &mutex );
+	
 	if (localtime_r(&time_value, &tm_time) == NULL) {
+		g_static_mutex_unlock ( &mutex );
 		g_warning ("gmyth_util_time_to_isoformat convertion error!\n");
         return NULL;
 	}
@@ -65,8 +68,114 @@
 	g_string_printf(result, "%04d-%02d-%02dT%02d:%02d:%02d",
 		tm_time.tm_year + 1900, tm_time.tm_mon + 1, tm_time.tm_mday,
 		tm_time.tm_hour, tm_time.tm_min, tm_time.tm_sec);
+		
+	gmyth_debug( "Result (ISO 8601) = %s", result->str );
+		
+	g_static_mutex_unlock ( &mutex );
 	
 	return result;
+	
+	
+}
+
+/** Converts a time_t struct in a GString at ISO standard format 
+ * (e.g. 2006-07-20T09:56:41).
+ * 
+ * The returned GString memory should be deallocated from 
+ * the calling function.
+ *
+ * @param time_value the GTimeValue to be converted
+ * @return GString* the converted isoformat string 
+ */
+static gchar*
+gmyth_util_time_to_isoformat_from_time_val_fmt ( const gchar *fmt_string, GTimeVal* time)
+{
+	
+	gchar *result = g_time_val_to_iso8601( time );
+	gmyth_debug ("GMythUtil: before transcoding, result is: %s!\n", result);
+	
+	struct tm* tm_timeval = g_new0( struct tm, 1 );
+	
+	g_return_val_if_fail( fmt_string != NULL, NULL );
+
+  if ( NULL == time ) { 
+		gmyth_debug ("GMythUtil: time_to_isoformat_from_time converter error (timeval == NULL)!\n");
+		return NULL;
+	}
+	
+	g_static_mutex_lock ( &mutex );
+	
+	strptime( result, "%Y-%m-%dT%H:%M:%SZ", tm_timeval ); 
+	
+	//g_date_set_time_val( date, time );
+	
+	//g_date_strftime( result, 21, fmt_string, date );
+	strftime( result, strlen(result), fmt_string, tm_timeval );
+	
+	g_static_mutex_unlock ( &mutex );
+	
+	gmyth_debug( "Result (ISO 8601) = %s", result  );
+	
+	//if ( date != NULL )
+	//	g_date_free( date );
+	
+	return result;	
+		
+}
+
+/** Converts a time_t struct in a GString at ISO standard format 
+ * (e.g. 2006-07-20T09:56:41).
+ * 
+ * The returned GString memory should be deallocated from 
+ * the calling function.
+ *
+ * @param time_value the GTimeValue to be converted
+ * @return GString* the converted isoformat string 
+ */
+gchar*
+gmyth_util_time_to_isoformat_from_time_val ( GTimeVal* time )
+{
+	gchar *result = gmyth_util_time_to_isoformat_from_time_val_fmt( "%Y-%m-%d %T", time );
+	//result[10] = ' ';
+	//result[ strlen(result) - 1] = '\0';
+	
+	return result;	
+}
+
+/** Converts a time_t struct in a GString at ISO standard format 
+ * (e.g. 2006-07-20T09:56:41).
+ * 
+ * The returned GString memory should be deallocated from 
+ * the calling function.
+ *
+ * @param time_value the GTimeValue to be converted
+ * @return GString* the converted isoformat string 
+ */
+gchar*
+gmyth_util_time_to_string_only_date ( GTimeVal* time )
+{
+	gchar *result = gmyth_util_time_to_isoformat_from_time_val_fmt( "%y-%m-%d", time );
+	result[10] = ' ';
+	result[ strlen(result) - 1] = '\0';
+	return result;
+}
+
+/** Converts a time_t struct in a GString at ISO standard format 
+ * (e.g. 2006-07-20T09:56:41).
+ * 
+ * The returned GString memory should be deallocated from 
+ * the calling function.
+ *
+ * @param time_value the GTimeValue to be converted
+ * @return GString* the converted isoformat string 
+ */
+gchar*
+gmyth_util_time_to_string_only_time ( GTimeVal* time )
+{
+	gchar *result = gmyth_util_time_to_isoformat_from_time_val_fmt( "%T", time );
+	result[10] = ' ';
+	result[ strlen(result) - 1] = '\0';
+	return result;
 }
 
 /** Converts a time_t struct in a GString to the following 
@@ -87,6 +196,23 @@
 	return result;
 }
 
+/** Converts a time_t struct in a GString to the following 
+ * format (e.g. 2006-07-20 09:56:41).
+ * 
+ * The returned GString memory should be deallocated from 
+ * the calling function.
+ *
+ * @param time_value the time value to be converted
+ * @return GString* the converted string 
+ */
+gchar*
+gmyth_util_time_to_string_from_time_val (GTimeVal *time_val)
+{
+	gchar *result = gmyth_util_time_to_isoformat_from_time_val (time_val);
+
+	return result;
+}
+
 /** Converts a GString in the following format 
  * (e.g. 2006-07-20 09:56:41) to a time_t struct.
  * 
@@ -96,27 +222,106 @@
 time_t
 gmyth_util_string_to_time (GString* time_str)
 {
-	int year, month, day, hour, min, sec;
+	gint year, month, day, hour, min, sec;
+	GDate *date = g_date_new();
     
-#if 0
-	gmyth_debug( "[%s] time_str = %s.\n", __FUNCTION__, time_str != NULL ? time_str->str : "[time string is NULL!]" );
-#endif
+	gmyth_debug( "[%s] time_str = %s. [%s]\n", __FUNCTION__, time_str != NULL ? 
+					time_str->str : "[time string is NULL!]", g_strdelimit( time_str->str, " ", 'T' ) );
 
-	if (sscanf (time_str->str, "%04d-%02d-%02d %02d:%02d:%02d",
-			&year, &month, &day, &hour, &min, &sec) < 3) { /* At least date */
+
+	//if (sscanf (time_str->str, "%04d-%02d-%02d %02d:%02d:%02d",
+	//		&year, &month, &day, &hour, &min, &sec) < 3) {				
+	//g_date_set_parse( date, time_str->str );
+  if ( NULL == date ) { 
 		g_warning ("GMythUtil: isoformat_to_time converter error!\n");
 		return 0;
-	} else {
-		struct tm* tm_time = g_new0( struct tm, 1 );
+	}
+	
+	g_static_mutex_lock ( &mutex );
+	//GDate *date = g_date_new_dmy( day, month - 1, year - 1900 );
+	
+	struct tm* tm_time = g_malloc0( sizeof(struct tm) );
+/*		
 		tm_time->tm_year = year - 1900;
 		tm_time->tm_mon = month - 1;
 		tm_time->tm_mday = day;
 		tm_time->tm_hour = hour;
 		tm_time->tm_min = min;
 		tm_time->tm_sec = sec;
-		
-		return mktime (tm_time);
+	*/
+	
+	GTimeVal *time = g_new0( GTimeVal, 1 ); 
+	
+	if ( !g_time_val_from_iso8601( g_strdelimit( time_str->str, " ", 'T' ), time ) )
+	{
+		gmyth_debug( "ERROR! Problems converting to GTimeVal == %s\n", g_time_val_to_iso8601( time ) );
+	} 
+	
+	gmyth_debug( "Converted to GTimeVal == %s\n", g_time_val_to_iso8601( time ) );
+	
+	g_date_set_time_val( date, time );
+	
+	g_date_to_struct_tm( date, tm_time ); 
+	
+	g_static_mutex_unlock ( &mutex );
+	
+	return mktime( tm_time );
+}
+
+/** Converts a GString in the following format 
+ * (e.g. 2006-07-20 09:56:41) to a time_t struct.
+ * 
+ * @param time_str the string to be converted
+ * @return time_t the time converted value
+ */
+GDate *
+gmyth_util_time_val_to_date (GTimeVal* time)
+{
+	GDate *date = g_date_new();
+    
+  if ( NULL == date ) { 
+		g_warning ("GMythUtil: GDate *gmyth_util_time_val_to_date (GTimeVal* time) - converter error!\n");
+		return 0;
 	}
+	
+	g_date_set_time_val( date, time );
+	
+	gmyth_debug( "Converted from GTimeVal == %s to GDate\n", g_time_val_to_iso8601( time ) );
+	
+	return date;
+}
+
+/** Converts a GString in the following format 
+ * (e.g. 2006-07-20 09:56:41) to a time_t struct.
+ * 
+ * @param time_str the string to be converted
+ * @return time_t the time converted value
+ */
+GTimeVal*
+gmyth_util_string_to_time_val (gchar* time_str)
+{
+	GTimeVal *time = g_new0( GTimeVal, 1 ); 
+    
+	gmyth_debug( "[%s] time_str = %s. [%s]\n", __FUNCTION__, time_str != NULL ? 
+					time_str : "[time string is NULL!]", g_strdelimit( time_str, " ", 'T' ) );
+
+  if ( NULL == time ) { 
+		g_warning ("GMythUtil: isoformat_to_time converter error!\n");
+		return NULL;
+	}
+	
+	g_static_mutex_lock ( &mutex );
+	
+	if ( !g_time_val_from_iso8601( g_strdelimit( time_str, " ", 'T' ), time ) )
+	{
+		gmyth_debug( "ERROR! Problems converting to GTimeVal == %s\n", g_strdelimit( time_str, " ", 'T' ) );
+	} 
+	
+	gmyth_debug( "Converted to GTimeVal == %s\n", g_time_val_to_iso8601( time ) );
+	
+	g_static_mutex_unlock ( &mutex );
+	
+	return time;
 }
 
 /** Decodes a long long variable from the string list
@@ -150,7 +355,7 @@
 }
 
 gboolean
-gmyth_util_file_exists (GMythBackendInfo *backend_info, const char* filename)
+gmyth_util_file_exists (GMythBackendInfo *backend_info, const gchar* filename)
 {
     GMythSocket *socket;
     gboolean res;
diff -r 631f2cf13501 -r 254e85c43269 gmyth/src/gmyth_util.h
--- a/gmyth/src/gmyth_util.h	Fri Dec 08 23:16:15 2006 +0000
+++ b/gmyth/src/gmyth_util.h	Tue Dec 12 17:59:47 2006 +0000
@@ -36,13 +36,25 @@
 
 G_BEGIN_DECLS
 
-GString *   gmyth_util_time_to_isoformat(time_t time_value);
-GString *   gmyth_util_time_to_string   (time_t time_value);
+GString 		*gmyth_util_time_to_isoformat(time_t time_value);
+GString 		*gmyth_util_time_to_string   (time_t time_value);
 time_t      gmyth_util_string_to_time   (GString* time_str);
-gint64     gmyth_util_decode_long_long (GMythStringList *strlist, 
+gint64     	gmyth_util_decode_long_long (GMythStringList *strlist, 
                                          guint offset);
+                                         
+GTimeVal		*gmyth_util_string_to_time_val (gchar* time_str);
 
-gboolean gmyth_util_file_exists (GMythBackendInfo *backend_info, const char* filename);
+gchar 			*gmyth_util_time_to_isoformat_from_time_val(GTimeVal *time);
+
+gchar				*gmyth_util_time_to_string_only_date ( GTimeVal* time );
+
+gchar				*gmyth_util_time_to_string_only_time ( GTimeVal* time );
+
+gchar				*gmyth_util_time_to_string_from_time_val (GTimeVal *time_val);
+
+GDate 			*gmyth_util_time_val_to_date (GTimeVal* time);
+
+gboolean 		gmyth_util_file_exists (GMythBackendInfo *backend_info, const gchar* filename);
 
 G_END_DECLS