[easytag/wip/disc-number] Use GDateTime instead of localtime()



commit 04b0db244fd99612ed99c04aa582b9b8b45baeab
Author: Pinak Ahuja <pinak ahuja gmail com>
Date:   Sat Jul 20 18:09:45 2013 +0100

    Use GDateTime instead of localtime()

 src/log.c  |   21 ++++++++-------------
 src/misc.c |   15 ++++++---------
 2 files changed, 14 insertions(+), 22 deletions(-)
---
diff --git a/src/log.c b/src/log.c
old mode 100644
new mode 100755
index 14ef135..7be6785
--- a/src/log.c
+++ b/src/log.c
@@ -224,19 +224,14 @@ void Log_Clean_Log_List (void)
 static gchar *
 Log_Format_Date (void)
 {
-    struct tm *tms;
-    time_t nowtime;
-    gchar *current_date, *current_work = g_malloc0(21);
-
-    // Get current time and date
-    nowtime = time(NULL);
-    tms = localtime(&nowtime);
-    strftime(current_work,20,"%X",tms); // Time without date in current locale
-    //strftime(current_work,20,"%x",ptr); // Date without time in current locale
-    current_date = Try_To_Validate_Utf8_String(current_work);
-    g_free(current_work);
-
-    return current_date;
+    GDateTime *dt;
+    gchar *time;
+
+    dt = g_date_time_new_now_local ();
+    /* Time without date in current locale. */
+    time = g_date_time_format (dt, "%X");
+
+    return time;
 }
 
 
diff --git a/src/misc.c b/src/misc.c
old mode 100644
new mode 100755
index 811b22c..41e473f
--- a/src/misc.c
+++ b/src/misc.c
@@ -416,15 +416,13 @@ void Insert_Only_Digit (GtkEditable *editable, const gchar *inserted_text, gint
 /*
  * Parse and auto complete date entry if you don't type the 4 digits.
  */
-#include <time.h>
 #include <stdlib.h>
 gboolean Parse_Date (void)
 {
     const gchar *year;
     gchar *tmp, *tmp1;
-    gchar current_year[5];
-    time_t t;
-    struct tm t0;
+    gchar *current_year;
+    GDateTime *dt;
 
     /* Early return. */
     if (!DATE_AUTO_COMPLETION) return FALSE;
@@ -434,11 +432,8 @@ gboolean Parse_Date (void)
 
     if ( strcmp(year,"")!=0 && strlen(year)<4 )
     {
-        t = time(NULL);
-        /* Get the current date */
-        memcpy(&t0, localtime(&t), sizeof(struct tm));
-        /* Put the current year in 'current_year' tab */
-        sprintf(current_year,"%04d",1900+t0.tm_year);
+        dt = g_date_time_new_now_local ();
+        current_year = g_date_time_format (dt, "%Y");
 
         tmp = &current_year[4-strlen(year)];
         if ( atoi(year) <= atoi(tmp) )
@@ -457,6 +452,8 @@ gboolean Parse_Date (void)
             gtk_entry_set_text(GTK_ENTRY(YearEntry),tmp1);
             g_free(tmp1);
         }
+
+        g_free (current_year);
     }
     return FALSE;
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]