Ok so i have this control: https://github.com/TBertuzzi/Xamarin.Forms.MaskedEntry
<control:MaskedEntry Placeholder="HH:MM:SS" Mask="XX:XX:XX" Keyboard="Numeric" Text="{Binding TaskDuration}" TextChanged="DurationIs8"></control:MaskedEntry>
In my app, the user enters a duration with this format hours:minute:second
Then this method is executed when saving the item, to get the duration to later use it for calculation :
public static TimeSpan GetDuration(string duration)
{
if(duration != null)
{
var value = duration.Split(':').Select(int.Parse).ToArray();
var datetime = new TimeSpan(value[0], value[1], value[2]);
return datetime;
}
return TimeSpan.Zero;
}
My Problem is that i want to be able to deal with cases where the user only enters, example : 02:0 Everytime i click the save button, i get the duration which generates the error if the MaskedEntry doesn't respect the format.
Currently this generate an index out of range exception everytime the GetDuration method is called because this line: var datetime = new TimeSpan(value[0], value[1], value[2]);
tries to access array value that doesn't exist.
Anyway to handle this so my app doesn't crash if the user doesn't complete the maskedentry ? Thanks a lot.