Howdy folks,
The DateTime to time_t marshaller creates a DateTime instance set to
midnight of January 1, 1970 and subtracts that from the DateTime
instance passed into the marshaller to obtain the time_t. The DateTime
instance passed to DateTimeTotime_t() should be in the caller's local
time zone. However, the epoch DateTime instance is not. DateTime (int,
int, int, int, int, int) does not take into account the local time zone.
Thus, the resulting time_t is off by the UTC offset of the caller.
I thought that maybe you were required to convert the DateTime instance
to UTC before passing it to the marshaller until I saw that the epoch
instance in the marshaller was named local_epoch.
This patch ensures that both the DateTime instance passed into the
marshaller and the epoch instance are in UTC before doing the
subtraction.
Please CC me on any responses as I am not subscribed to the list.
Chris
diff -ur gtk-sharp/glib/Marshaller.cs gtk-sharp-test/glib/Marshaller.cs
--- gtk-sharp/glib/Marshaller.cs 2005-08-17 14:06:15.000000000 -0400
+++ gtk-sharp-test/glib/Marshaller.cs 2005-08-17 14:28:22.000000000 -0400
@@ -237,17 +237,18 @@
return unmarshal_32 (array, argc);
}
- static DateTime local_epoch = new DateTime (1970, 1, 1, 0, 0, 0);
+ static DateTime epoch = new DateTime (1970, 1, 1, 0, 0, 0);
static int utc_offset = (int) (TimeZone.CurrentTimeZone.GetUtcOffset (DateTime.Now)).TotalSeconds;
public static IntPtr DateTimeTotime_t (DateTime time)
{
- return new IntPtr (((int)time.Subtract (local_epoch).TotalSeconds));
+ time = time.ToUniversalTime ();
+ return new IntPtr (((int)time.Subtract (epoch).TotalSeconds));
}
public static DateTime time_tToDateTime (IntPtr time_t)
{
- return local_epoch.AddSeconds ((int)time_t + utc_offset);
+ return epoch.AddSeconds ((int)time_t + utc_offset);
}
[DllImport("glibsharpglue-2")]
_______________________________________________
Gtk-sharp-list maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/gtk-sharp-list