From: Andrea Zagli Date: Sat, 26 Nov 2011 09:36:41 +0000 (+0100) Subject: Aggiunte alcune funzioni di conversione da e di GDate (closes #217). X-Git-Tag: 0.5.0~20 X-Git-Url: https://saetta.ns0.it/gitweb?a=commitdiff_plain;h=89d0e185205750d54b684eebd7345dc8d5e5b1e1;p=solipa%2Flibsolipa Aggiunte alcune funzioni di conversione da e di GDate (closes #217). --- diff --git a/.anjuta/default.profile b/.anjuta/default.profile index 6937de0..fab0d87 100644 --- a/.anjuta/default.profile +++ b/.anjuta/default.profile @@ -1,14 +1,14 @@ - + + value="anjuta-terminal:TerminalPlugin"/> - + + value="anjuta-tools:ATPPlugin"/> \n\n diff --git a/.anjuta/session/dock-layout.xml b/.anjuta/session/dock-layout.xml index b35c6db..b5b3e4d 100644 --- a/.anjuta/session/dock-layout.xml +++ b/.anjuta/session/dock-layout.xml @@ -1,2 +1,2 @@ - + diff --git a/.anjuta_sym_db.db b/.anjuta_sym_db.db index 1dba8fd..6f5d3ce 100644 Binary files a/.anjuta_sym_db.db and b/.anjuta_sym_db.db differ diff --git a/src/utils.c b/src/utils.c index 16c8107..656cdb9 100644 --- a/src/utils.c +++ b/src/utils.c @@ -880,17 +880,62 @@ struct tm return ret; } +GDateTime +*solipa_gdate_to_gdatetime (GDate *gdate) +{ + GDateTime *ret; + + ret = NULL; + if (g_date_valid (gdate)) + { + ret = g_date_time_new_local (g_date_get_year (gdate), + g_date_get_month (gdate), + g_date_get_day (gdate), + 0, 0, 0.0); + } + + return ret; +} + +GDate +*solipa_gdatetime_to_gdate (GDateTime *gdatetime) +{ + GDate *ret; + + ret = g_new0 (GDate, 1); + g_date_set_year (ret, g_date_time_get_year (gdatetime)); + g_date_set_month (ret, g_date_time_get_month (gdatetime)); + g_date_set_day (ret, g_date_time_get_day_of_month (gdatetime)); + + return ret; +} + const gchar *solipa_tm_to_sql (struct tm *tm_data, const gchar *format) { const gchar *ret; - gchar *_format; ret = g_strdup ("NULL"); if (tm_data != NULL) { - ret = solipa_gdatetime_to_sql (solipa_tm_to_gdatetime (tm_data), _format); + ret = solipa_gdatetime_to_sql (solipa_tm_to_gdatetime (tm_data), format); + } + + return ret; +} + + +const gchar +*solipa_gdate_to_sql (GDate *gdate, const gchar *format) +{ + const gchar *ret; + + ret = g_strdup ("NULL"); + + if (g_date_valid (gdate)) + { + ret = solipa_gdatetime_to_sql (solipa_gdate_to_gdatetime (gdate), format); } return ret; @@ -933,6 +978,18 @@ const gchar return ret; } +GDate +*solipa_get_gdate_from_string (const gchar *string, const gchar *format) +{ + GDate *ret; + + GDateTime *gdatetime; + + gdatetime = solipa_get_gdatetime_from_string (string, format); + + ret = solipa_gdatetime_to_gdate (gdatetime); +} + GDateTime *solipa_get_gdatetime_from_string (const gchar *string, const gchar *format) { @@ -1085,6 +1142,8 @@ GDateTime } } + g_strfreev (format_tokens); + g_strfreev (str_tokens); g_free (delimiters); g_free (new_format); g_free (new_str); @@ -1102,6 +1161,18 @@ GDateTime return ret; } +gchar +*solipa_gdate_format (GDate *gdate, const gchar *format) +{ + gchar *ret; + + if (g_date_valid (gdate)) return ""; + + ret = solipa_gdatetime_format (solipa_gdate_to_gdatetime (gdate), format); + + return ret; +} + gchar *solipa_gdatetime_format (GDateTime *gdatetime, const gchar *format) { diff --git a/src/utils.h b/src/utils.h index 3669859..7312840 100644 --- a/src/utils.h +++ b/src/utils.h @@ -64,10 +64,16 @@ GDate *solipa_get_today_gdate (void); GDateTime *solipa_tm_to_gdatetime (struct tm *tm_data); struct tm *solipa_gdatetime_to_tm (GDateTime *gdatetime); +GDateTime *solipa_gdate_to_gdatetime (GDate *gdate); +GDate *solipa_gdatetime_to_gdate (GDateTime *gdatetime); + const gchar *solipa_tm_to_sql (struct tm *tm_data, const gchar *format); +const gchar *solipa_gdate_to_sql (GDate *gdate, const gchar *format); const gchar *solipa_gdatetime_to_sql (GDateTime *gdatetime, const gchar *format); +GDate *solipa_get_gdate_from_string (const gchar *string, const gchar *format); GDateTime *solipa_get_gdatetime_from_string (const gchar *string, const gchar *format); +gchar *solipa_gdate_format (GDate *gdate, const gchar *format); gchar *solipa_gdatetime_format (GDateTime *gdatetime, const gchar *format); gdouble solipa_round (gdouble value, guint n_decimals);