// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
-using System.Collections;
+using System.Collections.Generic;
using System.Globalization;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// memory usage from 16 to 8 bytes, see bug: 592221. This also fixes the
// 622127 issue and simplifies the code in reflection.c to encode DateTimes
//
- public long encoded;
+ long encoded;
const long TicksMask = 0x3fffffffffffffff;
const long KindMask = unchecked ((long) 0xc000000000000000);
const int KindShift = 62;
"d/yy/MMM",
"yy/d/MMM",
};
+
+ private static readonly string[] ParseGenericYearMonthDayFormats = new string [] {
+ "yyyy/M/dT",
+ "yyyy/M/d",
+ "M/yyyy/dT",
+ "M/yyyy/d",
+ "yyyy'\u5E74'M'\u6708'd'\u65E5",
+ "yyyy'-'M'-'dT",
+ "yyyy'-'M'-'d",
+ };
// Patterns influenced by the MonthDayPattern in DateTimeFormatInfo.
// Note that these patterns cannot be followed by the time.
public static DateTime FromBinary (long dateData)
{
- switch ((ulong)dateData >> 62) {
+ switch ((ulong)dateData >> KindShift) {
case 1: // Utc
return new DateTime (dateData & TicksMask, DateTimeKind.Utc);
case 0: // Unspecified
if (fileTime < 0)
throw new ArgumentOutOfRangeException ("fileTime", "< 0");
- return new DateTime (w32file_epoch + fileTime);
+ return new DateTime (w32file_epoch + fileTime, DateTimeKind.Utc);
}
public static DateTime FromOADate (double d)
{
DateTimeFormatInfo info = (DateTimeFormatInfo) provider.GetFormat (typeof(DateTimeFormatInfo));
// return GetDateTimeFormats (info.GetAllDateTimePatterns ());
- ArrayList al = new ArrayList ();
+ var l = new List<string> ();
foreach (char c in "dDgGfFmMrRstTuUyY")
- al.AddRange (GetDateTimeFormats (c, info));
- return al.ToArray (typeof (string)) as string [];
+ l.AddRange (GetDateTimeFormats (c, info));
+ return l.ToArray ();
}
public string[] GetDateTimeFormats(char format,IFormatProvider provider )
DateTimeFormatInfo dfi = DateTimeFormatInfo.GetInstance (provider);
// Try first all the combinations of ParseAllDateFormats & ParseTimeFormats
- string[] allDateFormats = YearMonthDayFormats (dfi, setExceptionOnError, ref exception);
+ string[] allDateFormats = YearMonthDayFormats (dfi);
if (allDateFormats == null){
result = MinValue;
return false;
return ParseExact (s, format, provider, DateTimeStyles.None);
}
- private static string[] YearMonthDayFormats (DateTimeFormatInfo dfi, bool setExceptionOnError, ref Exception exc)
+ private static string[] YearMonthDayFormats (DateTimeFormatInfo dfi)
{
int dayIndex = dfi.ShortDatePattern.IndexOf('d');
int monthIndex = dfi.ShortDatePattern.IndexOf('M');
int yearIndex = dfi.ShortDatePattern.IndexOf('y');
- if (dayIndex == -1 || monthIndex == -1 || yearIndex == -1){
- if (setExceptionOnError)
- exc = new FormatException (Locale.GetText("Order of year, month and date is not defined by {0}", dfi.ShortDatePattern));
- return null;
- }
+ if (dayIndex == -1 || monthIndex == -1 || yearIndex == -1)
+ return ParseGenericYearMonthDayFormats;
if (yearIndex < monthIndex)
if (monthIndex < dayIndex)
return ParseYearDayMonthFormats;
else {
// The year cannot be between the date and the month
- if (setExceptionOnError)
- exc = new FormatException (Locale.GetText("Order of date, year and month defined by {0} is not supported", dfi.ShortDatePattern));
- return null;
+ return ParseGenericYearMonthDayFormats;
}
else if (dayIndex < monthIndex)
return ParseDayMonthYearFormats;
return ParseMonthDayYearFormats;
else {
// The year cannot be between the month and the date
- if (setExceptionOnError)
- exc = new FormatException (Locale.GetText("Order of month, year and date defined by {0} is not supported", dfi.ShortDatePattern));
- return null;
+ return ParseGenericYearMonthDayFormats;
}
}