当前位置: 首页>>代码示例>>C#>>正文


C# DateTime.EndOfMonth方法代码示例

本文整理汇总了C#中System.DateTime.EndOfMonth方法的典型用法代码示例。如果您正苦于以下问题:C# DateTime.EndOfMonth方法的具体用法?C# DateTime.EndOfMonth怎么用?C# DateTime.EndOfMonth使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.DateTime的用法示例。


在下文中一共展示了DateTime.EndOfMonth方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetJob_JobsToDateAndFromDateDifferent_ReturnAllJobs

        public void GetJob_JobsToDateAndFromDateDifferent_ReturnAllJobs(
            [Frozen] Mock<IZohoClient> zohoClient,
            JobService target)
        {
            var startFirst = new DateTime(2015, 07, 01);
            var endFirst = startFirst.EndOfMonth();

            var startSecond = new DateTime(2015, 08, 01);
            var endSecond = startSecond.EndOfMonth();

            var job1 = new Job { JobId = "1", FromDate = startFirst, ToDate = endFirst };
            var job2 = new Job { JobId = "2", FromDate = startSecond, ToDate = endSecond };

            zohoClient.Setup(x => x.TimeTracker.Jobs.GetAsync()).ReturnsAsync(new List<Job> { job1, job2 });

            // Act
            var firstJobId1 = target.GetJob(startFirst).Result;
            var firstJobId2 = target.GetJob(endFirst).Result;

            var secondJobId1 = target.GetJob(startSecond).Result;
            var secondJobId2 = target.GetJob(endSecond).Result;

            // Assert
            zohoClient.Verify(x => x.TimeTracker.Jobs.GetAsync(), Times.Exactly(4));

            Assert.Equal(job1.JobId, firstJobId1);
            Assert.Equal(job1.JobId, firstJobId2);

            Assert.Equal(job2.JobId, secondJobId1);
            Assert.Equal(job2.JobId, secondJobId2);
        }
开发者ID:drussilla,项目名称:ZohoPeopleTimeLogger,代码行数:31,代码来源:JobServiceTests.cs

示例2: MsMonth

 /// <summary>
 /// creates a new msMonth object for the month containing the date
 /// </summary>
 /// <param name="date">date within the month</param>
 public MsMonth(DateTime date)
 {
     #if NET20
     StartDate = MsDateHelpers.StartOfMonth(date);
     EndDate = MsDateHelpers.EndOfMonth(date);
     #else
     StartDate = date.StartOfMonth();
     EndDate = date.EndOfMonth();
     #endif
 }
开发者ID:pdesterlich,项目名称:msUtilities,代码行数:14,代码来源:msMonth.cs

示例3: EndOfMonth

        public void EndOfMonth()
        {
            // Type
            var @this = new DateTime(2013, 12, 22);

            // Examples
            DateTime value = @this.EndOfMonth(); // value = "2013/12/31 23:59:59:999";

            // Unit Test
            Assert.AreEqual(new DateTime(2013, 12, 31, 23, 59, 59, 999), value);
        }
开发者ID:ChuangYang,项目名称:Z.ExtensionMethods,代码行数:11,代码来源:DateTime.EndOfMonth.cs

示例4: EndOfMonth

        public void EndOfMonth()
        {
            var end = new DateTime(2011, 1, 31);
            Assert.AreEqual(end, end.AddDays(-2).EndOfMonth());
            Assert.AreEqual(end, new DateTime(2011, 1, 1).EndOfMonth());
            Assert.AreEqual(end, end.EndOfMonth());

            Assert.AreEqual(new DateTime(2012, 2, 29), new DateTime(2012, 2, 1).EndOfMonth());

            Assert.AreNotEqual(end, end.AddMonths(1).EndOfMonth());
            Assert.AreNotEqual(end, end.AddMonths(-1).EndOfMonth());
        }
开发者ID:TrinityWestern,项目名称:Nvelope,代码行数:12,代码来源:DateTimeExtensionTests.cs

示例5: GetDays

        public List<IDayViewModel> GetDays(DateTime month)
        {
            var startOfMonth = month.BeginOfMonth();
            var endOfMonth = month.EndOfMonth();
            
            var days = new List<IDayViewModel>();

            int firstDayOfMonthIndex = (int)startOfMonth.DayOfWeek - 1;
            int currentMonthDay = 1;

            if (startOfMonth.DayOfWeek == DayOfWeek.Sunday)
            {
                currentMonthDay++;
                firstDayOfMonthIndex = 0;
            }
            else if (startOfMonth.DayOfWeek == DayOfWeek.Saturday)
            {
                currentMonthDay += 2;
                firstDayOfMonthIndex = 0;
            }

            for (int dayIndexInTable = 0; dayIndexInTable < TotalDaysInATable; dayIndexInTable++)
            {
                if (dayIndexInTable >= firstDayOfMonthIndex)
                {
                    if (currentMonthDay > endOfMonth.Day)
                    {
                        days.Add(DayViewModel.DayFromOtherMonth(zohoClient));
                    }
                    else
                    {
                        days.Add(DayViewModel.DayFromThisMonth(currentMonthDay, month, zohoClient));

                        if (IsWeekEnded(dayIndexInTable))
                        {
                            currentMonthDay += 3;
                        }
                        else
                        {
                            currentMonthDay++;
                        }
                    }
                }
                else
                {
                    days.Add(DayViewModel.DayFromOtherMonth(zohoClient));
                }
            }

            return days;
        }
开发者ID:drussilla,项目名称:ZohoPeopleTimeLogger,代码行数:51,代码来源:DaysService.cs

示例6: GetJob_JobsIntersect_UseJobWithLaterToDate

        public void GetJob_JobsIntersect_UseJobWithLaterToDate(
            [Frozen] Mock<IZohoClient> zohoClient,
            JobService target)
        {
            var startFirst = new DateTime(2015, 07, 01);
            var endFirst = startFirst.EndOfMonth();

            var startSecond = new DateTime(2015, 07, 15);
            var endSecond = startSecond.AddMonths(1).EndOfMonth();

            var job1 = new Job { JobId = "1", FromDate = startFirst, ToDate = endFirst };
            var job2 = new Job { JobId = "2", FromDate = startSecond, ToDate = endSecond };

            zohoClient.Setup(x => x.TimeTracker.Jobs.GetAsync()).ReturnsAsync(new List<Job> { job1, job2 });

            // Act
            var jobId = target.GetJob(startSecond.AddDays(1)).Result;

            // Assert
            zohoClient.Verify(x => x.TimeTracker.Jobs.GetAsync(), Times.Once);

            Assert.Equal(job2.JobId, jobId);
        }
开发者ID:drussilla,项目名称:ZohoPeopleTimeLogger,代码行数:23,代码来源:JobServiceTests.cs

示例7: EndOfMonthWithCalendarShouldReturnExpectedResult

 public void EndOfMonthWithCalendarShouldReturnExpectedResult()
 {
     var date = new DateTime( 2013, 3, 1 );
     var calendar = new GregorianFiscalCalendar( 7 );
     var expected = new DateTime( 2013, 3, 31 );
     var actual = date.EndOfMonth( calendar );
     Assert.Equal( expected.Date, actual.Date );
 }
开发者ID:WaffleSquirrel,项目名称:More,代码行数:8,代码来源:DateTimeExtensionsTest.cs

示例8: FillTimeLogs

        private async Task FillTimeLogs(List<IDayViewModel> days, DateTime month)
        {
            var timeLogs = await zohoClient.TimeTracker.TimeLog.GetAsync(
                auth.GetAuthenticationData().Id,
                month.BeginOfMonth(),
                month.EndOfMonth());

            if (timeLogs == null || !timeLogs.Any())
            {
                return;
            }

            var groupedByDate = timeLogs.GroupBy(x => x.WorkDate);

            foreach (var itemsInLog in groupedByDate)
            {
                var dayToFill = days.FirstOrDefault(x => x.Day == itemsInLog.Key.Day);
                if (dayToFill != null)
                {
                    dayToFill.FillLogs(itemsInLog.ToList());
                }
            }
        }
开发者ID:drussilla,项目名称:ZohoPeopleTimeLogger,代码行数:23,代码来源:DaysService.cs

示例9: EndOfMonthShouldReturnExpectedResult

 public void EndOfMonthShouldReturnExpectedResult()
 {
     var date = new DateTime( 2013, 3, 1 );
     var expected = new DateTime( 2013, 3, 31 );
     var actual = date.EndOfMonth();
     Assert.Equal( expected.Date, actual.Date );
 }
开发者ID:WaffleSquirrel,项目名称:More,代码行数:7,代码来源:DateTimeExtensionsTest.cs

示例10: GetExpectedEmployeeMonthlyAliases

        private string GetExpectedEmployeeMonthlyAliases(DailyIndex index, DateTime utcNow, DateTime indexDateUtc) {
            var aliases = new List<string> { index.Name, index.GetIndex(indexDateUtc) };
            if (new DateTimeRange(utcNow.SubtractDays(1).StartOfMonth(), utcNow.EndOfMonth()).Contains(indexDateUtc))
                aliases.Add($"{index.Name}-today");

            if (new DateTimeRange(utcNow.SubtractDays(7).StartOfMonth(), utcNow.EndOfMonth()).Contains(indexDateUtc))
                aliases.Add($"{index.Name}-last7days");

            if (new DateTimeRange(utcNow.SubtractDays(30).StartOfMonth(), utcNow.EndOfMonth()).Contains(indexDateUtc))
                aliases.Add($"{index.Name}-last30days");

            if (new DateTimeRange(utcNow.SubtractDays(60).StartOfMonth(), utcNow.EndOfMonth()).Contains(indexDateUtc))
                aliases.Add($"{index.Name}-last60days");

            aliases.Sort();
            return String.Join(", ", aliases);
        }
开发者ID:exceptionless,项目名称:Foundatio.Repositories,代码行数:17,代码来源:IndexTests.cs

示例11: FillDays_TimeLogRecieved_FilledWithCorrectValues

        public async void FillDays_TimeLogRecieved_FilledWithCorrectValues(
            [Frozen] Mock<IZohoClient> zoho,
            [Frozen] Mock<IAuthenticationStorage> auth,
            AuthenticationData authData,
            DaysService target)
        {
            var startOfTheMonth = new DateTime(2015, 07, 01);
            var middleOfTheMonth = new DateTime(2015, 07, 15);
            var endOfTheMonth = startOfTheMonth.EndOfMonth();
            
            var firstLog = new TimeLog { WorkDate = startOfTheMonth, Hours = TimeSpan.FromHours(8) };
            var secondLog1 = new TimeLog { WorkDate = middleOfTheMonth, Hours = TimeSpan.FromHours(2) };
            var secondLog2 = new TimeLog { WorkDate = middleOfTheMonth, Hours = TimeSpan.FromHours(12) };
            var thirdLog = new TimeLog { WorkDate = endOfTheMonth, Hours = TimeSpan.FromHours(10) };

            var timeLogs = new List<TimeLog>
            {
                firstLog,
                secondLog1,
                secondLog2,
                thirdLog
            };

            auth.Setup(x => x.GetAuthenticationData())
                .Returns(authData);
            var days = target.GetDays(startOfTheMonth);

            zoho.Setup(x => x.TimeTracker.TimeLog.GetAsync(authData.Id, startOfTheMonth, endOfTheMonth, "all", "all"))
                .ReturnsAsync(timeLogs);
            
            // Act
            await target.FillDaysWithTimeLogsAsync(days, startOfTheMonth);

            // Assert
            zoho.Verify(x => x.TimeTracker.TimeLog.GetAsync(authData.Id, startOfTheMonth, endOfTheMonth, "all", "all"));
            zoho.Verify(x => x.Leave.GetHolidaysAsync(authData.Id));
            
            var firstDayInCalendar = days.First(x => x.Day == startOfTheMonth.Day);
            Assert.True(firstDayInCalendar.IsActive);
            Assert.True(firstDayInCalendar.IsFilled);
            Assert.Equal(TimeSpan.FromHours(8), firstDayInCalendar.Hours);
            Assert.False(firstDayInCalendar.IsHoliday);
            
            var secondDayInCalendar = days.First(x => x.Day == middleOfTheMonth.Day);
            Assert.True(secondDayInCalendar.IsActive);
            Assert.True(secondDayInCalendar.IsFilled);
            Assert.Equal(TimeSpan.FromHours(14), secondDayInCalendar.Hours);
            Assert.False(secondDayInCalendar.IsHoliday);
            
            var secondMiddleDayInCalendar = days.First(x => x.Day == middleOfTheMonth.Day + 1);
            Assert.False(secondMiddleDayInCalendar.IsHoliday);
            
            var thirdDayInMonth = days.First(x => x.Day == endOfTheMonth.Day);
            Assert.True(thirdDayInMonth.IsActive);
            Assert.True(thirdDayInMonth.IsFilled);
            Assert.Equal(TimeSpan.FromHours(10), thirdDayInMonth.Hours);
            Assert.False(thirdDayInMonth.IsHoliday);
            Assert.Null(thirdDayInMonth.HolidayName);

            var notFilledDay = days.First(x => x.Day == 2);
            Assert.True(notFilledDay.IsActive);
            Assert.False(notFilledDay.IsFilled);
        }
开发者ID:drussilla,项目名称:ZohoPeopleTimeLogger,代码行数:63,代码来源:DayServiceTests.cs

示例12: FillDays_HolidaysRecieved_FilledWithCorrectValues

        public async void FillDays_HolidaysRecieved_FilledWithCorrectValues(
            [Frozen] Mock<IZohoClient> zoho,
            [Frozen] Mock<IAuthenticationStorage> auth,
            AuthenticationData authData,
            DaysService target)
        {
            var startOfTheMonth = new DateTime(2015, 07, 01);
            var middleOfTheMonth = new DateTime(2015, 07, 15);
            var endOfTheMonth = startOfTheMonth.EndOfMonth();

            var singleDayyOffHoliday = new Holiday
            {
                FromDate = startOfTheMonth,
                ToDate = startOfTheMonth,
                Name = "singleHoliday",
                Remarks = DaysService.DayOffHolidayRemark
            };

            var singleDayNotOffHoliday = new Holiday
            {
                FromDate = endOfTheMonth,
                ToDate = endOfTheMonth,
                Name = "singleNoDayOffHoliday",
                Remarks = "Could be given off."
            };

            var coupleDaysHoliday = new Holiday
            {
                FromDate = middleOfTheMonth,
                ToDate = middleOfTheMonth.AddDays(1),
                Name = "twoDays",
                Remarks = DaysService.DayOffHolidayRemark
            };

            var holidays = new List<Holiday>
            {
                singleDayyOffHoliday,
                singleDayNotOffHoliday,
                coupleDaysHoliday
            };

            
            auth.Setup(x => x.GetAuthenticationData())
                .Returns(authData);
            var days = target.GetDays(startOfTheMonth);

            zoho.Setup(x => x.Leave.GetHolidaysAsync(It.IsAny<string>())).ReturnsAsync(holidays);

            // Act
            await target.FillDaysWithTimeLogsAsync(days, startOfTheMonth);

            // Assert
            zoho.Verify(x => x.Leave.GetHolidaysAsync(authData.Id));

            var firstDayInCalendar = days.First(x => x.Day == startOfTheMonth.Day);
            Assert.True(firstDayInCalendar.IsHoliday);
            Assert.Equal(singleDayyOffHoliday.Name, firstDayInCalendar.HolidayName);

            var secondDayInCalendar = days.First(x => x.Day == middleOfTheMonth.Day);
            Assert.True(secondDayInCalendar.IsHoliday);
            Assert.Equal(coupleDaysHoliday.Name, secondDayInCalendar.HolidayName);

            var secondMiddleDayInCalendar = days.First(x => x.Day == middleOfTheMonth.Day + 1);
            Assert.True(secondMiddleDayInCalendar.IsHoliday);
            Assert.Equal(coupleDaysHoliday.Name, secondMiddleDayInCalendar.HolidayName);

            var thirdDayInMonth = days.First(x => x.Day == endOfTheMonth.Day);
            Assert.False(thirdDayInMonth.IsHoliday);
            Assert.Null(thirdDayInMonth.HolidayName);
        }
开发者ID:drussilla,项目名称:ZohoPeopleTimeLogger,代码行数:70,代码来源:DayServiceTests.cs

示例13: EndOfMonth__The_End_Of_The_Month_Can_Be_Obtained

 public void EndOfMonth__The_End_Of_The_Month_Can_Be_Obtained()
 {
     var date = new DateTime(2000, 1, 1);
     var endOfMonth = date.EndOfMonth();
     Assert.IsTrue(endOfMonth == new DateTime(2000, 1, 31));
 }
开发者ID:ThoughtDrive,项目名称:XtensionMethods,代码行数:6,代码来源:DateTime.cs

示例14: EndOfMonth

        public static DateTime EndOfMonth( this Calendar calendar, DateTime date )
        {
            Arg.NotNull( calendar, nameof( calendar ) );
            Contract.Ensures( calendar.GetYear( Contract.Result<DateTime>() ) == Contract.OldValue( calendar.GetYear( date ) ) );
            Contract.Ensures( calendar.GetMonth( Contract.Result<DateTime>() ) == Contract.OldValue( calendar.GetMonth( date ) ) );

            return date.EndOfMonth( calendar );
        }
开发者ID:WaffleSquirrel,项目名称:More,代码行数:8,代码来源:CalendarExtensions.cs


注:本文中的System.DateTime.EndOfMonth方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。