[smuxi: 2/3] Engine: fixed storing last seen message / highlight correctly with smuxi-servers (closes: #1058)



commit bff11a093e0e57184a54ee0860aa586036dd2746
Author: Mirco Bauer <meebey meebey net>
Date:   Sat Jun 13 02:03:38 2015 +0200

    Engine: fixed storing last seen message / highlight correctly with smuxi-servers (closes: #1058)
    
    On Mono the DateTimeKind gets lost during serialization of .NET remoting. When
    this happens we store the timestamp in local time instead. Otherwise the
    timezone offset will be applied _again_ leading to incorrect values.

 src/Engine/MessageBuffers/SqliteMessageBuffer.cs |   24 ++++++++++++++++++++-
 1 files changed, 22 insertions(+), 2 deletions(-)
---
diff --git a/src/Engine/MessageBuffers/SqliteMessageBuffer.cs 
b/src/Engine/MessageBuffers/SqliteMessageBuffer.cs
index 1f26cc4..1e77e6a 100644
--- a/src/Engine/MessageBuffers/SqliteMessageBuffer.cs
+++ b/src/Engine/MessageBuffers/SqliteMessageBuffer.cs
@@ -76,7 +76,17 @@ namespace Smuxi.Engine
                     cmd.CommandText = sql;
                     var param = cmd.CreateParameter();
                     param.ParameterName = "timestamp";
-                    param.Value = value.ToUniversalTime().ToString("o");
+                    if (value.Kind == DateTimeKind.Unspecified) {
+                        // HACK: on Mono the DateTimeKind gets lost during
+                        // serialization of .NET remoting. When this happens we
+                        // store the timestamp in local time instead. Otherwise
+                        // the timezone offset will be applied _again_ leading
+                        // to incorrect values, see:
+                        // https://smuxi.im/issues/show/1058
+                        param.Value = value.ToString("o");
+                    } else {
+                        param.Value = value.ToUniversalTime().ToString("o");
+                    }
                     cmd.Parameters.Add(param);
                     cmd.ExecuteNonQuery();
                 }
@@ -109,7 +119,17 @@ namespace Smuxi.Engine
                     cmd.CommandText = sql;
                     var param = cmd.CreateParameter();
                     param.ParameterName = "timestamp";
-                    param.Value = value.ToUniversalTime().ToString("o");
+                    if (value.Kind == DateTimeKind.Unspecified) {
+                        // HACK: on Mono the DateTimeKind gets lost during
+                        // serialization of .NET remoting. When this happens we
+                        // store the timestamp in local time instead. Otherwise
+                        // the timezone offset will be applied _again_ leading
+                        // to incorrect values, see:
+                        // https://smuxi.im/issues/show/1058
+                        param.Value = value.ToString("o");
+                    } else {
+                        param.Value = value.ToUniversalTime().ToString("o");
+                    }
                     cmd.Parameters.Add(param);
                     cmd.ExecuteNonQuery();
                 }


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