Timespan contains timezone, need to implement the right code

Nov 29, 2011 at 1:09 AM

I'm getting the following "Server Error in '/' Application."

It is trying to read the timestamp from the meta data of the image, but where it could not find the timezone on the timestamp, it throws this error. Following is the piece of the code that does it:

         else if (typeof(T) == typeof(TimeSpan))
            {
                string timespanString = (unknownObject as string);

                if (!timespanString.EndsWith("+0000"))
                {
                    throw new NotImplementedException("Timespan contains timezone, need to implement the right code");
                }
                else if (timespanString.Length > 6)
                {
                    int hour = Convert.ToInt32(timespanString.Substring(0, 2));
                    int minute = Convert.ToInt32(timespanString.Substring(2, 2));
                    int second = Convert.ToInt32(timespanString.Substring(4, 2));

                    TimeSpan timeSpan = new TimeSpan(hour, minute, second);

                    return (T)Convert.ChangeType(timeSpan, typeof(T));
                }

 

Has there been an update to this code, so that this error doesn't occur? Or will I need to change the code to ignore the error and the return some default timestamp?

Aug 6, 2013 at 3:50 PM
I am getting this also. Just started today. Not sure why. Any updates on this issue?
Aug 9, 2013 at 5:04 PM
Edited Aug 9, 2013 at 5:11 PM
As a followup, this appears to happen when a photo was edited by a photo editor, such as Photoshop. For some reason, the editors change the time to an unusable format. I was able to change the code in the class to the following:

``` else if (typeof(T) == typeof(TimeSpan))
{
    string timespanString = (unknownObject as string);
    try
     {
    //if (!timespanString.EndsWith("+0000"))
    //{
    //}
    //else 
        if (timespanString.Length >= 6)
         {
             int hour = Convert.ToInt32(timespanString.Substring(0, 2));
             int minute = Convert.ToInt32(timespanString.Substring(2, 2));
             int second = Convert.ToInt32(timespanString.Substring(4, 2));

             TimeSpan timeSpan = new TimeSpan(hour, minute, second);
             return (T)Convert.ChangeType(timeSpan, typeof(T));
         }
        else
         {
            return default(T);
         }
     }
    catch (Exception)
     {
      return default(T);
     //throw new NotImplementedException("Timespan contains timezone, need to implement the right code");
     }
} 
 ```