public SmppTime(SmppTime time) { AbsoluteTime = time.AbsoluteTime; RelativeTime = time.RelativeTime; Type = time.Type; _includeUtc = time._includeUtc; }
public static void ParseRelative(string s, int days, int hours, int minutes) { var result = SmppTime.TryParse(s, out var time); Assert.True(result); Assert.Equal(SmppDateTimeType.Relative, time.Type); Assert.Equal(days, time.RelativeTime.Days); Assert.Equal(hours, time.RelativeTime.Hours); Assert.Equal(minutes, time.RelativeTime.Minutes); }
public static void ParseAbsoluteShort(string s, int year, int month, int day, int hour, int minute) { var result = SmppTime.TryParse(s, out SmppTime time); Assert.True(result); Assert.Equal(SmppDateTimeType.Absolute, time.Type); Assert.Equal(year, time.AbsoluteTime.Year); Assert.Equal(month, time.AbsoluteTime.Month); Assert.Equal(day, time.AbsoluteTime.Day); Assert.Equal(hour, time.AbsoluteTime.Hour); Assert.Equal(minute, time.AbsoluteTime.Minute); }
public static void ParseAbsoluteFull(string s, int year, int month, int day, int hour, int minute, int second, int millis) { var result = SmppTime.TryParse(s, out SmppTime time); Assert.True(result); Assert.Equal(SmppDateTimeType.Absolute, time.Type); var utc = time.AbsoluteTime.ToUniversalTime(); Assert.Equal(year, utc.Year); Assert.Equal(month, utc.Month); Assert.Equal(day, utc.Day); Assert.Equal(hour, utc.Hour); Assert.Equal(minute, utc.Minute); Assert.Equal(second, utc.Second); Assert.Equal(millis, utc.Millisecond); }
public static bool TryParse(string s, out SmppTime result) { Exception error; return(TryParse(s, out result, out error)); }
private static bool TryParse(string s, out SmppTime result, out Exception error) { try { if (s.Length >= SmppTime.MinShortSize) { int MM, DD, YY, mm, hh, ss; YY = Convert.ToInt32(s.Substring(0, 2)); MM = Convert.ToInt32(s.Substring(2, 2)); DD = Convert.ToInt32(s.Substring(4, 2)); hh = Convert.ToInt32(s.Substring(6, 2)); mm = Convert.ToInt32(s.Substring(8, 2)); ss = 0; if (s.Length >= SmppTime.MinRequiredSize) { ss = Convert.ToInt32(s.Substring(10, 2)); } if (s.Length >= SmppTime.MaxRequiredSize) { int ms, nn; string type; ms = Convert.ToInt32(s.Substring(12, 1)); nn = Convert.ToInt32(s.Substring(13, 2)); type = s.Substring(15, 1); // If it is a relative time, then use a timespan. if (type == "R") { //TODO: we are generalizing here; 365 days per year, 30 days per month result = new SmppTime(new TimeSpan((YY * 365) + (MM * 30) + DD, hh, mm, ss, ms * 100), true); error = null; return(true); } // Calculate the date and then convert it to UTC. var dateTime = new DateTime(YY + 2000, MM, DD, hh, mm, ss, ms * 100); if (type == "+") { dateTime += new TimeSpan(0, 0, nn * 15, 0, 0); } else if (type == "-") { dateTime -= new TimeSpan(0, 0, nn * 15, 0, 0); } // Now convert it to our local time. var localTime = TimeZoneInfo.ConvertTimeFromUtc(dateTime, TimeZoneInfo.Local); result = new SmppTime(localTime, true); error = null; return(true); } result = new SmppTime(new DateTime(YY + 2000, MM, DD, hh, mm, ss), false); error = null; return(true); } error = new FormatException($"The string '{s}' has an invalid format for SMPP"); result = null; return(false); } catch (Exception ex) { error = new FormatException($"The string '{s}' is invalid for a SMPP time", ex); result = null; return(false); } }
public static void FormatFullDate(int year, int month, int day, int hour, int minute, int second, int millis, string expected) { var date = new SmppTime(new DateTime(year, month, day, hour, minute, second, millis), true); Assert.Equal(expected, date.ToSmppString()); }
public static void FormatShortDate(int year, int month, int day, int hour, int minute, int second, string expected) { var date = new SmppTime(new DateTime(year, month, day, hour, minute, second), false); Assert.Equal(expected, date.ToSmppString()); }