Imported Upstream version 3.12.0

Former-commit-id: cf92446697332992ec36726e78eb8703e1f259d7
This commit is contained in:
Jo Shields
2015-01-13 10:44:36 +00:00
parent 8b9b85e7f5
commit 181b81b4a4
659 changed files with 12743 additions and 16300 deletions

View File

@@ -24,13 +24,16 @@
* 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))
#if INSIDE_CORLIB || (NET_3_5 && !NET_4_0 && !MOBILE)
using System.Runtime.CompilerServices;
using System.Runtime.Serialization;
namespace System
{
public sealed partial class TimeZoneInfo {
#if NET_4_0 || !INSIDE_CORLIB
public
#endif
sealed partial class TimeZoneInfo {
[SerializableAttribute]
#if MOBILE
[TypeForwardedFrom (Consts.AssemblySystem_Core)]

View File

@@ -453,29 +453,29 @@ namespace System {
: db.GetAvailableIds ();
}
static TimeZoneInfo _GetTimeZone (string name)
static TimeZoneInfo _GetTimeZone (string id, string name)
{
if (db == null)
return null;
byte[] buffer = db.GetTimeZoneData (name);
if (buffer == null)
return null;
return TimeZoneInfo.ParseTZBuffer (name, buffer, buffer.Length);
return TimeZoneInfo.ParseTZBuffer (id, buffer, buffer.Length);
}
internal static TimeZoneInfo GetTimeZone (string id)
internal static TimeZoneInfo GetTimeZone (string id, string name)
{
if (id != null) {
if (id == "GMT" || id == "UTC")
return new TimeZoneInfo (id, TimeSpan.FromSeconds (0), id, id, id, null, true);
if (id.StartsWith ("GMT"))
if (name != null) {
if (name == "GMT" || name == "UTC")
return new TimeZoneInfo (id, TimeSpan.FromSeconds (0), id, name, name, null, disableDaylightSavingTime:true);
if (name.StartsWith ("GMT"))
return new TimeZoneInfo (id,
TimeSpan.FromSeconds (ParseNumericZone (id)),
id, id, id, null, true);
TimeSpan.FromSeconds (ParseNumericZone (name)),
id, name, name, null, disableDaylightSavingTime:true);
}
try {
return _GetTimeZone (id);
return _GetTimeZone (id, name);
} catch (Exception) {
return null;
}
@@ -533,12 +533,13 @@ namespace System {
static readonly object _lock = new object ();
static TimeZoneInfo defaultZone;
internal static TimeZoneInfo Default {
internal static TimeZoneInfo Local {
get {
lock (_lock) {
if (defaultZone != null)
return defaultZone;
return defaultZone = GetTimeZone (GetDefaultTimeZoneName ());
var id = GetDefaultTimeZoneName ();
return defaultZone = GetTimeZone (id, id);
}
}
}
@@ -553,7 +554,10 @@ namespace System {
{
IntPtr value = IntPtr.Zero;
int n = 0;
string defaultTimeZone;
string defaultTimeZone = Environment.GetEnvironmentVariable ("__XA_OVERRIDE_TIMEZONE_ID__");
if (!string.IsNullOrEmpty (defaultTimeZone))
return defaultTimeZone;
// Used by the tests
if (Environment.GetEnvironmentVariable ("__XA_USE_JAVA_DEFAULT_TIMEZONE_ID__") == null)
@@ -576,16 +580,20 @@ namespace System {
#if SELF_TEST
/*
* Compile:
* mcs /out:tzi.exe /unsafe "/d:INSIDE_CORLIB;MONODROID;NET_4_0;LIBC;SELF_TEST" System/TimeZone*.cs ../../build/common/Consts.cs ../Mono.Options/Mono.Options/Options.cs
* mcs /debug+ /out:tzi.exe /unsafe "/d:INSIDE_CORLIB;MONODROID;NET_4_0;LIBC;SELF_TEST" ../corlib/System/AndroidPlatform.cs System/TimeZone*.cs ../../build/common/Consts.cs ../Mono.Options/Mono.Options/Options.cs
* Prep:
* mkdir -p usr/share/zoneinfo
* mkdir -p misc/zoneinfo/zoneinfo
* android_root=`adb shell echo '$ANDROID_ROOT' | tr -d "\r"`
* android_data=`adb shell echo '$ANDROID_DATA' | tr -d "\r"`
* adb pull $android_root/usr/share/zoneinfo usr/share/zoneinfo
* adb pull $android_data/misc/zoneinfo/tzdata misc/zoneinfo
* Run:
* ANDROID_ROOT=`pwd` mono tzi.exe
* __XA_OVERRIDE_TIMEZONE_ID__=America/New_York ANDROID_ROOT=`pwd` ANDROID_DATA=`pwd` mono --debug tzi.exe --offset=1969-01-01
*/
static void Main (string[] args)
{
DateTime? offset = null;
Func<IAndroidTimeZoneDB> c = () => GetDefaultTimeZoneDB ();
Mono.Options.OptionSet p = null;
p = new Mono.Options.OptionSet () {
@@ -595,6 +603,10 @@ namespace System {
{ "Z=", "Create ZoneInfoDB from {DIR}.", v => {
c = () => new ZoneInfoDB (v);
} },
{ "offset=", "Show timezone info offset for DateTime {OFFSET}.", v => {
offset = DateTime.Parse (v);
Console.WriteLine ("Using DateTime Offset: {0}", offset);
} },
{ "help", "Show this message and exit", v => {
p.WriteOptionDescriptions (Console.Out);
Environment.Exit (0);
@@ -606,9 +618,13 @@ namespace System {
foreach (var id in GetAvailableIds ()) {
Console.Write ("name={0,-40}", id);
try {
TimeZoneInfo zone = _GetTimeZone (id);
if (zone != null)
Console.Write (" {0}", zone);
TimeZoneInfo zone = _GetTimeZone (id, id);
if (zone != null) {
Console.Write (" {0,-40}", zone);
if (offset.HasValue) {
Console.Write ("From Offset: {0}", zone.GetUtcOffset (offset.Value));
}
}
else {
Console.Write (" ERROR:null");
}

View File

@@ -24,7 +24,7 @@
* 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))
#if INSIDE_CORLIB || (NET_3_5 && !NET_4_0 && !MOBILE)
using System.Collections.Generic;
using System.Globalization;
@@ -33,7 +33,10 @@ using System.Text;
namespace System
{
public partial class TimeZoneInfo
#if NET_4_0 || !INSIDE_CORLIB
public
#endif
partial class TimeZoneInfo
{
public static TimeZoneInfo FromSerializedString (string source)
{

View File

@@ -24,14 +24,17 @@
* 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))
#if INSIDE_CORLIB || (NET_3_5 && !NET_4_0 && !MOBILE)
using System.Runtime.CompilerServices;
using System.Runtime.Serialization;
namespace System
{
public sealed partial class TimeZoneInfo
#if NET_4_0 || !INSIDE_CORLIB
public
#endif
sealed partial class TimeZoneInfo
{
[SerializableAttribute]
#if MOBILE

View File

@@ -35,7 +35,7 @@ using System.Threading;
[assembly:TypeForwardedTo (typeof(TimeZoneInfo))]
#elif (INSIDE_CORLIB && NET_4_0) || (!INSIDE_CORLIB && (NET_3_5 && !NET_4_0 && !MOBILE))
#elif INSIDE_CORLIB || (NET_3_5 && !NET_4_0 && !MOBILE)
using System.Collections.Generic;
using System.Collections.ObjectModel;
@@ -57,7 +57,10 @@ namespace System
[TypeForwardedFrom (Consts.AssemblySystemCore_3_5)]
#endif
[SerializableAttribute]
public sealed partial class TimeZoneInfo : IEquatable<TimeZoneInfo>, ISerializable, IDeserializationCallback
#if NET_4_0 || !INSIDE_CORLIB
public
#endif
sealed partial class TimeZoneInfo : IEquatable<TimeZoneInfo>, ISerializable, IDeserializationCallback
{
TimeSpan baseUtcOffset;
public TimeSpan BaseUtcOffset {
@@ -100,15 +103,31 @@ namespace System
}
}
/*
TimeZone transitions are stored when there is a change on the base offset.
*/
private List<KeyValuePair<DateTime, TimeType>> transitions;
static TimeZoneInfo CreateLocal ()
{
#if MONODROID
return AndroidTimeZones.Default;
return AndroidTimeZones.Local;
#elif MONOTOUCH
using (Stream stream = GetMonoTouchData (null)) {
return BuildFromStream ("Local", stream);
}
#elif LIBC
var tz = Environment.GetEnvironmentVariable ("TZ");
if (tz != null) {
if (tz == String.Empty)
return Utc;
try {
return FindSystemTimeZoneByFileName (tz, Path.Combine (TimeZoneDirectory, tz));
} catch {
return Utc;
}
}
try {
return FindSystemTimeZoneByFileName ("Local", "/etc/localtime");
} catch {
@@ -332,8 +351,7 @@ namespace System
if (dateTime.Kind == DateTimeKind.Utc)
return dateTime;
//FIXME: do not rely on DateTime implementation !
return DateTime.SpecifyKind (dateTime.ToUniversalTime (), DateTimeKind.Utc);
return ConvertTimeToUtc (dateTime, TimeZoneInfo.Local);
}
public static DateTime ConvertTimeToUtc (DateTime dateTime, TimeZoneInfo sourceTimeZone)
@@ -350,15 +368,9 @@ namespace System
if (sourceTimeZone.IsInvalidTime (dateTime))
throw new ArgumentException ("dateTime parameter is an invalid time");
if (dateTime.Kind == DateTimeKind.Utc && sourceTimeZone == TimeZoneInfo.Utc)
return dateTime;
if (dateTime.Kind == DateTimeKind.Utc)
return dateTime;
if (dateTime.Kind == DateTimeKind.Local)
return ConvertTimeToUtc (dateTime);
if (sourceTimeZone.IsAmbiguousTime (dateTime) || !sourceTimeZone.IsDaylightSavingTime (dateTime))
return DateTime.SpecifyKind (dateTime - sourceTimeZone.BaseUtcOffset, DateTimeKind.Utc);
else {
@@ -414,12 +426,6 @@ namespace System
return FromRegistryKey(id, key);
}
#endif
#if MONODROID
var timeZoneInfo = AndroidTimeZones.GetTimeZone (id);
if (timeZoneInfo == null)
throw new TimeZoneNotFoundException ();
return timeZoneInfo;
#else
// Local requires special logic that already exists in the Local property (bug #326)
if (id == "Local")
return Local;
@@ -427,12 +433,16 @@ namespace System
using (Stream stream = GetMonoTouchData (id)) {
return BuildFromStream (id, stream);
}
#elif MONODROID
var timeZoneInfo = AndroidTimeZones.GetTimeZone (id, id);
if (timeZoneInfo == null)
throw new TimeZoneNotFoundException ();
return timeZoneInfo;
#elif LIBC
string filepath = Path.Combine (TimeZoneDirectory, id);
return FindSystemTimeZoneByFileName (id, filepath);
#else
throw new NotImplementedException ();
#endif
#endif
}
@@ -644,7 +654,7 @@ namespace System
#endif
#if MONODROID
foreach (string id in AndroidTimeZones.GetAvailableIds ()) {
var tz = AndroidTimeZones.GetTimeZone (id);
var tz = AndroidTimeZones.GetTimeZone (id, id);
if (tz != null)
systemTimeZones.Add (tz);
}
@@ -684,13 +694,8 @@ namespace System
public TimeSpan GetUtcOffset (DateTime dateTime)
{
if (IsDaylightSavingTime (dateTime)) {
AdjustmentRule rule = GetApplicableRule (dateTime);
if (rule != null)
return BaseUtcOffset + rule.DaylightDelta;
}
return BaseUtcOffset;
bool isDST;
return GetUtcOffset (dateTime, out isDST);
}
public TimeSpan GetUtcOffset (DateTimeOffset dateTimeOffset)
@@ -698,6 +703,82 @@ namespace System
throw new NotImplementedException ();
}
private TimeSpan GetUtcOffset (DateTime dateTime, out bool isDST)
{
isDST = false;
TimeZoneInfo tz = this;
if (dateTime.Kind == DateTimeKind.Utc)
tz = TimeZoneInfo.Utc;
if (dateTime.Kind == DateTimeKind.Local)
tz = TimeZoneInfo.Local;
bool isTzDst;
var tzOffset = GetUtcOffset (dateTime, tz, out isTzDst);
if (tz == this) {
isDST = isTzDst;
return tzOffset;
}
var utcTicks = dateTime.Ticks - tzOffset.Ticks;
if (utcTicks < 0 || utcTicks > DateTime.MaxValue.Ticks)
return BaseUtcOffset;
var utcDateTime = new DateTime (utcTicks, DateTimeKind.Utc);
return GetUtcOffset (utcDateTime, this, out isDST);
}
private static TimeSpan GetUtcOffset (DateTime dateTime, TimeZoneInfo tz, out bool isDST)
{
if (dateTime.Kind == DateTimeKind.Local && tz != TimeZoneInfo.Local)
throw new Exception ();
isDST = false;
if (tz == TimeZoneInfo.Utc)
return TimeSpan.Zero;
TimeSpan offset;
if (tz.TryGetTransitionOffset(dateTime, out offset, out isDST))
return offset;
if (dateTime.Kind == DateTimeKind.Utc) {
var utcRule = tz.GetApplicableRule (dateTime);
if (utcRule != null && tz.IsInDST (utcRule, dateTime)) {
isDST = true;
return tz.BaseUtcOffset + utcRule.DaylightDelta;
}
return tz.BaseUtcOffset;
}
var stdTicks = dateTime.Ticks - tz.BaseUtcOffset.Ticks;
if (stdTicks < 0 || stdTicks > DateTime.MaxValue.Ticks)
return tz.BaseUtcOffset;
var stdUtcDateTime = new DateTime (stdTicks, DateTimeKind.Utc);
var tzRule = tz.GetApplicableRule (stdUtcDateTime);
DateTime dstUtcDateTime = DateTime.MinValue;
if (tzRule != null) {
var dstTicks = stdUtcDateTime.Ticks - tzRule.DaylightDelta.Ticks;
if (dstTicks < 0 || dstTicks > DateTime.MaxValue.Ticks)
return tz.BaseUtcOffset;
dstUtcDateTime = new DateTime (dstTicks, DateTimeKind.Utc);
}
if (tzRule != null && tz.IsInDST (tzRule, stdUtcDateTime) && tz.IsInDST (tzRule, dstUtcDateTime)) {
isDST = true;
return tz.BaseUtcOffset + tzRule.DaylightDelta;
}
return tz.BaseUtcOffset;
}
public bool HasSameRules (TimeZoneInfo other)
{
if (other == null)
@@ -752,6 +833,16 @@ namespace System
throw new NotImplementedException ();
}
private bool IsInDST (AdjustmentRule rule, DateTime dateTime)
{
// Check whether we're in the dateTime year's DST period
if (IsInDSTForYear (rule, dateTime, dateTime.Year))
return true;
// We might be in the dateTime previous year's DST period
return IsInDSTForYear (rule, dateTime, dateTime.Year - 1);
}
bool IsInDSTForYear (AdjustmentRule rule, DateTime dateTime, int year)
{
DateTime DST_start = TransitionPoint (rule.DaylightTransitionStart, year);
@@ -774,25 +865,11 @@ namespace System
if (!SupportsDaylightSavingTime)
return false;
//FIXME: do not rely on DateTime implementation !
if ((dateTime.Kind == DateTimeKind.Local || dateTime.Kind == DateTimeKind.Unspecified) && this == TimeZoneInfo.Local)
return dateTime.IsDaylightSavingTime ();
//FIXME: do not rely on DateTime implementation !
if (dateTime.Kind == DateTimeKind.Local && this != TimeZoneInfo.Utc)
return IsDaylightSavingTime (DateTime.SpecifyKind (dateTime.ToUniversalTime (), DateTimeKind.Utc));
AdjustmentRule rule = GetApplicableRule (dateTime.Date);
if (rule == null)
return false;
// Check whether we're in the dateTime year's DST period
if (IsInDSTForYear (rule, dateTime, dateTime.Year))
return true;
bool isDst;
GetUtcOffset (dateTime, out isDst);
// We might be in the dateTime previous year's DST period
return IsInDSTForYear (rule, dateTime, dateTime.Year - 1);
return isDst;
}
public bool IsDaylightSavingTime (DateTimeOffset dateTimeOffset)
@@ -969,6 +1046,40 @@ namespace System
return null;
}
private bool TryGetTransitionOffset (DateTime dateTime, out TimeSpan offset,out bool isDst)
{
offset = BaseUtcOffset;
isDst = false;
if (transitions == null)
return false;
//Transitions are always in standard time
DateTime date = dateTime;
if (dateTime.Kind == DateTimeKind.Local && this != TimeZoneInfo.Local)
date = date.ToUniversalTime () + BaseUtcOffset;
if (dateTime.Kind == DateTimeKind.Utc && this != TimeZoneInfo.Utc)
date = date + BaseUtcOffset;
for (var i = transitions.Count - 1; i >= 0; i--) {
var pair = transitions [i];
DateTime ttime = pair.Key;
TimeType ttype = pair.Value;
if (ttime > date)
continue;
offset = new TimeSpan (0, 0, ttype.Offset);
isDst = ttype.IsDst;
return true;
}
return false;
}
private static DateTime TransitionPoint (TransitionTime transition, int year)
{
if (transition.IsFixedDateRule)
@@ -1059,6 +1170,7 @@ namespace System
bool dst_observed = false;
DateTime dst_start = DateTime.MinValue;
List<AdjustmentRule> adjustmentRules = new List<AdjustmentRule> ();
bool storeTransition = false;
for (int i = 0; i < transitions.Count; i++) {
var pair = transitions [i];
@@ -1069,6 +1181,8 @@ namespace System
standardDisplayName = ttype.Name;
daylightDisplayName = null;
baseUtcOffset = new TimeSpan (0, 0, ttype.Offset);
if (adjustmentRules.Count > 0) // We ignore AdjustmentRules but store transitions.
storeTransition = true;
adjustmentRules = new List<AdjustmentRule> ();
dst_observed = false;
}
@@ -1110,16 +1224,22 @@ namespace System
}
}
if (adjustmentRules.Count == 0) {
TimeZoneInfo tz;
if (adjustmentRules.Count == 0 && !storeTransition) {
TimeType t = (TimeType)time_types [0];
if (standardDisplayName == null) {
standardDisplayName = t.Name;
baseUtcOffset = new TimeSpan (0, 0, t.Offset);
}
return CreateCustomTimeZone (id, baseUtcOffset, id, standardDisplayName);
tz = CreateCustomTimeZone (id, baseUtcOffset, id, standardDisplayName);
} else {
return CreateCustomTimeZone (id, baseUtcOffset, id, standardDisplayName, daylightDisplayName, ValidateRules (adjustmentRules).ToArray ());
tz = CreateCustomTimeZone (id, baseUtcOffset, id, standardDisplayName, daylightDisplayName, ValidateRules (adjustmentRules).ToArray ());
}
if (storeTransition)
tz.transitions = transitions;
return tz;
}
static Dictionary<int, string> ParseAbbreviations (byte [] buffer, int index, int count)