public void Flexible_timespan_parse_should_work() { TimeSpanExt.Parse(null).Should().Be(TimeSpan.Zero); TimeSpanExt.Parse("").Should().Be(TimeSpan.Zero); TimeSpanExt.Parse("10").Should().Be(TimeSpan.FromSeconds(10)); TimeSpanExt.Parse("59").Should().Be(TimeSpan.FromSeconds(59)); Assert.Throws <FormatException>(() => TimeSpanExt.Parse("60")); TimeSpanExt.Parse("1:10").Should().Be(new TimeSpan(0, 0, 1, 10)); TimeSpanExt.Parse("15:10").Should().Be(new TimeSpan(0, 0, 15, 10)); TimeSpanExt.Parse("12:15:10").Should().Be(new TimeSpan(0, 12, 15, 10)); }
/// <summary> /// Сборка TimeSpanExt из вспомогательных полей /// </summary> /// <param name="formatedTimeSpanExt"></param> /// <returns></returns> public TimeSpanExt ConvertFormatedTimeSpanExtString(string formatedTimeSpanExt) { TimeSpanExt timeSpanExt = new TimeSpanExt(this.Session); try { // Сингулярность timeSpanExt.TimeSingularity = WorkTimeSingularity; if (WorkTimeSingularity == CS.TimeSingularity.Standart) { string Delimiter = " "; string TimeDelimiter = ":"; string[] separator = { Delimiter }; string[] timeSeparator = { TimeDelimiter }; string[] mTimeExt = formatedTimeSpanExt.Split(separator, StringSplitOptions.RemoveEmptyEntries); string[] mTime = mTimeExt[6].Split(timeSeparator, StringSplitOptions.RemoveEmptyEntries); timeSpanExt.Second = 0; timeSpanExt.Minute = Convert.ToInt32(mTime[1]); timeSpanExt.Hour = Convert.ToInt32(mTime[0]); timeSpanExt.Day = Convert.ToInt32(mTimeExt[4]); timeSpanExt.Month = Convert.ToInt32(mTimeExt[2]); timeSpanExt.Quarter = 0; timeSpanExt.Year = Convert.ToInt32(mTimeExt[0]); } else { timeSpanExt.Second = 0; timeSpanExt.Minute = 0; timeSpanExt.Hour = 0; timeSpanExt.Day = 0; timeSpanExt.Month = 0; timeSpanExt.Quarter = 0; timeSpanExt.Year = 0; } } catch (Exception ex) { throw new Exception("Error parsing TimeSpanExt formated string", ex); } return(timeSpanExt); }
private void Button_Clicked(object sender, EventArgs e) { var imageStream = GetType().Assembly.GetManifestResourceStream("LocalNotification.Sample.icon.png"); byte[] imageBytes = null; if (imageStream != null) { using (var ms = new MemoryStream()) { imageStream.CopyTo(ms); imageBytes = ms.ToArray(); } } _tapCount++; var notificationId = 100; var title = "Test"; var list = new List <string> { typeof(NotificationPage).FullName, notificationId.ToString(), title, _tapCount.ToString() }; var serializeReturningData = JsonSerializer.Serialize(list); var request = new NotificationRequest { NotificationId = notificationId, Title = title, Subtitle = $"Tap Count: {_tapCount}", Description = $"Tap Count: {_tapCount}", BadgeNumber = _tapCount, ReturningData = serializeReturningData, Image = { //ResourceName = "icon", Binary = imageBytes }, CategoryType = NotificationCategoryType.Status, Android = { IconSmallName = { ResourceName = "icon1", }, Color = { ResourceName = "colorPrimary" }, IsProgressBarIndeterminate = false, ProgressBarMax = 20, ProgressBarProgress = _tapCount //AutoCancel = false, //Ongoing = true }, iOS = { HideForegroundAlert = CustomAlert.IsToggled, PlayForegroundSound = ForegroundSound.IsToggled } }; // if not specified, default sound will be played. if (CustomSoundSwitch.IsToggled) { request.Sound = Device.RuntimePlatform == Device.Android ? "good_things_happen" : "good_things_happen.aiff"; } // if not specified, notification will show immediately. if (UseNotifyTimeSwitch.IsToggled) { var notifyDateTime = NotifyDatePicker.Date.Add(NotifyTimePicker.Time); if (notifyDateTime <= DateTime.Now) { notifyDateTime = DateTime.Now.AddSeconds(10); } request.Schedule.NotifyAutoCancelTime = DateTime.Now.AddMinutes(5); request.Schedule.NotifyTime = notifyDateTime; //request.Schedule.RepeatType = RepeatSwitch.IsToggled ? NotificationRepeat.Daily : NotificationRepeat.No; request.Schedule.RepeatType = NotificationRepeat.TimeInterval; request.Schedule.NotifyRepeatInterval = TimeSpanExt.ToTimeSpanExt(TimeSpan.FromMinutes(2)); } NotificationCenter.Current.Show(request); }
protected virtual TimeSpan TrimInvalidationDelay(TimeSpan delay) => TimeSpanExt.Min(delay, MaxInvalidationDelay);