/// <summary>
        /// 获取某日期所在的季度的开始日期和结束日期
        /// </summary>
        /// <param name="dtNow">当前日期</param>
        /// <returns>本季度初,本季度末</returns>
        public static (DateOnly firstDay, DateOnly lastDay) GetDateQuarter(DateOnly dtNow)
        {
            var dtQuarterSt = dtNow.AddMonths(0 - (dtNow.Month - 1) % 3).AddDays(1 - dtNow.Day); //本季度初
            var dtQuarterEd = dtQuarterSt.AddMonths(3).AddDays(-1);                              //本季度末

            return(dtQuarterSt, dtQuarterEd);
        }
        /// <summary>
        /// получение полезного отпуска (FORMAB71)
        /// </summary>
        /// <returns></returns>
        private ElectricitySupply ParseElectricitySupplyRecord(DbfRecord record)
        {
            ElectricitySupply electricitySupply = new();

            if (record != null)
            {
                int      currYear = DateTime.Now.Year;
                DateOnly period   = ConvertToDateOnly(record.GetValue <DateTime>("DATE_N"));
                if (period.Year == currYear || period.Year == currYear - 1)
                {
                    try
                    {
                        electricitySupply.ДатаОплаты          = ConvertToDateOnly(record.GetValue <DateTime>("DATE_OPL"));
                        electricitySupply.ОплаченныеПоказания = record.GetValue <int>("DATA_OPL");

                        electricitySupply.Период                 = period.AddMonths(-1); // оплата на месяц позже
                        electricitySupply.Лицевой                = ConvertToULong(record.GetString("LIC_SCH"));
                        electricitySupply.Полезный_отпуск        = record.GetValue <int>("POLOT");
                        electricitySupply.Задолженность          = record.GetValue <int>("KVT_ZADOL");
                        electricitySupply.Тип_населённого_пункта = record.GetString("TIP");
                    }
                    catch (Exception ex)
                    {
                        logger?.Error($">>> TMP.WORK.AramisChetchiki.Repository>GetSelectedDepartamentData->electricitySupplyTable\n>>>: {TMPApp.GetExceptionDetails(ex)}");
                    }

                    /*
                     *                           System.Data.DataRow[] abonents = electricitySupplyRow.GetChildRows("ПО_абонент");
                     *
                     * if (abonents != null && abonents.Length != 0)
                     * {
                     *  DataRow abonent = abonents[0];
                     *  electricitySupply.Населённый_пункт = _getChildRelationValue(abonent, "населенный_пункт", "TOWN");
                     *  electricitySupply.Адрес = string.Join(", ", new string[]
                     *  {
                     * _getChildRelationValue(abonent, "улицы", "STREET"),
                     * _getString(abonent["HOME"]),
                     * _getString(abonent["KV"])
                     *  });
                     *
                     *  var fider10Rows = abonent.GetChildRows("фидер10");
                     *  if (fider10Rows.Length > 0)
                     *  {
                     *      var fider10 = fider10Rows[0];
                     *      s = _getString(fider10["ФИДЕР"]);
                     *      electricitySupply.Фидер10 = String.IsNullOrWhiteSpace(s) ? String.Empty : _getString(fider10["НАИМЕНОВ"]) + "-" + s;
                     *      electricitySupply.Подстанция = _getChildRelationValue(fider10, "подстанция", "НАИМЕНОВ");
                     *  }
                     *  electricitySupply.ТП = _getChildRelationValue(abonent, "тп", "НАИМЕНОВ");
                     *  electricitySupply.Фидер04 = _getString(abonent["ФИДЕР"]);
                     * }
                     * */
                }
            }
            else
            {
            }

            return(electricitySupply);
        }
        /// <summary>
        /// 获取某日期所在的月的月初日期和月末日期
        /// </summary>
        /// <param name="dtNow">当前日期</param>
        /// <returns>月初,月末</returns>
        public static (DateOnly firstDay, DateOnly lastDay) GetDateMonth(DateOnly dtNow)
        {
            DateOnly dtFirstDay = dtNow.AddDays(1 - dtNow.Day);        //本月月初
            DateOnly dtLastDay  = dtFirstDay.AddMonths(1).AddDays(-1); //本月月末

            //dtMonthEd = dtMonthSt.AddDays((dtNow.AddMonths(1) - dtNow).Days - 1);  //本月月末
            return(dtFirstDay, dtLastDay);
        }
Esempio n. 4
0
    public static int MonthsTo(this DateOnly start, DateOnly end)
    {
        int result = end.Month - start.Month + (end.Year - start.Year) * 12;

        if (end < start.AddMonths(result))
        {
            result--;
        }

        return(result);
    }
        /// <summary>
        /// Calculates the distance of time in words between two provided dates
        /// </summary>
        public static string DefaultHumanize(DateOnly input, DateOnly comparisonBase, CultureInfo culture)
        {
            var tense    = input > comparisonBase ? Tense.Future : Tense.Past;
            var diffDays = Math.Abs(comparisonBase.DayOfYear - input.DayOfYear);
            var ts       = new TimeSpan(diffDays, 0, 0, 0);

            var sameMonth = comparisonBase.AddMonths(tense == Tense.Future ? 1 : -1) == input;

            var days = Math.Abs(input.DayOfYear - comparisonBase.DayOfYear);

            return(DefaultHumanize(ts, sameMonth, days, tense, culture));
        }
Esempio n. 6
0
        public static void AddMonthsTest()
        {
            DateOnly dateOnly = new DateOnly(2021, 1, 31);

            for (int i = 1; i < 12; i++)
            {
                Assert.Equal(i, dateOnly.Month);
                dateOnly = dateOnly.AddMonths(1);
            }

            for (int i = 12; i > 1; i--)
            {
                Assert.Equal(i, dateOnly.Month);
                dateOnly = dateOnly.AddMonths(-1);
            }

            DateTime dt = DateTime.Today;

            dateOnly = DateOnly.FromDayNumber((int)(dt.Ticks / TimeSpan.TicksPerDay));

            Assert.Equal(dt.Year, dateOnly.Year);
            Assert.Equal(dt.Month, dateOnly.Month);
            Assert.Equal(dt.Day, dateOnly.Day);

            dt       = dt.AddMonths(1);
            dateOnly = dateOnly.AddMonths(1);
            Assert.Equal(dt.Month, dateOnly.Month);

            dt       = dt.AddMonths(50);
            dateOnly = dateOnly.AddMonths(50);
            Assert.Equal(dt.Month, dateOnly.Month);

            dt       = dt.AddMonths(-150);
            dateOnly = dateOnly.AddMonths(-150);
            Assert.Equal(dt.Month, dateOnly.Month);

            Assert.Throws <ArgumentOutOfRangeException>(() => DateOnly.MinValue.AddMonths(-1));
            Assert.Throws <ArgumentOutOfRangeException>(() => DateOnly.MaxValue.AddMonths(1));
        }
 /// <summary>
 /// 10 months from the provided date
 /// </summary>
 public static DateOnly MonthsFrom(DateOnly date)
 {
     return(date.AddMonths(10));
 }