コード例 #1
0
        /// <summary>
        /// Gets first day of quarter. <br />
        /// 获取一个季度的第一天。
        /// </summary>
        /// <param name="ld"></param>
        /// <returns></returns>
        public static LocalDate FirstDayOfQuarter(this LocalDate ld)
        {
            var currentQuarter = (ld.Month - 1) / 3 + 1;
            var firstDay       = new LocalDate(ld.Year, 3 * currentQuarter - 2, 1);

            return(ld.SetDate(firstDay.Year, firstDay.Month, firstDay.Day));
        }
コード例 #2
0
        /// <summary>
        /// Gets last day of quarter.<br />
        /// 获取一个季度的最后一天。
        /// </summary>
        /// <param name="ld"></param>
        /// <returns></returns>
        public static LocalDate LastDayOfQuarter(this LocalDate ld)
        {
            var currentQuarter = (ld.Month - 1) / 3 + 1;
            var firstDay       = ld.SetDate(ld.Year, 3 * currentQuarter - 2, 1);

            return(firstDay.SetMonth(firstDay.Month + 2).LastDayOfMonth());
        }
コード例 #3
0
        /// <summary>
        /// Gets previous month.<br />
        /// 上一个月。
        /// </summary>
        /// <param name="ld"></param>
        /// <returns></returns>
        public static LocalDate PreviousMonth(this LocalDate ld)
        {
            var year = ld.Month == 1 ? ld.Year - 1 : ld.Year;

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

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

            var lastDayOfPreviousMonth = firstDayOfPreviousMonth.LastDayOfMonth().Day;

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

            return(firstDayOfPreviousMonth.SetDay(day));
        }
コード例 #4
0
 /// <summary>
 /// Gets first day of year. <br />
 /// 获取一年的第一天。
 /// </summary>
 /// <param name="ld"></param>
 /// <returns></returns>
 public static LocalDate FirstDayOfYear(this LocalDate ld) => ld.SetDate(ld.Year, 1, 1);
コード例 #5
0
 /// <summary>
 /// Gets last day of year.<br />
 /// 获取一年的最后一天。
 /// </summary>
 /// <param name="ld"></param>
 /// <returns></returns>
 public static LocalDate LastDayOfYear(this LocalDate ld) => ld.SetDate(ld.Year, 12, 31);