Esempio n. 1
0
        /// <summary>
        /// First day of week. <br />
        /// 获取一周的第一天。
        /// </summary>
        /// <param name="ld"></param>
        /// <returns></returns>
        public static LocalDate FirstDayOfWeek(this LocalDate ld)
        {
            var currentCulture = CultureInfo.CurrentCulture;
            var firstDayOfWeek = (int)currentCulture.DateTimeFormat.FirstDayOfWeek;

            var currentDayOfWeek = (int)ld.DayOfWeek;

            var offset = currentDayOfWeek - firstDayOfWeek < 0 ? 7 : 0;
            var numberOfDaysSinceBeginningOfTheWeek = currentDayOfWeek + offset - firstDayOfWeek;

            return(ld.AddDays(-numberOfDaysSinceBeginningOfTheWeek));
        }
Esempio n. 2
0
        /// <summary>
        /// Previous Year.<br />
        /// 上一年。
        /// </summary>
        /// <param name="ld"></param>
        /// <returns></returns>
        public static LocalDate PreviousYear(this LocalDate ld)
        {
            var year        = ld.Year - 1;
            var daysOfMonth = DateTime.DaysInMonth(year, ld.Month);

            if (daysOfMonth == ld.Day)
            {
                return(new LocalDate(ld.Era, year, ld.Month, ld.Day));
            }

            var d = ld.Day - daysOfMonth;
            var p = new LocalDate(ld.Era, year, ld.Month, daysOfMonth);

            return(p.AddDays(d));
        }
Esempio n. 3
0
 /// <summary>
 /// Previous Day.<br />
 /// 上一天。
 /// </summary>
 /// <param name="ld"></param>
 /// <returns></returns>
 public static LocalDate PreviousDay(this LocalDate ld) => ld.AddDays(-1);
Esempio n. 4
0
 /// <summary>
 /// Next day.<br />
 /// 下一天。
 /// </summary>
 /// <param name="ld"></param>
 /// <returns></returns>
 public static LocalDate NextDay(this LocalDate ld) => ld.AddDays(1);