Simplify NSDate.ParseDateString.

This commit is contained in:
Matthias Reitinger
2019-10-15 08:51:34 +02:00
parent 2566d63668
commit 2e80020d00

View File

@@ -42,6 +42,7 @@ namespace Claunia.PropertyList
// understands the 'Z' character as a timezone, specify the 'K' format string.
static readonly string sdfDefault = "yyyy-MM-dd'T'HH:mm:ssK";
static readonly string sdfGnuStep = "yyyy-MM-dd HH:mm:ss zzz";
static readonly string[] sdfAll = { sdfDefault, sdfGnuStep };
static readonly CultureInfo provider = CultureInfo.InvariantCulture;
@@ -89,8 +90,7 @@ namespace Claunia.PropertyList
/// <exception cref="FormatException">Given string cannot be parsed</exception>
static DateTime ParseDateString(string textRepresentation)
{
try { return DateTime.ParseExact(textRepresentation, sdfDefault, provider); }
catch(FormatException) { return DateTime.ParseExact(textRepresentation, sdfGnuStep, provider); }
return DateTime.ParseExact(textRepresentation, sdfAll, provider, DateTimeStyles.None);
}
/// <summary>