static PeriodUnit() { Month = new PeriodUnit("month", "m"); Year = new PeriodUnit("year", "y", 12); HalfMonth = new PeriodUnit("half-month", "half-month", 0.5m); BiMontly = new PeriodUnit("bi-monthly", "bi-monthly", 2); Quarter = new PeriodUnit("quarter", "quarter", 3); HalfYear = new PeriodUnit("half-year", "half-year", 6); }
/// <summary>Constructor for a period of [start, start + amount*term]</summary> /// <param name="start">Start of a period</param> /// <param name="amount">Number of terms</param> /// <param name="term">Term (default Month)</param> /// <param name="rounding">Rounding option</param> /// <param name="decimals">Rate precision</param> public TermsItem(DateTime start, uint amount = 1, PeriodUnit term = null, Rounding rounding = Rounding.None, int decimals = 0) : base(start, end(start, amount, term), rounding, decimals) { Amount = amount; Term = term ?? PeriodUnit.Month; }
private static DateTime end(DateTime start, uint amount, PeriodUnit term) => start.AddMonths((int)(amount * (term ?? PeriodUnit.Month).AmountOfBaseUnits)).AddDays(-1);
/// <summary>Constructor</summary> /// <param name="name">Name</param> /// <param name="symbol">Symbol</param> /// <param name="amount">Amount of reference units (1 for the base unit)</param> /// <param name="reference">Reference Measure Unit (null for the base unit)</param> /// <exception cref="ArgumentException">Amount must be positive</exception> /// <exception cref="TypeInitializationException">Created unit and the reference unit must belong to the same measure equivalence class</exception> /// <exception cref="TypeInitializationException">First unit of the equivalence class must have rate equal to 1</exception> public PeriodUnit(string name, string symbol, decimal amount = 1, PeriodUnit reference = null) : base(name, symbol, amount, reference) { }