コード例 #1
0
 /// <summary>
 /// Get a DateTime representing the current unit of time.
 /// </summary>
 /// <param name="current">The current date.</param>
 /// <param name="dateUnit">The date unit.</param>
 /// <returns></returns>
 public static DateTime This(this DateTime current, DateUnit dateUnit)
 {
     switch (dateUnit)
     {
         case DateUnit.Day:
             return current.Midnight();
         case DateUnit.Week:
             return current.AddWeeks(-1).Next(CultureInfo.CurrentCulture.DateTimeFormat.FirstDayOfWeek);
         case DateUnit.Month:
             return current.First();
         case DateUnit.Year:
             return new DateTime(current.Year,1,1);
     }
     return current;
 }
コード例 #2
0
ファイル: DateTimeExtensions.cs プロジェクト: HaKDMoDz/eStd
 /// <summary>
 /// Adds one week to the specified <see cref="DateTime">DateTime</see> value.
 /// </summary>
 /// <param name="value">The date to evaluate.</param>
 /// <returns>A <see cref="DateTime">DateTime</see> representing one weeek after the specified <see cref="DateTime">DateTime</see>.</returns>
 public static DateTime AddWeek(this DateTime value)
 {
     return value.AddWeeks(1);
 }
コード例 #3
0
 /// <summary>
 /// Subtracts given weeks from the given DateTime.
 /// </summary>
 /// <param name="date">The given DateTime.</param>
 /// <param name="weeks">Number of weeks to be subtracted.</param>
 /// <returns>The DateTime after the given weeks are subtracted.</returns>
 public static DateTime SubtractWeeks(this DateTime date, int weeks)
 {
     return date.AddWeeks(weeks.Negate());
 }
コード例 #4
0
 /// <summary>
 /// Adds one week to the given DateTime.
 /// </summary>
 /// <param name="date">The given DateTime.</param>
 /// <returns>The DateTime after one week is added.</returns>
 public static DateTime AddAWeek(this DateTime date)
 {
     return date.AddWeeks(1);
 }
コード例 #5
0
 public static DateTime SubtractWeeks(this DateTime dateTime, int weeks)
 {
     return dateTime.AddWeeks(-weeks);
 }
コード例 #6
0
        public static DateTime SubtractWeeks(this DateTime date, double value) {
            if (value < 0)
                throw new ArgumentException("Value cannot be less than 0.", "value");

            return date.AddWeeks(value * -1);
        }
コード例 #7
0
 public static DateTime AddWeek(this DateTime d)
 {
     return d.AddWeeks(1);
 }
コード例 #8
0
 public static DateTimeOffset SubtractWeeks(this DateTimeOffset dateTimeOffset, double weeks)
 {
     return dateTimeOffset.AddWeeks(-weeks);
 }
コード例 #9
0
        public static DateTime? GetDayOfWeekInTheMonth(this DateTime date, DayOfWeek dayOfWeek, int instance)
        {
            if (instance <= 0)
                return null;

            date = FirstDayOfTheMonth(date, dayOfWeek);

            if (instance == 1)
                return date;
            return date.AddWeeks();
        }