Exemplo n.º 1
0
        /// <summary>
        /// Gets last day of quarter
        /// </summary>
        /// <param name="ldt"></param>
        /// <returns></returns>
        public static LocalDateTime LastDayOfQuarter(this LocalDateTime ldt)
        {
            var currentQuarter = (ldt.Month - 1) / 3 + 1;
            var firstDay       = ldt.SetDate(ldt.Year, 3 * currentQuarter - 2, 1);

            return(firstDay.SetMonth(firstDay.Month + 2).LastDayOfMonth());
        }
Exemplo n.º 2
0
        /// <summary>
        /// Gets first day of quarter
        /// </summary>
        /// <param name="ldt"></param>
        /// <returns></returns>
        public static LocalDateTime FirstDayOfQuarter(this LocalDateTime ldt)
        {
            var currentQuarter = (ldt.Month - 1) / 3 + 1;
            var firstDay       = new LocalDateTime(ldt.Year, 3 * currentQuarter - 2, 1, ldt.Hour, ldt.Minute);

            return(ldt.SetDate(firstDay.Year, firstDay.Month, firstDay.Day));
        }
Exemplo n.º 3
0
        /// <summary>
        /// Gets previous month
        /// </summary>
        /// <param name="ldt"></param>
        /// <returns></returns>
        public static LocalDateTime PreviousMonth(this LocalDateTime ldt)
        {
            var year = ldt.Month == 1 ? ldt.Year - 1 : ldt.Year;

            var month = ldt.Month == 1 ? 12 : ldt.Month - 1;

            var firstDayOfPreviousMonth = ldt.SetDate(year, month, 1);

            var lastDayOfPreviousMonth = firstDayOfPreviousMonth.LastDayOfMonth().Day;

            var day = ldt.Day > lastDayOfPreviousMonth ? lastDayOfPreviousMonth : ldt.Day;

            return(firstDayOfPreviousMonth.SetDay(day));
        }
Exemplo n.º 4
0
 /// <summary>
 /// Gets last day of year
 /// </summary>
 /// <param name="ldt"></param>
 /// <returns></returns>
 public static LocalDateTime LastDayOfYear(this LocalDateTime ldt) => ldt.SetDate(ldt.Year, 12, 31);
Exemplo n.º 5
0
 /// <summary>
 /// Gets first day of year
 /// </summary>
 /// <param name="ldt"></param>
 /// <returns></returns>
 public static LocalDateTime FirstDayOfYear(this LocalDateTime ldt) => ldt.SetDate(ldt.Year, 1, 1);