public static bool Test() { if ((new WorldTime() { Hour = 4, Minute = 30, AM = true }).ToString() != "4:30 AM") { return(false); } if (WorldTime.Parse(0).ToString() != "4:30 AM") { return(false); } if (WorldTime.Parse("12:00pm").Value.GameTime != 27000) //43200.0) { return(false); } if (WorldTime.Parse("12:00am").Value.GameTime != WorldTime.TimeMax - (4.5 * 60.0 * 60.0)) //43200.0) { var aa = WorldTime.Parse("12:00am").Value.GameTime; var a = WorldTime.Parse("12:30am").Value.GameTime; var ab = WorldTime.Parse("12:59am").Value.GameTime; var b = WorldTime.Parse("1:00am").Value.GameTime; var c = WorldTime.Parse("3:00am").Value.GameTime; var d = WorldTime.Parse("4:00am").Value.GameTime; var f = WorldTime.Parse("5:00am").Value.GameTime; return(false); } var _12 = WorldTime.Parse("12:00am").Value.GameTime; var parsed = WorldTime.Parse(_12); if (parsed.ToString() != "12:00 AM") { return(false); } _12 = WorldTime.Parse("12:01am").Value.GameTime; parsed = WorldTime.Parse(_12); if (parsed.ToString() != "12:01 AM") { return(false); } for (var h = 1; h <= 24; h++) { for (var m = 0; m < 60; m++) { var time = String.Format("{0}:{1:00} {2}", h > 12 ? h - 12 : h, m, h < 12 ? "AM" : "PM"); System.Diagnostics.Debug.WriteLine("Testing time " + time); var t = Parse(time); if (t.ToString() != time) { return(false); } var t2 = Parse(t.Value.GameTime); if (t2.ToString() != time) { Parse(t.Value.GameTime); Parse(t.Value.GameTime); return(false); } //if (t2.ToString() == (new WorldTime() //{ // Hour = (byte)h, // Minute = (byte)m, // AM = h <= 12 //}).ToString()) //{ // return false; //} } } return(true); }
bool TryParseAt <T>(int at, out T t) { t = default(T); if (typeof(T) == typeof(string)) { string val; if (TryGetString(at, out val)) { t = (T)(object)val; return(true); } return(false); } else if (typeof(T) == typeof(int)) { int val; if (TryGetInt(at, out val)) { t = (T)(object)val; return(true); } return(false); } else if (typeof(T) == typeof(bool)) { bool val; if (TryGetBool(at, out val)) { t = (T)(object)val; return(true); } return(false); } #if Full_API else if (typeof(T) == typeof(Player)) { Player val; if (TryGetOnlinePlayer(at, out val)) { t = (T)(object)val; return(true); } return(false); } #endif else if (typeof(T) == typeof(double)) { double val; if (TryGetDouble(at, out val)) { t = (T)(object)val; return(true); } return(false); } else if (typeof(T) == typeof(TimeSpan)) { TimeSpan val; if (TryGetDuration(at, out val)) { t = (T)(object)val; return(true); } return(false); } else if (typeof(T) == typeof(WorldTime)) { var val = WorldTime.Parse(this[at]); if (val != null) { var gt = val.Value.GameTime; if (gt >= WorldTime.TimeMin && gt <= WorldTime.TimeMax) { t = (T)(object)val.Value; return(true); } else { throw new CommandError("Invalid time."); } } return(false); } throw new CommandError("Internal command error, type is unsupported by parser: {0}.", typeof(T).ToString()); }