Hello there,
I've got a problem using the UnixFileParser when the CultureInfo of the System is different to en-US.
The Name of the month in ParseExact throws an exception "unable to parse DateTime" as my System is running in CultureInfo "de-DE".
I had to add these line:
IFormatProvider culture = new CultureInfo("en-US", true);
My actual code looks now like:
// next 3 are the date time
int dateTimePos = index;
System.DateTime lastModified;
System.Text.StringBuilder stamp = new System.Text.StringBuilder(fields[index++]);
stamp.Append('-').Append(fields[index++]).Append('-');
string field = fields[index++];
// Force use of "en-US"
IFormatProvider culture = new CultureInfo("en-US", true);
if (field.IndexOf((System.Char) ':') < 0)
{
stamp.Append(field); // year
// Force use of "en-US"
lastModified = DateTime.ParseExact(stamp.ToString(), format1, culture, DateTimeStyles.None);
}
else
{
// add the year ourselves as not present
int year = CultureInfo.CurrentCulture.Calendar.GetYear(DateTime.Now);
stamp.Append(year).Append('-').Append(field);
// Force use of "en-US"
lastModified = DateTime.ParseExact(stamp.ToString(), format2, culture, DateTimeStyles.None);
// can't be in the future - must be the previous year
if (lastModified > DateTime.Now)
{
lastModified.AddYears(-1);
}
}
Now everything works fine for me.
Maybe there other users encounter similar problems.