I I have a timezone taken from a user that must be converted into total minutes to be stored in the database. I have the following code and it looks pretty ugly. I am new to C# and was wondering if there is a better way to do this.
string tz = userList.Rows[0][1].ToString().Trim();
//Timezones can take the form of + or - followed by hour and then minutes in 15 minute increments.
Match tzre = new Regex(@"^(\+|-)?(0?[0-9]|1[0-2])(00|15|30|45)$").Match(tz);
if (!tzre.success)
{
throw new
myException("Row 1, column 2 of the CSV file to be imported must be a valid timezone: " + tz);
}
GroupCollection tzg = tzre.Groups;
tz = Convert.ToInt32(tzg[0].Value + Convert.ToString(Convert.ToInt32(tzg[1].Value) * 60 + Convert.ToInt32(tzg[2]))).ToString();