public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { if (!(value is string str)) { return(null); } try { return(TypeConverters.ParseOsuTimestamp(str).TotalMilliseconds); } catch (Exception e) { Console.WriteLine(e); } if (parameter is string s) { return(TypeConverters.TryParseDouble(str, out double result2) ? result2 : double.Parse(s, CultureInfo.InvariantCulture)); } if (TypeConverters.TryParseDouble(str, out double result3)) { return(result3); } return(new ValidationResult(false, "Time format error.")); }
public void TimestampParserTest() { var test1 = TypeConverters.ParseOsuTimestamp("00:00:891 (1) - "); Assert.AreEqual(891, test1.TotalMilliseconds); var test2 = TypeConverters.ParseOsuTimestamp("60:00:074 (2,4) - "); Assert.AreEqual(3600074, test2.TotalMilliseconds); var test3 = TypeConverters.ParseOsuTimestamp("60:00:074 - "); Assert.AreEqual(3600074, test3.TotalMilliseconds); var test4 = TypeConverters.ParseOsuTimestamp("00:-01:-230 (1) - "); Assert.AreEqual(-1230, test4.TotalMilliseconds); }