XMP InvariantCulture or CurrentCulture

Well it wasn’t to be all smooth sailing in my XMP adventure. It turns out dates will always be a problem in life. The BitmapMetadata class has a property DateTaken that is a string! When I copied the date from the backup file to the current file it was swapping the days and months around? Whats wrong with this i thought?

destMetadata.DateTaken = sourceMetadata.DateTaken;

Download trusty Reflector to the travel laptop and voila! It turns out the property getter uses DateTime.FromFiletime to get the string. It appears this uses the Current Culture to format the date. The setter parses the passed in value using Convert.ToDateTime(value, CultureInfo.InvariantCulture); I maybe missing something and I am sure it is by design, but surely they could have used a consistent culture to save me from this? Especially on my honeymoon! 🙂

DateTime fromDate = Convert.ToDateTime(sourceMetaData.DateTaken, CultureInfo.CurrentCulture);
destMetadata.DateTaken = fromDate.ToString(CultureInfo.InvariantCulture.DateTimeFormat);

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s