diff options
author | Homer Horwitz | 2008-10-18 15:26:41 +0000 |
---|---|---|
committer | Homer Horwitz | 2008-10-18 15:26:41 +0000 |
commit | 3a75a54da1d973d0a8044a680c97bc2a54995548 (patch) | |
tree | 6ab775de65c290ac55b0310c828e0ade7e808403 /OpenSim/Framework/Util.cs | |
parent | Guard against a null ref that can prevent objects from being persisted (diff) | |
download | opensim-SC-3a75a54da1d973d0a8044a680c97bc2a54995548.zip opensim-SC-3a75a54da1d973d0a8044a680c97bc2a54995548.tar.gz opensim-SC-3a75a54da1d973d0a8044a680c97bc2a54995548.tar.bz2 opensim-SC-3a75a54da1d973d0a8044a680c97bc2a54995548.tar.xz |
- Fix Util.UnixTimeSinceEpoch:
* Unix epoch starts at midnight, not at 8:00am
* All date/time handling should be done in UTC in the server, not in
the local timezone.
* Refactor out repeated computation of a constant value
- Added setting of CreationTime to some places where inventoryitems
are created
This fixes Mantis#2390.
Diffstat (limited to 'OpenSim/Framework/Util.cs')
-rw-r--r-- | OpenSim/Framework/Util.cs | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/OpenSim/Framework/Util.cs b/OpenSim/Framework/Util.cs index 0f0aa47..c5334a8 100644 --- a/OpenSim/Framework/Util.cs +++ b/OpenSim/Framework/Util.cs | |||
@@ -27,6 +27,7 @@ | |||
27 | 27 | ||
28 | using System; | 28 | using System; |
29 | using System.Data; | 29 | using System.Data; |
30 | using System.Globalization; | ||
30 | using System.IO; | 31 | using System.IO; |
31 | using System.IO.Compression; | 32 | using System.IO.Compression; |
32 | using System.Net; | 33 | using System.Net; |
@@ -59,6 +60,10 @@ namespace OpenSim.Framework | |||
59 | private static string regexInvalidPathChars = "[" + new String(Path.GetInvalidPathChars()) + "]"; | 60 | private static string regexInvalidPathChars = "[" + new String(Path.GetInvalidPathChars()) + "]"; |
60 | private static object XferLock = new object(); | 61 | private static object XferLock = new object(); |
61 | 62 | ||
63 | // Unix-epoch starts at January 1st 1970, 00:00:00 UTC. And all our times in the server are (or at least should be) in UTC. | ||
64 | private static readonly DateTime unixEpoch = | ||
65 | DateTime.ParseExact("1970-01-01 00:00:00 +0", "yyyy-MM-dd hh:mm:ss z", DateTimeFormatInfo.InvariantInfo).ToUniversalTime(); | ||
66 | |||
62 | #region Vector Equations | 67 | #region Vector Equations |
63 | 68 | ||
64 | /// <summary> | 69 | /// <summary> |
@@ -290,19 +295,19 @@ namespace OpenSim.Framework | |||
290 | 295 | ||
291 | public static int ToUnixTime(DateTime stamp) | 296 | public static int ToUnixTime(DateTime stamp) |
292 | { | 297 | { |
293 | TimeSpan t = (stamp.ToUniversalTime() - Convert.ToDateTime("1/1/1970 8:00:00 AM")); | 298 | TimeSpan t = stamp.ToUniversalTime() - unixEpoch; |
294 | return (int) t.TotalSeconds; | 299 | return (int) t.TotalSeconds; |
295 | } | 300 | } |
296 | 301 | ||
297 | public static DateTime ToDateTime(ulong seconds) | 302 | public static DateTime ToDateTime(ulong seconds) |
298 | { | 303 | { |
299 | DateTime epoch = Convert.ToDateTime("1/1/1970 8:00:00 AM"); | 304 | DateTime epoch = unixEpoch; |
300 | return epoch.AddSeconds(seconds); | 305 | return epoch.AddSeconds(seconds); |
301 | } | 306 | } |
302 | 307 | ||
303 | public static DateTime ToDateTime(int seconds) | 308 | public static DateTime ToDateTime(int seconds) |
304 | { | 309 | { |
305 | DateTime epoch = Convert.ToDateTime("1/1/1970 8:00:00 AM"); | 310 | DateTime epoch = unixEpoch; |
306 | return epoch.AddSeconds(seconds); | 311 | return epoch.AddSeconds(seconds); |
307 | } | 312 | } |
308 | 313 | ||