From 3a75a54da1d973d0a8044a680c97bc2a54995548 Mon Sep 17 00:00:00 2001 From: Homer Horwitz Date: Sat, 18 Oct 2008 15:26:41 +0000 Subject: [PATCH] - 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. --- OpenSim/Framework/Communications/Capabilities/Caps.cs | 1 + OpenSim/Framework/Util.cs | 11 ++++++++--- .../Agent/AssetTransaction/AssetXferUploader.cs | 3 ++- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/OpenSim/Framework/Communications/Capabilities/Caps.cs b/OpenSim/Framework/Communications/Capabilities/Caps.cs index fd43e89d4b..28e56dada8 100644 --- a/OpenSim/Framework/Communications/Capabilities/Caps.cs +++ b/OpenSim/Framework/Communications/Capabilities/Caps.cs @@ -754,6 +754,7 @@ namespace OpenSim.Framework.Communications.Capabilities item.BasePermissions = 2147483647; item.EveryOnePermissions = 0; item.NextPermissions = 2147483647; + item.CreationDate = Util.UnixTimeSinceEpoch(); if (AddNewInventoryItem != null) { diff --git a/OpenSim/Framework/Util.cs b/OpenSim/Framework/Util.cs index 0f0aa47f4b..c5334a88a4 100644 --- a/OpenSim/Framework/Util.cs +++ b/OpenSim/Framework/Util.cs @@ -27,6 +27,7 @@ using System; using System.Data; +using System.Globalization; using System.IO; using System.IO.Compression; using System.Net; @@ -59,6 +60,10 @@ namespace OpenSim.Framework private static string regexInvalidPathChars = "[" + new String(Path.GetInvalidPathChars()) + "]"; private static object XferLock = new object(); + // 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. + private static readonly DateTime unixEpoch = + DateTime.ParseExact("1970-01-01 00:00:00 +0", "yyyy-MM-dd hh:mm:ss z", DateTimeFormatInfo.InvariantInfo).ToUniversalTime(); + #region Vector Equations /// @@ -290,19 +295,19 @@ namespace OpenSim.Framework public static int ToUnixTime(DateTime stamp) { - TimeSpan t = (stamp.ToUniversalTime() - Convert.ToDateTime("1/1/1970 8:00:00 AM")); + TimeSpan t = stamp.ToUniversalTime() - unixEpoch; return (int) t.TotalSeconds; } public static DateTime ToDateTime(ulong seconds) { - DateTime epoch = Convert.ToDateTime("1/1/1970 8:00:00 AM"); + DateTime epoch = unixEpoch; return epoch.AddSeconds(seconds); } public static DateTime ToDateTime(int seconds) { - DateTime epoch = Convert.ToDateTime("1/1/1970 8:00:00 AM"); + DateTime epoch = unixEpoch; return epoch.AddSeconds(seconds); } diff --git a/OpenSim/Region/Environment/Modules/Agent/AssetTransaction/AssetXferUploader.cs b/OpenSim/Region/Environment/Modules/Agent/AssetTransaction/AssetXferUploader.cs index 2763831446..2bac3c7e57 100644 --- a/OpenSim/Region/Environment/Modules/Agent/AssetTransaction/AssetXferUploader.cs +++ b/OpenSim/Region/Environment/Modules/Agent/AssetTransaction/AssetXferUploader.cs @@ -278,7 +278,7 @@ namespace OpenSim.Region.Environment.Modules.Agent.AssetTransaction CachedUserInfo userInfo = m_userTransactions.Manager.MyScene.CommsManager.UserProfileCacheService.GetUserDetails( ourClient.AgentId); - + if (userInfo != null) { InventoryItemBase item = new InventoryItemBase(); @@ -296,6 +296,7 @@ namespace OpenSim.Region.Environment.Modules.Agent.AssetTransaction item.EveryOnePermissions=0; item.NextPermissions = nextPerm; item.Flags = (uint) wearableType; + item.CreationDate = Util.UnixTimeSinceEpoch(); userInfo.AddItem(item); ourClient.SendInventoryItemCreateUpdate(item);