< Summary

Information
Class: MyNet.Temporal.DateTimeOffsetExtensions
Assembly: MyNet.Temporal
File(s): https://raw.githubusercontent.com/sandre58/MyNet/5aaaab311aa14541478b9e402357d98b657a23e4/src/MyNet.Temporal/Extensions/DateTimeOffsetExtensions.cs
Tag: 342_31701152804
Line coverage
57%
Covered lines: 66
Uncovered lines: 48
Coverable lines: 114
Total lines: 474
Line coverage: 57.8%
Branch coverage
57%
Covered branches: 28
Total branches: 49
Branch coverage: 57.1%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
ToDateTimeOffsetPeriod(...)100%210%
ToDateTimeOffsetPeriod(...)0%2040%
AddCalendarAmount(...)100%11100%
SubtractCalendarAmount(...)100%11100%
EndOfDay(...)100%11100%
BeginningOfDay(...)100%11100%
NextYear(...)50%2257.14%
PreviousYear(...)50%2257.14%
NextDay(...)100%11100%
PreviousDay(...)100%11100%
Next(...)100%22100%
Previous(...)100%22100%
WeekAfter(...)100%210%
WeekEarlier(...)100%210%
IncreaseTime(...)100%210%
DecreaseTime(...)100%210%
SetTime(...)100%210%
SetTime(...)100%210%
SetTime(...)100%210%
SetTime(...)100%11100%
SetHour(...)100%210%
SetMinute(...)100%210%
SetSecond(...)100%210%
SetMillisecond(...)100%210%
Midnight(...)100%210%
Noon(...)100%11100%
SetDate(...)100%210%
SetDate(...)100%210%
SetDate(...)100%11100%
SetYear(...)100%210%
SetMonth(...)100%210%
SetDay(...)100%11100%
At(...)100%210%
At(...)100%210%
At(...)100%210%
FirstDayOfQuarter(...)100%210%
FirstDayOfMonth(...)100%11100%
LastDayOfQuarter(...)100%210%
LastDayOfMonth(...)100%11100%
AddBusinessDays(...)100%88100%
SubtractBusinessDays(...)100%210%
IsInFuture(...)100%11100%
IsInPast(...)100%11100%
Round(...)46.15%771327.77%
FirstDayOfWeek(...)50%22100%
FirstDayOfYear(...)100%11100%
LastDayOfWeek(...)100%11100%
LastDayOfYear(...)100%11100%
PreviousMonth(...)50%66100%
NextMonth(...)50%66100%
SameDay(...)100%11100%
SameMonth(...)50%22100%
SameYear(...)100%11100%

File(s)

https://raw.githubusercontent.com/sandre58/MyNet/5aaaab311aa14541478b9e402357d98b657a23e4/src/MyNet.Temporal/Extensions/DateTimeOffsetExtensions.cs

#LineLine coverage
 1// -----------------------------------------------------------------------
 2// <copyright file="DateTimeOffsetExtensions.cs" company="Stéphane ANDRE">
 3// Copyright (c) Stéphane ANDRE. All rights reserved.
 4// </copyright>
 5// -----------------------------------------------------------------------
 6
 7using System;
 8using System.Globalization;
 9using MyNet.Temporal.Intervals;
 10
 11#pragma warning disable IDE0130 // Namespace does not match folder structure
 12namespace MyNet.Temporal;
 13#pragma warning restore IDE0130 // Namespace does not match folder structure
 14
 15public static class DateTimeOffsetExtensions
 16{
 17    extension(DateTimeOffset dateTimeOffset)
 18    {
 19        /// <summary>
 20        /// Creates a half-open <see cref="DateTimeOffsetPeriod"/> lasting the specified calendar amount.
 21        /// </summary>
 22        public DateTimeOffsetPeriod ToDateTimeOffsetPeriod(CalendarAmount amount) =>
 023            new(dateTimeOffset, dateTimeOffset.AddCalendarAmount(amount));
 24
 25        /// <summary>
 26        /// Creates a half-open <see cref="DateTimeOffsetPeriod"/> between this value and <paramref name="other"/>.
 27        /// </summary>
 28        public DateTimeOffsetPeriod ToDateTimeOffsetPeriod(DateTimeOffset other)
 29        {
 030            var start = dateTimeOffset <= other ? dateTimeOffset : other;
 031            var end = dateTimeOffset <= other ? other : dateTimeOffset;
 032            return new DateTimeOffsetPeriod(start, end);
 33        }
 34
 35        /// <summary>
 36        /// Returns a new <see cref="DateTimeOffset"/> that adds the value of the specified <see cref="CalendarAmount"/>
 37        /// Calendar components are applied as years, then months, then the fixed <see cref="TimeSpan"/>.
 38        /// </summary>
 939        public DateTimeOffset AddCalendarAmount(CalendarAmount timeSpan) => dateTimeOffset.AddYears(timeSpan.Years)
 940            .AddMonths(timeSpan.Months)
 941            .Add(timeSpan.TimeSpan);
 42
 43        /// <summary>
 44        /// Returns a new <see cref="DateTimeOffset"/> that subtracts the value of the specified <see cref="CalendarAmou
 45        /// </summary>
 646        public DateTimeOffset SubtractCalendarAmount(CalendarAmount timeSpan) => dateTimeOffset.AddYears(-timeSpan.Years
 647            .AddMonths(-timeSpan.Months)
 648            .Subtract(timeSpan.TimeSpan);
 49
 50        /// <summary>
 51        /// Returns the very end of the given day (the last millisecond of the last hour for the given <see cref="DateTi
 52        /// </summary>
 353        public DateTimeOffset EndOfDay() => new(dateTimeOffset.Year, dateTimeOffset.Month, dateTimeOffset.Day, 23, 59, 5
 54
 55        /// <summary>
 56        /// Returns the Start of the given day (the first millisecond of the given <see cref="DateTimeOffset"/>).
 57        /// </summary>
 358        public DateTimeOffset BeginningOfDay() => new(dateTimeOffset.Year, dateTimeOffset.Month, dateTimeOffset.Day, 0, 
 59
 60        /// <summary>
 61        /// Returns the same date (same Day, Month, Hour, Minute, Second etc.) in the next calendar year.
 62        /// If that day does not exist in next year in same month, number of missing days is added to the last day in sa
 63        /// </summary>
 64        public DateTimeOffset NextYear()
 65        {
 366            var nextYear = dateTimeOffset.Year + 1;
 367            var numberOfDaysInSameMonthNextYear = DateTime.DaysInMonth(nextYear, dateTimeOffset.Month);
 68
 369            if (numberOfDaysInSameMonthNextYear >= dateTimeOffset.Day)
 370                return new DateTimeOffset(nextYear, dateTimeOffset.Month, dateTimeOffset.Day, dateTimeOffset.Hour, dateT
 071            var differenceInDays = dateTimeOffset.Day - numberOfDaysInSameMonthNextYear;
 072            var dateTimeOffset1 = new DateTimeOffset(nextYear, dateTimeOffset.Month, numberOfDaysInSameMonthNextYear, da
 073            return dateTimeOffset1.AddCalendarAmount(differenceInDays.Days());
 74        }
 75
 76        /// <summary>
 77        /// Returns the same date (same Day, Month, Hour, Minute, Second etc.) in the previous calendar year.
 78        /// If that day does not exist in previous year in same month, number of missing days is added to the last day i
 79        /// </summary>
 80        public DateTimeOffset PreviousYear()
 81        {
 382            var previousYear = dateTimeOffset.Year - 1;
 383            var numberOfDaysInSameMonthPreviousYear = DateTime.DaysInMonth(previousYear, dateTimeOffset.Month);
 84
 385            if (numberOfDaysInSameMonthPreviousYear >= dateTimeOffset.Day)
 386                return new DateTimeOffset(previousYear, dateTimeOffset.Month, dateTimeOffset.Day, dateTimeOffset.Hour, d
 087            var differenceInDays = dateTimeOffset.Day - numberOfDaysInSameMonthPreviousYear;
 088            var dateTime = new DateTimeOffset(previousYear, dateTimeOffset.Month, numberOfDaysInSameMonthPreviousYear, d
 089            return dateTime.AddCalendarAmount(differenceInDays.Days());
 90        }
 91
 92        /// <summary>
 93        /// Returns <see cref="DateTimeOffset"/> increased by 24 hours ie Next Day.
 94        /// </summary>
 695        public DateTimeOffset NextDay() => dateTimeOffset.AddCalendarAmount(1.Days());
 96
 97        /// <summary>
 98        /// Returns <see cref="DateTimeOffset"/> decreased by 24h period ie Previous Day.
 99        /// </summary>
 6100        public DateTimeOffset PreviousDay() => dateTimeOffset.SubtractCalendarAmount(1.Days());
 101
 102        /// <summary>
 103        /// Returns first next occurrence of specified <see cref="DayOfWeek"/>.
 104        /// </summary>
 105        public DateTimeOffset Next(DayOfWeek day)
 106        {
 107            do
 3108                dateTimeOffset = dateTimeOffset.NextDay();
 3109            while (dateTimeOffset.DayOfWeek != day);
 110
 3111            return dateTimeOffset;
 112        }
 113
 114        /// <summary>
 115        /// Returns first next occurrence of specified <see cref="DayOfWeek"/>.
 116        /// </summary>
 117        public DateTimeOffset Previous(DayOfWeek day)
 118        {
 119            do
 3120                dateTimeOffset = dateTimeOffset.PreviousDay();
 3121            while (dateTimeOffset.DayOfWeek != day);
 122
 3123            return dateTimeOffset;
 124        }
 125
 126        /// <summary>
 127        /// Increases supplied <see cref="DateTimeOffset"/> for 7 days ie returns the Next Week.
 128        /// </summary>
 0129        public DateTimeOffset WeekAfter() => dateTimeOffset.AddCalendarAmount(1.Weeks());
 130
 131        /// <summary>
 132        /// Decreases supplied <see cref="DateTimeOffset"/> for 7 days ie returns the Previous Week.
 133        /// </summary>
 0134        public DateTimeOffset WeekEarlier() => dateTimeOffset.SubtractCalendarAmount(1.Weeks());
 135
 136        /// <summary>
 137        /// Increases the <see cref="DateTimeOffset"/> object with given <see cref="TimeSpan"/> value.
 138        /// </summary>
 0139        public DateTimeOffset IncreaseTime(TimeSpan toAdd) => dateTimeOffset + toAdd;
 140
 141        /// <summary>
 142        /// Decreases the <see cref="DateTimeOffset"/> object with given <see cref="TimeSpan"/> value.
 143        /// </summary>
 0144        public DateTimeOffset DecreaseTime(TimeSpan toSubtract) => dateTimeOffset - toSubtract;
 145
 146        /// <summary>
 147        /// Returns the original <see cref="DateTimeOffset"/> with Hour part changed to supplied hour parameter.
 148        /// </summary>
 0149        public DateTimeOffset SetTime(int hour) => new(dateTimeOffset.Year, dateTimeOffset.Month, dateTimeOffset.Day, ho
 150
 151        /// <summary>
 152        /// Returns the original <see cref="DateTimeOffset"/> with Hour and Minute parts changed to supplied hour and mi
 153        /// </summary>
 0154        public DateTimeOffset SetTime(int hour, int minute) => new(dateTimeOffset.Year, dateTimeOffset.Month, dateTimeOf
 155
 156        /// <summary>
 157        /// Returns the original <see cref="DateTimeOffset"/> with Hour, Minute and Second parts changed to supplied hou
 158        /// </summary>
 0159        public DateTimeOffset SetTime(int hour, int minute, int second) => new(dateTimeOffset.Year, dateTimeOffset.Month
 160
 161        /// <summary>
 162        /// Returns the original <see cref="DateTimeOffset"/> with Hour, Minute, Second and Millisecond parts changed to
 163        /// </summary>
 6164        public DateTimeOffset SetTime(int hour, int minute, int second, int millisecond) => new(dateTimeOffset.Year, dat
 165
 166        /// <summary>
 167        /// Returns <see cref="DateTimeOffset"/> with changed Hour part.
 168        /// </summary>
 0169        public DateTimeOffset SetHour(int hour) => new(dateTimeOffset.Year, dateTimeOffset.Month, dateTimeOffset.Day, ho
 170
 171        /// <summary>
 172        /// Returns <see cref="DateTimeOffset"/> with changed Minute part.
 173        /// </summary>
 0174        public DateTimeOffset SetMinute(int minute) => new(dateTimeOffset.Year, dateTimeOffset.Month, dateTimeOffset.Day
 175
 176        /// <summary>
 177        /// Returns <see cref="DateTimeOffset"/> with changed Second part.
 178        /// </summary>
 0179        public DateTimeOffset SetSecond(int second) => new(dateTimeOffset.Year, dateTimeOffset.Month, dateTimeOffset.Day
 180
 181        /// <summary>
 182        /// Returns <see cref="DateTimeOffset"/> with changed Millisecond part.
 183        /// </summary>
 0184        public DateTimeOffset SetMillisecond(int millisecond) => new(dateTimeOffset.Year, dateTimeOffset.Month, dateTime
 185
 186        /// <summary>
 187        /// Returns original <see cref="DateTimeOffset"/> value with time part set to midnight (alias for <see cref="Beg
 188        /// </summary>
 0189        public DateTimeOffset Midnight() => dateTimeOffset.BeginningOfDay();
 190
 191        /// <summary>
 192        /// Returns original <see cref="DateTimeOffset"/> value with time part set to Noon (12:00:00h).
 193        /// </summary>
 194        /// <returns>A <see cref="DateTimeOffset"/> value with time part set to Noon (12:00:00h).</returns>
 3195        public DateTimeOffset Noon() => dateTimeOffset.SetTime(12, 0, 0, 0);
 196
 197        /// <summary>
 198        /// Returns <see cref="DateTimeOffset"/> with changed Year part.
 199        /// </summary>
 0200        public DateTimeOffset SetDate(int year) => new(year, dateTimeOffset.Month, dateTimeOffset.Day, dateTimeOffset.Ho
 201
 202        /// <summary>
 203        /// Returns <see cref="DateTimeOffset"/> with changed Year and Month part.
 204        /// </summary>
 0205        public DateTimeOffset SetDate(int year, int month) => new(year, month, dateTimeOffset.Day, dateTimeOffset.Hour, 
 206
 207        /// <summary>
 208        /// Returns <see cref="DateTimeOffset"/> with changed Year, Month and Day part.
 209        /// </summary>
 12210        public DateTimeOffset SetDate(int year, int month, int day) => new(year, month, day, dateTimeOffset.Hour, dateTi
 211
 212        /// <summary>
 213        /// Returns <see cref="DateTimeOffset"/> with changed Year part.
 214        /// </summary>
 0215        public DateTimeOffset SetYear(int year) => new(year, dateTimeOffset.Month, dateTimeOffset.Day, dateTimeOffset.Ho
 216
 217        /// <summary>
 218        /// Returns <see cref="DateTimeOffset"/> with changed Month part.
 219        /// </summary>
 0220        public DateTimeOffset SetMonth(int month) => new(dateTimeOffset.Year, month, dateTimeOffset.Day, dateTimeOffset.
 221
 222        /// <summary>
 223        /// Returns <see cref="DateTimeOffset"/> with changed Day part.
 224        /// </summary>
 18225        public DateTimeOffset SetDay(int day) => new(dateTimeOffset.Year, dateTimeOffset.Month, day, dateTimeOffset.Hour
 226
 227        /// <summary>
 228        /// Returns the given <see cref="DateTimeOffset"/> with hour and minutes set At given values.
 229        /// </summary>
 230        /// <param name="hour">The hour to set time to.</param>
 231        /// <param name="minute">The minute to set time to.</param>
 232        /// <returns><see cref="DateTimeOffset"/> with hour and minute set to given values.</returns>
 0233        public DateTimeOffset At(int hour, int minute) => dateTimeOffset.SetTime(hour, minute);
 234
 235        /// <summary>
 236        /// Returns the given <see cref="DateTimeOffset"/> with hour and minutes and seconds set At given values.
 237        /// </summary>
 238        /// <param name="hour">The hour to set time to.</param>
 239        /// <param name="minute">The minute to set time to.</param>
 240        /// <param name="second">The second to set time to.</param>
 241        /// <returns><see cref="DateTimeOffset"/> with hour and minutes and seconds set to given values.</returns>
 0242        public DateTimeOffset At(int hour, int minute, int second) => dateTimeOffset.SetTime(hour, minute, second);
 243
 244        /// <summary>
 245        /// Returns the given <see cref="DateTimeOffset"/> with hour and minutes and seconds and milliseconds set At giv
 246        /// </summary>
 247        /// <param name="hour">The hour to set time to.</param>
 248        /// <param name="minute">The minute to set time to.</param>
 249        /// <param name="second">The second to set time to.</param>
 250        /// <param name="milliseconds">The milliseconds to set time to.</param>
 251        /// <returns><see cref="DateTimeOffset"/> with hour and minutes and seconds set to given values.</returns>
 0252        public DateTimeOffset At(int hour, int minute, int second, int milliseconds) => dateTimeOffset.SetTime(hour, min
 253
 254        /// <summary>
 255        /// Sets the day of the <see cref="DateTimeOffset"/> to the first day in that calendar quarter.
 256        /// credit to http://www.devcurry.com/2009/05/find-first-and-last-day-of-current.html.
 257        /// </summary>
 258        /// <returns>given <see cref="DateTimeOffset"/> with the day part set to the first day in the quarter.</returns>
 259        public DateTimeOffset FirstDayOfQuarter()
 260        {
 0261            var currentQuarter = ((dateTimeOffset.Month - 1) / 3) + 1;
 0262            return dateTimeOffset.SetDate(dateTimeOffset.Year, (3 * currentQuarter) - 2, 1);
 263        }
 264
 265        /// <summary>
 266        /// Sets the day of the <see cref="DateTimeOffset"/> to the first day in that month.
 267        /// </summary>
 268        /// <returns>given <see cref="DateTimeOffset"/> with the day part set to the first day in that month.</returns>
 3269        public DateTimeOffset FirstDayOfMonth() => dateTimeOffset.SetDay(1);
 270
 271        /// <summary>
 272        /// Sets the day of the <see cref="DateTimeOffset"/> to the last day in that calendar quarter.
 273        /// credit to http://www.devcurry.com/2009/05/find-first-and-last-day-of-current.html.
 274        /// </summary>
 275        /// <returns>given <see cref="DateTimeOffset"/> with the day part set to the last day in the quarter.</returns>
 276        public DateTimeOffset LastDayOfQuarter()
 277        {
 0278            var currentQuarter = ((dateTimeOffset.Month - 1) / 3) + 1;
 0279            var firstDay = dateTimeOffset.SetDate(dateTimeOffset.Year, (3 * currentQuarter) - 2, 1);
 0280            return firstDay.SetMonth(firstDay.Month + 2).LastDayOfMonth();
 281        }
 282
 283        /// <summary>
 284        /// Sets the day of the <see cref="DateTimeOffset"/> to the last day in that month.
 285        /// </summary>
 286        /// <returns>given <see cref="DateTimeOffset"/> with the day part set to the last day in that month.</returns>
 9287        public DateTimeOffset LastDayOfMonth() => dateTimeOffset.SetDay(DateTime.DaysInMonth(dateTimeOffset.Year, dateTi
 288
 289        /// <summary>
 290        /// Adds the given number of business days to the <see cref="DateTimeOffset"/>.
 291        /// </summary>
 292        /// <param name="days">Number of business days to be added.</param>
 293        /// <returns>A <see cref="DateTimeOffset"/> increased by a given number of business days.</returns>
 294        public DateTimeOffset AddBusinessDays(int days)
 295        {
 3296            var sign = Math.Sign(days);
 3297            var unsignedDays = Math.Abs(days);
 12298            for (var i = 0; i < unsignedDays; i++)
 299            {
 300                do
 9301                    dateTimeOffset = dateTimeOffset.AddDays(sign);
 9302                while (dateTimeOffset.DayOfWeek is DayOfWeek.Saturday or DayOfWeek.Sunday);
 303            }
 304
 3305            return dateTimeOffset;
 306        }
 307
 308        /// <summary>
 309        /// Subtracts the given number of business days to the <see cref="DateTimeOffset"/>.
 310        /// </summary>
 311        /// <param name="days">Number of business days to be subtracted.</param>
 312        /// <returns>A <see cref="DateTimeOffset"/> increased by a given number of business days.</returns>
 0313        public DateTimeOffset SubtractBusinessDays(int days) => dateTimeOffset.AddBusinessDays(-days);
 314
 315        /// <summary>
 316        /// Determine if a <see cref="DateTimeOffset"/> is in the future.
 317        /// </summary>
 318        /// <returns><c>true</c> if <paramref name="dateTimeOffset"/> is in the future; otherwise <c>false</c>.</returns
 3319        public bool IsInFuture() => dateTimeOffset > DateTimeOffset.Now;
 320
 321        /// <summary>
 322        /// Determine if a <see cref="DateTimeOffset"/> is in the past.
 323        /// </summary>
 324        /// <returns><c>true</c> if <paramref name="dateTimeOffset"/> is in the past; otherwise <c>false</c>.</returns>
 3325        public bool IsInPast() => dateTimeOffset < DateTimeOffset.Now;
 326
 327        /// <summary>
 328        /// Rounds <paramref name="dateTimeOffset"/> to the nearest <see cref="RoundTo"/>.
 329        /// </summary>
 330        /// <returns>The rounded <see cref="DateTimeOffset"/>.</returns>
 331        public DateTimeOffset Round(RoundTo rt)
 332        {
 333            DateTimeOffset rounded;
 334
 335            switch (rt)
 336            {
 337                case RoundTo.Second:
 338                    {
 0339                        rounded = new DateTimeOffset(dateTimeOffset.Year, dateTimeOffset.Month, dateTimeOffset.Day, date
 0340                        if (dateTimeOffset.Millisecond >= 500)
 0341                            rounded = rounded.AddSeconds(1);
 0342                        break;
 343                    }
 344
 345                case RoundTo.Minute:
 346                    {
 3347                        rounded = new DateTimeOffset(dateTimeOffset.Year, dateTimeOffset.Month, dateTimeOffset.Day, date
 3348                        if (dateTimeOffset.Second >= 30)
 3349                            rounded = rounded.AddMinutes(1);
 3350                        break;
 351                    }
 352
 353                case RoundTo.Hour:
 354                    {
 0355                        rounded = new DateTimeOffset(dateTimeOffset.Year, dateTimeOffset.Month, dateTimeOffset.Day, date
 0356                        if (dateTimeOffset.Minute >= 30)
 0357                            rounded = rounded.AddHours(1);
 0358                        break;
 359                    }
 360
 361                case RoundTo.Day:
 362                    {
 0363                        rounded = new DateTimeOffset(dateTimeOffset.Year, dateTimeOffset.Month, dateTimeOffset.Day, 0, 0
 0364                        if (dateTimeOffset.Hour >= 12)
 0365                            rounded = rounded.AddDays(1);
 0366                        break;
 367                    }
 368
 369                default:
 370                    {
 0371                        throw new ArgumentOutOfRangeException(nameof(rt));
 372                    }
 373            }
 374
 3375            return rounded;
 376        }
 377
 378        /// <summary>
 379        /// Returns a DateTimeOffset adjusted to the beginning of the week.
 380        /// </summary>
 381        /// <returns>A DateTimeOffset instance adjusted to the beginning of the current week.</returns>
 382        /// <remarks>the beginning of the week is controlled by the current Culture.</remarks>
 383        public DateTimeOffset FirstDayOfWeek()
 384        {
 6385            var currentCulture = CultureInfo.CurrentCulture;
 6386            var firstDayOfWeek = currentCulture.DateTimeFormat.FirstDayOfWeek;
 6387            var offset = dateTimeOffset.DayOfWeek < firstDayOfWeek ? 7 : 0;
 6388            var numberOfDaysSinceBeginningOfTheWeek = dateTimeOffset.DayOfWeek + offset - firstDayOfWeek;
 389
 6390            return dateTimeOffset.AddDays(-numberOfDaysSinceBeginningOfTheWeek);
 391        }
 392
 393        /// <summary>
 394        /// Returns the first day of the year keeping the time component intact. Eg, 2011-02-04T06:40:20.005 => 2011-01-
 395        /// </summary>
 3396        public DateTimeOffset FirstDayOfYear() => dateTimeOffset.SetDate(dateTimeOffset.Year, 1, 1);
 397
 398        /// <summary>
 399        /// Returns the last day of the week keeping the time component intact. Eg, 2011-12-24T06:40:20.005 => 2011-12-2
 400        /// </summary>
 3401        public DateTimeOffset LastDayOfWeek() => dateTimeOffset.FirstDayOfWeek().AddDays(6);
 402
 403        /// <summary>
 404        /// Returns the last day of the year keeping the time component intact. Eg, 2011-12-24T06:40:20.005 => 2011-12-3
 405        /// </summary>
 3406        public DateTimeOffset LastDayOfYear() => dateTimeOffset.SetDate(dateTimeOffset.Year, 12, 31);
 407
 408        /// <summary>
 409        /// Returns the previous month keeping the time component intact. Eg, 2010-01-20T06:40:20.005 => 2009-12-20T06:4
 410        /// If the previous month doesn't have that many days the last day of the previous month is used. Eg, 2009-03-31
 411        /// </summary>
 412        public DateTimeOffset PreviousMonth()
 413        {
 3414            var year = dateTimeOffset.Month == 1 ? dateTimeOffset.Year - 1 : dateTimeOffset.Year;
 415
 3416            var month = dateTimeOffset.Month == 1 ? 12 : dateTimeOffset.Month - 1;
 417
 3418            var firstDayOfPreviousMonth = dateTimeOffset.SetDate(year, month, 1);
 419
 3420            var lastDayOfPreviousMonth = firstDayOfPreviousMonth.LastDayOfMonth().Day;
 421
 3422            var day = dateTimeOffset.Day > lastDayOfPreviousMonth ? lastDayOfPreviousMonth : dateTimeOffset.Day;
 423
 3424            return firstDayOfPreviousMonth.SetDay(day);
 425        }
 426
 427        /// <summary>
 428        /// Returns the next month keeping the time component intact. Eg, 2012-12-05T06:40:20.005 => 2013-01-05T06:40:20
 429        /// If the next month doesn't have that many days the last day of the next month is used. Eg, 2013-01-31T06:40:2
 430        /// </summary>
 431        public DateTimeOffset NextMonth()
 432        {
 3433            var year = dateTimeOffset.Month == 12 ? dateTimeOffset.Year + 1 : dateTimeOffset.Year;
 434
 3435            var month = dateTimeOffset.Month == 12 ? 1 : dateTimeOffset.Month + 1;
 436
 3437            var firstDayOfNextMonth = dateTimeOffset.SetDate(year, month, 1);
 438
 3439            var lastDayOfPreviousMonth = firstDayOfNextMonth.LastDayOfMonth().Day;
 440
 3441            var day = dateTimeOffset.Day > lastDayOfPreviousMonth ? lastDayOfPreviousMonth : dateTimeOffset.Day;
 442
 3443            return firstDayOfNextMonth.SetDay(day);
 444        }
 445
 446        /// <summary>
 447        /// Determines whether the specified <see cref="DateTimeOffset"/> value is exactly the same day (day + month + y
 448        /// </summary>
 449        /// <param name="date">Value to compare with.</param>
 450        /// <returns>
 451        ///     <c>true</c> if the specified date is exactly the same year then current; otherwise, <c>false</c>.
 452        /// </returns>
 3453        public bool SameDay(DateTimeOffset date) => dateTimeOffset.Date == date.Date;
 454
 455        /// <summary>
 456        /// Determines whether the specified <see cref="DateTimeOffset"/> value is exactly the same month (month + year)
 457        /// </summary>
 458        /// <param name="date">Value to compare with.</param>
 459        /// <returns>
 460        ///     <c>true</c> if the specified date is exactly the same month and year then current; otherwise, <c>false</
 461        /// </returns>
 3462        public bool SameMonth(DateTimeOffset date) => dateTimeOffset.Month == date.Month && dateTimeOffset.Year == date.
 463
 464        /// <summary>
 465        /// Determines whether the specified <see cref="DateTimeOffset"/> value is exactly the same year then current. E
 466        /// </summary>
 467        /// <param name="date">Value to compare with.</param>
 468        /// <returns>
 469        ///     <c>true</c> if the specified date is exactly the same date then current; otherwise, <c>false</c>.
 470        /// </returns>
 3471        public bool SameYear(DateTimeOffset date) => dateTimeOffset.Year == date.Year;
 472    }
 473}
 474

Methods/Properties

ToDateTimeOffsetPeriod(System.DateTimeOffset,MyNet.Temporal.CalendarAmount)
ToDateTimeOffsetPeriod(System.DateTimeOffset,System.DateTimeOffset)
AddCalendarAmount(System.DateTimeOffset,MyNet.Temporal.CalendarAmount)
SubtractCalendarAmount(System.DateTimeOffset,MyNet.Temporal.CalendarAmount)
EndOfDay(System.DateTimeOffset)
BeginningOfDay(System.DateTimeOffset)
NextYear(System.DateTimeOffset)
PreviousYear(System.DateTimeOffset)
NextDay(System.DateTimeOffset)
PreviousDay(System.DateTimeOffset)
Next(System.DateTimeOffset,System.DayOfWeek)
Previous(System.DateTimeOffset,System.DayOfWeek)
WeekAfter(System.DateTimeOffset)
WeekEarlier(System.DateTimeOffset)
IncreaseTime(System.DateTimeOffset,System.TimeSpan)
DecreaseTime(System.DateTimeOffset,System.TimeSpan)
SetTime(System.DateTimeOffset,System.Int32)
SetTime(System.DateTimeOffset,System.Int32,System.Int32)
SetTime(System.DateTimeOffset,System.Int32,System.Int32,System.Int32)
SetTime(System.DateTimeOffset,System.Int32,System.Int32,System.Int32,System.Int32)
SetHour(System.DateTimeOffset,System.Int32)
SetMinute(System.DateTimeOffset,System.Int32)
SetSecond(System.DateTimeOffset,System.Int32)
SetMillisecond(System.DateTimeOffset,System.Int32)
Midnight(System.DateTimeOffset)
Noon(System.DateTimeOffset)
SetDate(System.DateTimeOffset,System.Int32)
SetDate(System.DateTimeOffset,System.Int32,System.Int32)
SetDate(System.DateTimeOffset,System.Int32,System.Int32,System.Int32)
SetYear(System.DateTimeOffset,System.Int32)
SetMonth(System.DateTimeOffset,System.Int32)
SetDay(System.DateTimeOffset,System.Int32)
At(System.DateTimeOffset,System.Int32,System.Int32)
At(System.DateTimeOffset,System.Int32,System.Int32,System.Int32)
At(System.DateTimeOffset,System.Int32,System.Int32,System.Int32,System.Int32)
FirstDayOfQuarter(System.DateTimeOffset)
FirstDayOfMonth(System.DateTimeOffset)
LastDayOfQuarter(System.DateTimeOffset)
LastDayOfMonth(System.DateTimeOffset)
AddBusinessDays(System.DateTimeOffset,System.Int32)
SubtractBusinessDays(System.DateTimeOffset,System.Int32)
IsInFuture(System.DateTimeOffset)
IsInPast(System.DateTimeOffset)
Round(System.DateTimeOffset,MyNet.Temporal.RoundTo)
FirstDayOfWeek(System.DateTimeOffset)
FirstDayOfYear(System.DateTimeOffset)
LastDayOfWeek(System.DateTimeOffset)
LastDayOfYear(System.DateTimeOffset)
PreviousMonth(System.DateTimeOffset)
NextMonth(System.DateTimeOffset)
SameDay(System.DateTimeOffset,System.DateTimeOffset)
SameMonth(System.DateTimeOffset,System.DateTimeOffset)
SameYear(System.DateTimeOffset,System.DateTimeOffset)