Imported Upstream version 3.10.0

Former-commit-id: 172c8e3c300b39d5785c7a3e8dfb08ebdbc1a99b
This commit is contained in:
Jo Shields
2014-10-04 11:27:48 +01:00
parent fe777c5c82
commit 8b9b85e7f5
970 changed files with 20242 additions and 31308 deletions

View File

@@ -5,6 +5,7 @@ System/Funcs.cs
System/InvalidTimeZoneException.cs
System/TimeZoneInfo.AdjustmentRule.cs
System/TimeZoneInfo.cs
System/TimeZoneInfo.Serialization.cs
System/TimeZoneInfo.TransitionTime.cs
System/TimeZoneNotFoundException.cs
System.Runtime.CompilerServices/DynamicAttribute.cs

View File

@@ -1,5 +1,6 @@
System/TimeZoneInfoTest.cs
System/TimeZoneInfo.AdjustmentRuleTest.cs
System/TimeZoneInfo.SerializationTest.cs
System/TimeZoneInfo.TransitionTimeTest.cs
System.Collections.Generic/HashSetTest.cs
System.IO.MemoryMappedFiles/MemoryMappedFileTest.cs

View File

@@ -2265,11 +2265,9 @@ namespace System.Linq.Expressions {
internal static bool IsUnsigned (Type t)
{
#if !TARGET_JVM
if (t.IsPointer)
return IsUnsigned (t.GetElementType ());
#endif
return t == typeof (ushort) ||
t == typeof (uint) ||
t == typeof (ulong) ||

View File

@@ -230,18 +230,23 @@ namespace System.Linq.Parallel
var implementerToken = options.ImplementerToken;
try {
// Avoid cache thrashing of locals array
var local = locals [index];
if (seedFunc == null) {
if (!enumerator.MoveNext ())
return;
locals[index] = (U)(object)enumerator.Current;
local = (U)(object)enumerator.Current;
}
while (enumerator.MoveNext ()) {
if (implementerToken.IsCancellationRequested)
break;
token.ThrowIfCancellationRequested ();
locals[index] = localCall (locals[index], enumerator.Current);
local = localCall (local, enumerator.Current);
}
locals [index] = local;
} finally {
enumerator.Dispose ();
}

View File

@@ -64,12 +64,15 @@ namespace System {
[DllImport ("__Internal")]
extern static IntPtr monotouch_timezone_get_data (string name, ref int size);
static Stream GetMonoTouchData (string name)
static Stream GetMonoTouchData (string name, bool throw_on_error = true)
{
int size = 0;
IntPtr data = monotouch_timezone_get_data (name, ref size);
if (size <= 0)
throw new TimeZoneNotFoundException ();
if (size <= 0) {
if (throw_on_error)
throw new TimeZoneNotFoundException ();
return null;
}
unsafe {
var s = new UnmanagedMemoryStream ((byte*) data, size);

View File

@@ -0,0 +1,213 @@
/*
* System.TimeZoneInfo.Serialization
*
* Author(s)
* Sasha Kotlyar <sasha@arktronic.com>
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#if (INSIDE_CORLIB && NET_4_0) || (!INSIDE_CORLIB && (NET_3_5 && !NET_4_0 && !MOBILE))
using System.Collections.Generic;
using System.Globalization;
using System.Runtime.Serialization;
using System.Text;
namespace System
{
public partial class TimeZoneInfo
{
public static TimeZoneInfo FromSerializedString (string source)
{
var input = new StringBuilder (source);
var tzId = DeserializeString (ref input);
var offset = DeserializeInt (ref input);
var displayName = DeserializeString (ref input);
var standardName = DeserializeString (ref input);
var daylightName = DeserializeString (ref input);
var rules = new List<TimeZoneInfo.AdjustmentRule> ();
while (input [0] != ';') {
rules.Add (DeserializeAdjustmentRule (ref input));
}
var offsetSpan = TimeSpan.FromMinutes (offset);
return TimeZoneInfo.CreateCustomTimeZone (tzId, offsetSpan, displayName, standardName, daylightName, rules.ToArray ());
}
public string ToSerializedString ()
{
var stb = new StringBuilder ();
var daylightName = (string.IsNullOrEmpty(this.DaylightName) ? this.StandardName : this.DaylightName);
stb.AppendFormat ("{0};{1};{2};{3};{4};", EscapeForSerialization (this.Id), (int)this.BaseUtcOffset.TotalMinutes,
EscapeForSerialization (this.DisplayName), EscapeForSerialization (this.StandardName), EscapeForSerialization (daylightName));
if (this.SupportsDaylightSavingTime) {
foreach (var rule in this.GetAdjustmentRules()) {
var start = rule.DateStart.ToString ("MM:dd:yyyy", CultureInfo.InvariantCulture);
var end = rule.DateEnd.ToString ("MM:dd:yyyy", CultureInfo.InvariantCulture);
var delta = (int)rule.DaylightDelta.TotalMinutes;
var transitionStart = SerializeTransitionTime (rule.DaylightTransitionStart);
var transitionEnd = SerializeTransitionTime (rule.DaylightTransitionEnd);
stb.AppendFormat ("[{0};{1};{2};{3};{4};]", start, end, delta,
transitionStart, transitionEnd);
}
}
stb.Append (";");
return stb.ToString ();
}
private static TimeZoneInfo.AdjustmentRule DeserializeAdjustmentRule (ref StringBuilder input)
{
// Similar to: [01:01:0001;12:31:9999;60;[0;01:00:00;3;5;0;];[0;02:00:00;10;5;0;];]
if (input [0] != '[')
throw new SerializationException ();
input.Remove (0, 1); // [
var dateStart = DeserializeDate (ref input);
var dateEnd = DeserializeDate (ref input);
var delta = DeserializeInt (ref input);
var transitionStart = DeserializeTransitionTime (ref input);
var transitionEnd = DeserializeTransitionTime (ref input);
input.Remove (0, 1); // ]
var deltaSpan = TimeSpan.FromMinutes (delta);
return TimeZoneInfo.AdjustmentRule.CreateAdjustmentRule (dateStart, dateEnd, deltaSpan,
transitionStart, transitionEnd);
}
private static TimeZoneInfo.TransitionTime DeserializeTransitionTime (ref StringBuilder input)
{
if (input [0] != '[' || (input [1] != '0' && input [1] != '1') || input [2] != ';')
throw new SerializationException ();
var rule = input [1];
input.Remove (0, 3); // [#;
var timeOfDay = DeserializeTime (ref input);
var month = DeserializeInt (ref input);
if (rule == '0') {
// Floating rule such as: [0;01:00:00;3;5;0;];
var week = DeserializeInt (ref input);
var dayOfWeek = DeserializeInt (ref input);
input.Remove (0, 2); // ];
return TimeZoneInfo.TransitionTime.CreateFloatingDateRule (timeOfDay, month, week, (DayOfWeek)dayOfWeek);
}
// Fixed rule such as: [1;02:15:59.999;6;2;];
var day = DeserializeInt (ref input);
input.Remove (0, 2); // ];
return TimeZoneInfo.TransitionTime.CreateFixedDateRule (timeOfDay, month, day);
}
private static string DeserializeString (ref StringBuilder input)
{
var stb = new StringBuilder ();
var isEscaped = false;
int charCount;
for (charCount = 0; charCount < input.Length; charCount++) {
var inChar = input [charCount];
if (isEscaped) {
isEscaped = false;
stb.Append (inChar);
} else if (inChar == '\\') {
isEscaped = true;
continue;
} else if (inChar == ';') {
break;
} else {
stb.Append (inChar);
}
}
input.Remove (0, charCount + 1);
return stb.ToString ();
}
private static int DeserializeInt(ref StringBuilder input)
{
int charCount = 0;
while(charCount++ < input.Length)
{
if (input[charCount] == ';')
break;
}
int result;
if(!int.TryParse(input.ToString(0, charCount), NumberStyles.Integer, CultureInfo.InvariantCulture, out result))
throw new SerializationException();
input.Remove(0, charCount + 1);
return result;
}
private static DateTime DeserializeDate (ref StringBuilder input)
{
var inChars = new char[11];
input.CopyTo (0, inChars, 0, inChars.Length);
DateTime result;
if (!DateTime.TryParseExact (new string (inChars), "MM:dd:yyyy;", CultureInfo.InvariantCulture, DateTimeStyles.None, out result))
throw new SerializationException ();
input.Remove (0, inChars.Length);
return result;
}
private static DateTime DeserializeTime (ref StringBuilder input)
{
if (input [8] == ';') {
// Without milliseconds
var inChars = new char[9];
input.CopyTo (0, inChars, 0, inChars.Length);
DateTime result;
if (!DateTime.TryParseExact (new string (inChars), "HH:mm:ss;", CultureInfo.InvariantCulture, DateTimeStyles.NoCurrentDateDefault, out result))
throw new SerializationException ();
input.Remove (0, inChars.Length);
return result;
} else if (input [12] == ';') {
// With milliseconds
char[] inChars = new char[13];
input.CopyTo (0, inChars, 0, inChars.Length);
var inString = new string (inChars);
DateTime result;
if (!DateTime.TryParseExact (inString, "HH:mm:ss.fff;", CultureInfo.InvariantCulture, DateTimeStyles.NoCurrentDateDefault, out result))
throw new SerializationException ();
input.Remove (0, inChars.Length);
return result;
}
throw new SerializationException ();
}
private static string EscapeForSerialization (string unescaped)
{
return unescaped.Replace (@"\", @"\\").Replace (";", "\\;");
}
private static string SerializeTransitionTime (TimeZoneInfo.TransitionTime transition)
{
string timeOfDay;
if (transition.TimeOfDay.Millisecond > 0)
timeOfDay = transition.TimeOfDay.ToString ("HH:mm:ss.fff");
else
timeOfDay = transition.TimeOfDay.ToString ("HH:mm:ss");
if (transition.IsFixedDateRule) {
return string.Format ("[1;{0};{1};{2};]", timeOfDay, transition.Month, transition.Day);
}
return string.Format ("[0;{0};{1};{2};{3};]", timeOfDay, transition.Month,
transition.Week, (int)transition.DayOfWeek);
}
}
}
#endif

View File

@@ -572,11 +572,6 @@ namespace System
}
#endif
public static TimeZoneInfo FromSerializedString (string source)
{
throw new NotImplementedException ();
}
public AdjustmentRule [] GetAdjustmentRules ()
{
if (!supportsDaylightSavingTime)
@@ -656,7 +651,9 @@ namespace System
#elif MONOTOUCH
if (systemTimeZones.Count == 0) {
foreach (string name in GetMonoTouchNames ()) {
using (Stream stream = GetMonoTouchData (name)) {
using (Stream stream = GetMonoTouchData (name, false)) {
if (stream == null)
continue;
systemTimeZones.Add (BuildFromStream (name, stream));
}
}
@@ -876,11 +873,6 @@ namespace System
}
}
public string ToSerializedString ()
{
throw new NotImplementedException ();
}
public override string ToString ()
{
return DisplayName;
@@ -986,6 +978,8 @@ namespace System
int day = 1 + (transition.Week - 1) * 7 + (transition.DayOfWeek - first) % 7;
if (day > DateTime.DaysInMonth (year, transition.Month))
day -= 7;
if (day < 1)
day += 7;
return new DateTime (year, transition.Month, day) + transition.TimeOfDay.TimeOfDay;
}

View File

@@ -96,7 +96,6 @@ namespace MonoTests.System.Collections.Generic {
}
[Test]
[Category("TargetJvmNotWorking")]
public void TestCopyTo ()
{
var data = new [] {1, 2, 3, 4, 5};

View File

@@ -192,7 +192,6 @@ namespace MonoTests.System.Linq.Expressions {
}
[Test]
[Category("TargetJvmNotSupported")]
public void ExpressionDelegateTarget ()
{
var p = Expression.Parameter (typeof (string), "str");
@@ -220,7 +219,6 @@ namespace MonoTests.System.Linq.Expressions {
#if !NET_4_0
[Test]
[Category ("TargetJvmNotSupported")]
public void GlobalsInScope ()
{
var foo = new Foo { gazonk = "gazonk" };

View File

@@ -0,0 +1,97 @@
using System;
using System.IO;
using NUnit.Framework;
namespace MonoTests.System
{
[TestFixture]
public class SerializedStringTests
{
[Test]
public void SerializeUtc ()
{
Assert.AreEqual ("UTC;0;UTC;UTC;UTC;;", TimeZoneInfo.Utc.ToSerializedString ());
}
[Test]
public void DeserializeUtc ()
{
var utc = TimeZoneInfo.FromSerializedString ("UTC;0;UTC;UTC;UTC;;");
Assert.AreEqual ("UTC", utc.Id);
Assert.AreEqual ("UTC", utc.DisplayName);
Assert.AreEqual ("UTC", utc.StandardName);
Assert.IsFalse (utc.SupportsDaylightSavingTime);
Assert.AreEqual (0, utc.GetAdjustmentRules ().Length);
}
[Test]
public void SerializeCustomUtcZoneWithOddNaming ()
{
var tz1 = TimeZoneInfo.CreateCustomTimeZone (@"My\; Zone, @1!.", TimeSpan.FromMinutes (0), @"My\\; Zone 1 Name", "My; Zone 1 Standard Time");
Assert.AreEqual (@"My\\\; Zone, @1!.;0;My\\\\\; Zone 1 Name;My\; Zone 1 Standard Time;My\; Zone 1 Standard Time;;", tz1.ToSerializedString ());
}
[Test]
public void SerializeCustomZoneWithOddOffset ()
{
var tz2 = TimeZoneInfo.CreateCustomTimeZone ("My Zone 2", TimeSpan.FromHours (1.25), "My Zone 2 Name", "My Zone 2 Standard Time");
Assert.AreEqual ("My Zone 2;75;My Zone 2 Name;My Zone 2 Standard Time;My Zone 2 Standard Time;;", tz2.ToSerializedString ());
}
[Test]
public void SerializeCustomZoneWithFloatingDaylightTransitions ()
{
var tz3rules = new TimeZoneInfo.AdjustmentRule[] { TimeZoneInfo.AdjustmentRule.CreateAdjustmentRule (new DateTime (1, 1, 1), new DateTime (9999, 12, 31), TimeSpan.FromMinutes (23), TimeZoneInfo.TransitionTime.CreateFloatingDateRule (new DateTime (1, 1, 1, 2, 15, 58, 0), 3, 2, DayOfWeek.Tuesday), TimeZoneInfo.TransitionTime.CreateFloatingDateRule (new DateTime (1, 1, 1, 2, 15, 59, 999), 6, 2, DayOfWeek.Tuesday)) };
var tz3 = TimeZoneInfo.CreateCustomTimeZone ("My Zone 3", TimeSpan.FromHours (-4), "My Zone 3 Name", "My Zone 3 Standard Time", "My Zone 3 Daylight Time", tz3rules);
Assert.AreEqual ("My Zone 3;-240;My Zone 3 Name;My Zone 3 Standard Time;My Zone 3 Daylight Time;[01:01:0001;12:31:9999;23;[0;02:15:58;3;2;2;];[0;02:15:59.999;6;2;2;];];", tz3.ToSerializedString ());
}
[Test]
public void SerializeCustomZoneWithFixedDaylightTransitions ()
{
var tz4rules = new TimeZoneInfo.AdjustmentRule[] { TimeZoneInfo.AdjustmentRule.CreateAdjustmentRule (new DateTime (1, 1, 1), new DateTime (9999, 12, 31), TimeSpan.FromMinutes (23), TimeZoneInfo.TransitionTime.CreateFixedDateRule (new DateTime (1, 1, 1, 2, 15, 59, 48), 3, 2), TimeZoneInfo.TransitionTime.CreateFixedDateRule (new DateTime (1, 1, 1, 2, 15, 59, 999), 6, 2)) };
var tz4 = TimeZoneInfo.CreateCustomTimeZone ("My Zone 4", TimeSpan.FromHours (-4), "My Zone 4 Name", "My Zone 4 Standard Time", "My Zone 4 Daylight Time", tz4rules);
Assert.AreEqual ("My Zone 4;-240;My Zone 4 Name;My Zone 4 Standard Time;My Zone 4 Daylight Time;[01:01:0001;12:31:9999;23;[1;02:15:59.048;3;2;];[1;02:15:59.999;6;2;];];", tz4.ToSerializedString ());
}
[Test]
public void SerializeCustomZoneWithMultipleDaylightRules ()
{
var tz5rules = new TimeZoneInfo.AdjustmentRule[] {
TimeZoneInfo.AdjustmentRule.CreateAdjustmentRule (new DateTime (1, 1, 1), new DateTime (2012, 12, 31), TimeSpan.FromMinutes (23), TimeZoneInfo.TransitionTime.CreateFloatingDateRule (new DateTime (1, 1, 1, 2, 15, 59, 999), 3, 2, DayOfWeek.Tuesday), TimeZoneInfo.TransitionTime.CreateFloatingDateRule (new DateTime (1, 1, 1, 2, 15, 59, 999), 6, 2, DayOfWeek.Tuesday)),
TimeZoneInfo.AdjustmentRule.CreateAdjustmentRule (new DateTime (2013, 1, 1), new DateTime (9999, 12, 31), TimeSpan.FromMinutes (48), TimeZoneInfo.TransitionTime.CreateFloatingDateRule (new DateTime (1, 1, 1, 2, 15, 59, 999), 3, 2, DayOfWeek.Tuesday), TimeZoneInfo.TransitionTime.CreateFloatingDateRule (new DateTime (1, 1, 1, 2, 15, 59, 999), 6, 2, DayOfWeek.Tuesday))
};
var tz5 = TimeZoneInfo.CreateCustomTimeZone ("My Zone 5", TimeSpan.FromHours (-6.75), "My Zone 5 Name", "My Zone 5 Standard Time", "My Zone 5 Daylight Time", tz5rules);
Assert.AreEqual ("My Zone 5;-405;My Zone 5 Name;My Zone 5 Standard Time;My Zone 5 Daylight Time;[01:01:0001;12:31:2012;23;[0;02:15:59.999;3;2;2;];[0;02:15:59.999;6;2;2;];][01:01:2013;12:31:9999;48;[0;02:15:59.999;3;2;2;];[0;02:15:59.999;6;2;2;];];", tz5.ToSerializedString ());
}
[Test]
public void DeserializeCustomZoneWithOddNamingAndMultipleDaylightRules ()
{
var rule1 = TimeZoneInfo.AdjustmentRule.CreateAdjustmentRule (new DateTime (1, 1, 1), new DateTime (2012, 12, 31), TimeSpan.FromMinutes (23), TimeZoneInfo.TransitionTime.CreateFloatingDateRule (new DateTime (1, 1, 1, 2, 15, 59, 999), 3, 2, DayOfWeek.Tuesday), TimeZoneInfo.TransitionTime.CreateFloatingDateRule (new DateTime (1, 1, 1, 2, 15, 59, 999), 6, 2, DayOfWeek.Tuesday));
var rule2 = TimeZoneInfo.AdjustmentRule.CreateAdjustmentRule (new DateTime (2013, 1, 1), new DateTime (9999, 12, 31), TimeSpan.FromMinutes (48), TimeZoneInfo.TransitionTime.CreateFloatingDateRule (new DateTime (1, 1, 1, 2, 15, 59, 999), 3, 2, DayOfWeek.Tuesday), TimeZoneInfo.TransitionTime.CreateFloatingDateRule (new DateTime (1, 1, 1, 2, 15, 59, 999), 6, 2, DayOfWeek.Tuesday));
var tz1 = TimeZoneInfo.FromSerializedString ("My\\; Zone 5;-405;My Zone\\; 5 Name;My Zone 5\\; Standard Time;My Zone 5 Daylight\\; Time;[01:01:0001;12:31:2012;23;[0;02:15:59.999;3;2;2;];[0;02:15:59.999;6;2;2;];][01:01:2013;12:31:9999;48;[0;02:15:59.999;3;2;2;];[0;02:15:59.999;6;2;2;];];");
Assert.AreEqual ("My; Zone 5", tz1.Id);
Assert.AreEqual ("My Zone; 5 Name", tz1.DisplayName);
Assert.AreEqual ("My Zone 5; Standard Time", tz1.StandardName);
Assert.AreEqual ("My Zone 5 Daylight; Time", tz1.DaylightName);
Assert.AreEqual (TimeSpan.FromMinutes (-405), tz1.BaseUtcOffset);
Assert.IsTrue (tz1.SupportsDaylightSavingTime);
var deserializedRules = tz1.GetAdjustmentRules ();
Assert.AreEqual (2, deserializedRules.Length);
Assert.IsFalse (deserializedRules [0].Equals (deserializedRules [1]));
Assert.IsTrue (rule1.Equals (deserializedRules [0]));
Assert.IsTrue (rule2.Equals (deserializedRules [1]));
}
[Test]
public void DeserializeAndUseEasternTimeZone ()
{
var et = TimeZoneInfo.FromSerializedString (@"Eastern Standard Time;-300;(UTC-05:00) Eastern Time (US & Canada);Eastern Standard Time;Eastern Daylight Time;[01:01:0001;12:31:2006;60;[0;02:00:00;4;1;0;];[0;02:00:00;10;5;0;];][01:01:2007;12:31:9999;60;[0;02:00:00;3;2;0;];[0;02:00:00;11;1;0;];];");
var testDate = new DateTime (2014, 8, 1, 6, 0, 0, DateTimeKind.Unspecified);
Assert.AreEqual (TimeSpan.FromHours (-4), et.GetUtcOffset (testDate));
}
}
}

View File

@@ -4,6 +4,7 @@ System/Funcs.cs
System/InvalidTimeZoneException.cs
System/TimeZoneInfo.AdjustmentRule.cs
System/TimeZoneInfo.cs
System/TimeZoneInfo.Serialization.cs
System/TimeZoneInfo.TransitionTime.cs
System/TimeZoneNotFoundException.cs
System/Util.cs

View File

@@ -5,6 +5,7 @@ System/Funcs.cs
System/InvalidTimeZoneException.cs
System/TimeZoneInfo.AdjustmentRule.cs
System/TimeZoneInfo.cs
System/TimeZoneInfo.Serialization.cs
System/TimeZoneInfo.TransitionTime.cs
System/TimeZoneNotFoundException.cs
System/Util.cs