public void WriteTimespan_WritesTheTimepspansInCultureInvariantFormat(string span, string expected) { var t = new TimespanType() { Ts = TimeSpan.Parse(span) }; var written = Toml.WriteString(t); written.Should().Be($"Ts = {expected}\r\n"); }
protected void ToForm() { CustomCurrency cc = Currency; hdnCCId.Value = cc.ID.ToString(CultureInfo.InvariantCulture); txtRuleName.Text = cc.DisplayName; cmbLimitType.SelectedValue = cc.CurrencyLimitType.ToString(); if (cc.EventType.IsIntegerOnly()) { decMinEvents.EditingMode = Controls_mfbDecimalEdit.EditMode.Integer; decMinEvents.IntValue = (int)cc.RequiredEvents; } else { decMinEvents.EditingMode = Controls_mfbDecimalEdit.EditMode.Decimal; decMinEvents.Value = cc.RequiredEvents; } cmbEventTypes.SelectedValue = ((int)cc.EventType).ToString(CultureInfo.InvariantCulture); SelectedTimespanType = cc.CurrencyTimespanType; txtTimeFrame.Text = cc.CurrencyTimespanType.IsAligned() ? string.Empty : cc.ExpirationSpan.ToString(CultureInfo.InvariantCulture); foreach (ListItem li in lstModels.Items) { li.Selected = cc.ModelsRestriction.Contains(Convert.ToInt32(li.Value, CultureInfo.InvariantCulture)); } foreach (ListItem li in lstAircraft.Items) { li.Selected = cc.AircraftRestriction.Contains(Convert.ToInt32(li.Value, CultureInfo.InvariantCulture)); } cmbCategory.SelectedValue = cc.CategoryRestriction; cmbCatClass.SelectedValue = cc.CatClassRestriction.ToString(); txtAirport.Text = cc.AirportRestriction; txtContainedText.Text = cc.TextRestriction; if (cc.PropertyRestriction != null) { HashSet <int> hsPropsChecked = new HashSet <int>(cc.PropertyRestriction); foreach (ListItem li in lstProps.Items) { int propID = Convert.ToInt32(li.Value, CultureInfo.InvariantCulture); li.Selected = cc.PropertyRestriction.Contains(propID); hsPropsChecked.Remove(propID); } // Add in any properties that were not found above! (I.e., blacklisted or otherwise not favorite) IEnumerable <CustomPropertyType> rgBlackListProps = CustomPropertyType.GetCustomPropertyTypes(hsPropsChecked); foreach (CustomPropertyType cpt in rgBlackListProps) { lstProps.Items.Add(new ListItem(cpt.Title, cpt.PropTypeID.ToString(CultureInfo.InvariantCulture)) { Selected = true }); } } btnAddCurrencyRule.Visible = cc.ID <= 0; // only show the add button if we're doing a new currency. }
public void WriteTimespan_WritesTheTimepspansInGoLikeFormat(string span, string expected) { var t = new TimespanType() { Ts = TimeSpan.Parse(span) }; var written = Toml.WriteString(t); written.Should().Be($"Ts = {expected}\r\n"); }
public static Func <DateTime, int, DateTime> ToIncrementer(this TimespanType kind) { return(kind switch { TimespanType.None => new Func <DateTime, int, DateTime>((x, i) => x), TimespanType.Second => new Func <DateTime, int, DateTime>((x, i) => x.AddSeconds(i)), TimespanType.Minute => new Func <DateTime, int, DateTime>((x, i) => x.AddMinutes(i)), TimespanType.Hour => new Func <DateTime, int, DateTime>((x, i) => x.AddHours(i)), TimespanType.Day => new Func <DateTime, int, DateTime>((x, i) => x.AddDays(i)), TimespanType.Week => new Func <DateTime, int, DateTime>((x, i) => x.AddDays(7 * i)), TimespanType.Month => new Func <DateTime, int, DateTime>((x, i) => x.AddMonths(i)), TimespanType.Year => new Func <DateTime, int, DateTime>((x, i) => x.AddYears(i)), _ => throw new ArgumentOutOfRangeException(nameof(kind), kind, null), });
public IEnumerable <DateTime> Enumerate(TimespanType kind, int interval = 1) { if (kind == TimespanType.None) { throw new ArgumentException("Cannot enumerate by null"); } interval = Math.Abs(interval); foreach (var item in base.Start.EnumerateInterval(kind, interval)) { if (item > base.End) { yield break; } yield return(item); } }
public IEnumerable <DateTimeRange> EnumerateRanges(TimespanType type, int interval = 1) { if (type == TimespanType.None) { throw new ArgumentException("Cannot enumerate by null"); } var previous = base.Start; interval = Math.Abs(interval); foreach (var item in base.Start.EnumerateInterval(type, interval)) { if (previous != item) { yield return(new DateTimeRange(previous, item)); } previous = item; if (item > base.End) { yield break; } } }
public static IEnumerable <DateTime> EnumerateInterval(this DateTime dateTime, TimespanType kind, int interval = 1) { if (kind == TimespanType.None) { throw new ArgumentException("Cannot enumerate by null"); } var incrementer = kind.ToIncrementer(); for (var dt = dateTime; ; dt = incrementer(dt, interval)) { yield return(dt); } }