[chronojump] Better utilDate (don't need try/catch)
- From: Xavier de Blas <xaviblas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [chronojump] Better utilDate (don't need try/catch)
- Date: Wed, 14 Jan 2015 11:17:55 +0000 (UTC)
commit 514894c13baeae8aec9e17c79f17715d7858a7ca
Author: Xavier de Blas <xaviblas gmail com>
Date: Wed Jan 14 12:17:13 2015 +0100
Better utilDate (don't need try/catch)
src/utilDate.cs | 65 +++++++++++++++++++++++++++----------------------------
1 files changed, 32 insertions(+), 33 deletions(-)
---
diff --git a/src/utilDate.cs b/src/utilDate.cs
index 6daee7b..f1bc262 100644
--- a/src/utilDate.cs
+++ b/src/utilDate.cs
@@ -51,41 +51,40 @@ public class UtilDate
//return datetime
public static DateTime FromSql (string date)
{
- try {
- /*
- maybe date format is before 0.72 (d/m/Y)
- this is still here and not in a standalone conversion
- because if someone converts from older database
- can have problems wih constructors with different date formats
- */
-
- DateTime dt; //Datetime (year, month, day) constructor
- if(date.IndexOf('/') == -1) {
- //not contains '/'
- //new sqlite3 compatible date format sice db 0.72 YYYY-MM-DD
- string [] dateFull = date.Split(new char[] {'-'});
- dt = new DateTime(
- Convert.ToInt32(dateFull[0]),
- Convert.ToInt32(dateFull[1]),
- Convert.ToInt32(dateFull[2]));
- } else {
- //contains '/'
- //old D/M/Y format
- string [] dateFull = date.Split(new char[] {'/'});
- dt = new DateTime(
- Convert.ToInt32(dateFull[2]),
- Convert.ToInt32(dateFull[1]),
- Convert.ToInt32(dateFull[0]));
- }
- return dt;
- }
- catch {
- /*
- on report we do a session select with uniqueID = -1
- it returns nothing, date has nothing
- */
+ /*
+ on report we do a session select with uniqueID = -1
+ it returns nothing, date has nothing
+ */
+ if(date == null || date == "")
return DateTime.Now;
+
+
+ /*
+ maybe date format is before 0.72 (d/m/Y)
+ this is still here and not in a standalone conversion
+ because if someone converts from older database
+ can have problems wih constructors with different date formats
+ */
+
+ DateTime dt; //Datetime (year, month, day) constructor
+ if(date.IndexOf('/') == -1) {
+ //not contains '/'
+ //new sqlite3 compatible date format sice db 0.72 YYYY-MM-DD
+ string [] dateFull = date.Split(new char[] {'-'});
+ dt = new DateTime(
+ Convert.ToInt32(dateFull[0]),
+ Convert.ToInt32(dateFull[1]),
+ Convert.ToInt32(dateFull[2]));
+ } else {
+ //contains '/'
+ //old D/M/Y format
+ string [] dateFull = date.Split(new char[] {'/'});
+ dt = new DateTime(
+ Convert.ToInt32(dateFull[2]),
+ Convert.ToInt32(dateFull[1]),
+ Convert.ToInt32(dateFull[0]));
}
+ return dt;
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]