Imported Upstream version 4.6.0.125

Former-commit-id: a2155e9bd80020e49e72e86c44da02a8ac0e57a4
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2016-08-03 10:59:49 +00:00
parent a569aebcfd
commit e79aa3c0ed
17047 changed files with 3137615 additions and 392334 deletions

View File

@@ -90,14 +90,14 @@ namespace System
*/
private List<KeyValuePair<DateTime, TimeType>> transitions;
private static bool libcNotFound;
private static bool readlinkNotFound;
[DllImport ("libc")]
private static extern int readlink (string path, byte[] buffer, int buflen);
private static string readlink (string path)
{
if (libcNotFound)
if (readlinkNotFound)
return null;
byte[] buf = new byte [512];
@@ -106,7 +106,10 @@ namespace System
try {
ret = readlink (path, buf, buf.Length);
} catch (DllNotFoundException e) {
libcNotFound = true;
readlinkNotFound = true;
return null;
} catch (EntryPointNotFoundException e) {
readlinkNotFound = true;
return null;
}
@@ -120,8 +123,12 @@ namespace System
{
name = null;
var linkPath = readlink (path);
if (linkPath != null)
path = linkPath;
if (linkPath != null) {
if (Path.IsPathRooted(linkPath))
path = linkPath;
else
path = Path.Combine(Path.GetDirectoryName(path), linkPath);
}
path = Path.GetFullPath (path);
@@ -730,7 +737,8 @@ namespace System
public TimeSpan GetUtcOffset (DateTimeOffset dateTimeOffset)
{
throw new NotImplementedException ();
bool isDST;
return GetUtcOffset (dateTimeOffset.UtcDateTime, out isDST);
}
private TimeSpan GetUtcOffset (DateTime dateTime, out bool isDST)
@@ -865,7 +873,7 @@ namespace System
return true;
// We might be in the dateTime previous year's DST period
return IsInDSTForYear (rule, dateTime, dateTime.Year - 1);
return dateTime.Year > 1 && IsInDSTForYear (rule, dateTime, dateTime.Year - 1);
}
bool IsInDSTForYear (AdjustmentRule rule, DateTime dateTime, int year)
@@ -1213,8 +1221,10 @@ namespace System
try {
return ParseTZBuffer (id, buffer, length);
} catch (InvalidTimeZoneException) {
throw;
} catch (Exception e) {
throw new InvalidTimeZoneException (e.Message);
throw new InvalidTimeZoneException ("Time zone information file contains invalid data", e);
}
}
@@ -1271,7 +1281,7 @@ namespace System
if (time_types.Count == 0)
throw new InvalidTimeZoneException ();
if (time_types.Count == 1 && ((TimeType)time_types[0]).IsDst)
if (time_types.Count == 1 && time_types[0].IsDst)
throw new InvalidTimeZoneException ();
TimeSpan baseUtcOffset = new TimeSpan (0);
@@ -1352,8 +1362,8 @@ namespace System
TimeZoneInfo tz;
if (adjustmentRules.Count == 0 && !storeTransition) {
TimeType t = (TimeType)time_types [0];
if (standardDisplayName == null) {
var t = time_types [0];
standardDisplayName = t.Name;
baseUtcOffset = new TimeSpan (0, 0, t.Offset);
}
@@ -1397,6 +1407,20 @@ namespace System
var types = new Dictionary<int, TimeType> (count);
for (int i = 0; i < count; i++) {
int offset = ReadBigEndianInt32 (buffer, index + 6 * i);
//
// The official tz database contains timezone with GMT offsets
// not only in whole hours/minutes but in seconds. This happens for years
// before 1901. For example
//
// NAME GMTOFF RULES FORMAT UNTIL
// Europe/Madrid -0:14:44 - LMT 1901 Jan 1 0:00s
//
// .NET as of 4.6.2 cannot handle that and uses hours/minutes only, so
// we remove seconds to not crash later
//
offset = (offset / 60) * 60;
byte is_dst = buffer [index + 6 * i + 4];
byte abbrev = buffer [index + 6 * i + 5];
types.Add (i, new TimeType (offset, (is_dst != 0), abbreviations [(int)abbrev]));
@@ -1452,7 +1476,7 @@ namespace System
#endregion
}
struct TimeType {
class TimeType {
public readonly int Offset;
public readonly bool IsDst;
public string Name;