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


C# DateInterval类代码示例

本文整理汇总了C#中DateInterval的典型用法代码示例。如果您正苦于以下问题:C# DateInterval类的具体用法?C# DateInterval怎么用?C# DateInterval使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: DateAdd

        public static DateTime DateAdd(DateInterval Interval, double Number, DateTime DateValue)
        {
            int years = (int) Math.Round(Conversion.Fix(Number));
            switch (Interval)
            {
                case DateInterval.Year:
                    return CurrentCalendar.AddYears(DateValue, years);

                case DateInterval.Quarter:
                    return DateValue.AddMonths(years * 3);

                case DateInterval.Month:
                    return CurrentCalendar.AddMonths(DateValue, years);

                case DateInterval.DayOfYear:
                case DateInterval.Day:
                case DateInterval.Weekday:
                    return DateValue.AddDays((double) years);

                case DateInterval.WeekOfYear:
                    return DateValue.AddDays(years * 7.0);

                case DateInterval.Hour:
                    return DateValue.AddHours((double) years);

                case DateInterval.Minute:
                    return DateValue.AddMinutes((double) years);

                case DateInterval.Second:
                    return DateValue.AddSeconds((double) years);
            }
            throw new ArgumentException(Utils.GetResourceString("Argument_InvalidValue1", new string[] { "Interval" }));
        }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:33,代码来源:DateAndTime.cs

示例2: CompareTo_DateIntervalWithSameStartAndSameEndDates_ReturnsZero

        public void CompareTo_DateIntervalWithSameStartAndSameEndDates_ReturnsZero()
        {
            // Arrange
            var dateInterval1 = new DateInterval(now, inOneHour);
            var dateInterval2 = new DateInterval(now, inOneHour);

            // Act
            int compareToValue = dateInterval1.CompareTo(dateInterval2); // Shortest duration comes first

            // Assert
            Assert.True(compareToValue == 0);
        }
开发者ID:Orcomp,项目名称:Orcomp,代码行数:12,代码来源:DateIntervalTest.cs

示例3: Collapse

        public static IList<ITask> Collapse(this IEnumerable<ITask> taskCollection)
        {
            var taskList = taskCollection.ToList();

            if (taskCollection == null)
            {
                return null;
            }

            var output = new Collection<ITask>();

            // Grabbing all time split points and sorting them
            List<DateTime> timeEvents = taskList.SelectMany(task => new[] { task.StartTime, task.EndTime })
                                                     .Distinct()
                                                     .OrderBy(x => x)
                                                     .ToList();

            for (var i = 0; i < timeEvents.Count - 1; i++)
            {
                var newSpan = new DateInterval(timeEvents[i], timeEvents[i + 1]);

                var overlappingTasks = taskList.Where(x => x.DateInterval.Overlaps(newSpan));

                if (overlappingTasks.Any())
                {
                    var quantityPerHour = overlappingTasks.Sum(x => x.QuantityPerHour);
                    output.Add(Task.CreateUsingQuantityPerHour(newSpan, quantityPerHour));
                }
            }

            return output;
        }
开发者ID:Orcomp,项目名称:Orcomp,代码行数:32,代码来源:TaskCollectionExtensions.cs

示例4: DateDiff

 /// <summary>
 /// Devuelve un valor Long que especifica el número de
 /// intervalos de tiempo entre dos valores Date.
 /// </summary>
 /// <param name="interval">Obligatorio. Valor de enumeración
 /// DateInterval o expresión String que representa el intervalo
 /// de tiempo que se desea utilizar como unidad de diferencia
 /// entre Date1 y Date2.</param>
 /// <param name="date1">Obligatorio. Date. Primer valor de
 /// fecha u hora que se desea utilizar en el cálculo.</param>
 /// <param name="date2">Obligatorio. Date. Segundo valor de
 /// fecha u hora que se desea utilizar en el cálculo.</param>
 /// <returns></returns>
 public static long DateDiff(DateInterval interval, DateTime date1, DateTime date2)
 {
     long rs = 0;
     TimeSpan diff = date2.Subtract(date1);
     switch (interval)
     {
         case DateInterval.Day:
         case DateInterval.DayOfYear:
             rs = (long)diff.TotalDays;
             break;
         case DateInterval.Hour:
             rs = (long)diff.TotalHours;
             break;
         case DateInterval.Minute:
             rs = (long)diff.TotalMinutes;
             break;
         case DateInterval.Month:
             rs = (date2.Month - date1.Month) + (12*DateTimeExtension.DateDiff(DateInterval.Year, date1, date2));
             break;
         case DateInterval.Quarter:
             rs = (long)Math.Ceiling((double)(DateTimeExtension.DateDiff(DateInterval.Month, date1, date2) / 3.0));
             break;
         case DateInterval.Second:
             rs = (long)diff.TotalSeconds;
             break;
         case DateInterval.Weekday:
         case DateInterval.WeekOfYear:
             rs = (long)(diff.TotalDays/7);
             break;
         case DateInterval.Year:
             rs = date2.Year - date1.Year;
             break;
     }//switch
     return rs;
 }
开发者ID:hamekoz,项目名称:hamekoz-tiempos,代码行数:48,代码来源:MainWindow.cs

示例5: DateDiff

 internal static long DateDiff(DateInterval Interval, System.DateTime StartDate, System.DateTime EndDate)
 {
     long lngDateDiffValue = 0;
     System.TimeSpan TS = new System.TimeSpan(EndDate.Ticks - StartDate.Ticks);
     switch (Interval)
     {
         case DateInterval.Day:
             lngDateDiffValue = (long)TS.Days;
             break;
         case DateInterval.Hour:
             lngDateDiffValue = (long)TS.TotalHours;
             break;
         case DateInterval.Minute:
             lngDateDiffValue = (long)TS.TotalMinutes;
             break;
         case DateInterval.Month:
             lngDateDiffValue = (long)(TS.Days / 30);
             break;
         case DateInterval.Quarter:
             lngDateDiffValue = (long)((TS.Days / 30) / 3);
             break;
         case DateInterval.Second:
             lngDateDiffValue = (long)TS.TotalSeconds;
             break;
         case DateInterval.Week:
             lngDateDiffValue = (long)(TS.Days / 7);
             break;
         case DateInterval.Year:
             lngDateDiffValue = (long)(TS.Days / 365);
             break;
     }
     return (lngDateDiffValue);
 }
开发者ID:jbrambilla,项目名称:boletonet,代码行数:33,代码来源:Utils.cs

示例6: Construction_DefaultToInclusive

 public void Construction_DefaultToInclusive()
 {
     LocalDate start = new LocalDate(2000, 1, 1);
     LocalDate end = new LocalDate(2001, 6, 19);
     var interval = new DateInterval(start, end);
     Assert.IsTrue(interval.Inclusive);
 }
开发者ID:ivandrofly,项目名称:nodatime,代码行数:7,代码来源:DateIntervalTest.cs

示例7: GetDateDiff

        /// <summary>
        /// Gets the difference between two dates based on an interval.
        /// </summary>
        /// <param name="interval">The interval to use (seconds, minutes, hours, days, months, years)</param>
        /// <param name="date1">The date to use for comparison.</param>
        /// <param name="date2">The date to compare against the first date.</param>
        /// <returns></returns>
        public static object GetDateDiff(DateInterval interval, DateTime date1, DateTime date2)
        {
            object returnValue = null;
            TimeSpan t;

            object diff = 0.0;

            //returns negative value if date1 is more recent
            t = date2 - date1;

            switch (interval)
            {
                case DateInterval.Second:
                    diff = t.TotalSeconds;
                    break;
                case DateInterval.Minute:
                    diff = t.TotalMinutes;
                    break;
                case DateInterval.Hour:
                    diff = t.TotalHours;
                    break;
                case DateInterval.Day:
                    diff = t.TotalDays;
                    break;
                case DateInterval.Month:
                    diff = t.TotalDays / 365.25 * 12.0;
                    break;
                case DateInterval.Year:
                    diff = t.TotalDays / 365.25;
                    break;
            }

            returnValue = Convert.ToInt32(diff);
            return returnValue;
        }
开发者ID:NALSS,项目名称:epiinfo-82474,代码行数:42,代码来源:EpiFunctions.cs

示例8: Length_Exclusive

 public void Length_Exclusive()
 {
     LocalDate start = new LocalDate(2000, 1, 1);
     LocalDate end = new LocalDate(2000, 2, 10);
     var interval = new DateInterval(start, end, false);
     Assert.AreEqual(40, interval.Length);
 }
开发者ID:KonstantinDavidov,项目名称:nodatime,代码行数:7,代码来源:DateIntervalTest.cs

示例9: AccountForEfficiencies_FixedEnd_MultipleDateIntervalEfficiencies_ReturnsCorrectAnswer

        public void AccountForEfficiencies_FixedEnd_MultipleDateIntervalEfficiencies_ReturnsCorrectAnswer()
        {
            //         +------------+
            //       |0|  |0|  |0|

            // Result:
            //   +------------------+
            //       |0|  |0|  |0|

            // Arrange
            var now = DateTime.Now;
            var dateInterval = new DateInterval(now, now.AddDays(5));

            var dateIntervalEfficiencies = new List<DateIntervalEfficiency>();
            var efficiency1 = new DateIntervalEfficiency(now.AddDays(1), now.AddDays(2), 0);
            var efficiency2 = new DateIntervalEfficiency(now.AddDays(3), now.AddDays(4), 0);
            var efficiency3 = new DateIntervalEfficiency(now.AddDays(5), now.AddDays(6), 0);

            dateIntervalEfficiencies.Add(efficiency1);
            dateIntervalEfficiencies.Add(efficiency2);
            dateIntervalEfficiencies.Add(efficiency3);

            // Act
            var newDateInterval = dateInterval.AccountForEfficiencies(dateIntervalEfficiencies, FixedEndPoint.Max);

            var correctDateInterval = new DateInterval(dateInterval.Max.Value.Add(-dateInterval.Duration).Add(-efficiency1.Duration).Add(-efficiency2.Duration).Add(-efficiency3.Duration), dateInterval.Max.Value);

            // Assert
            Assert.AreEqual(correctDateInterval, newDateInterval);
        }
开发者ID:asheze,项目名称:Orcomp,代码行数:30,代码来源:AccountForEfficienciesTest.cs

示例10: DateDiff

 public static long DateDiff(this DateTime startDate, DateTime endDate, DateInterval interval = DateInterval.Day)
 {
     long lngDateDiffValue = 0;
       var timeSpan = new TimeSpan(endDate.Ticks - startDate.Ticks);
       switch (interval)
       {
     case DateInterval.Second:
       lngDateDiffValue = (long) timeSpan.TotalSeconds;
       break;
     case DateInterval.Minute:
       lngDateDiffValue = (long) timeSpan.TotalMinutes;
       break;
     case DateInterval.Hour:
       lngDateDiffValue = (long) timeSpan.TotalHours;
       break;
     case DateInterval.Day:
       lngDateDiffValue = timeSpan.Days;
       break;
     case DateInterval.Week:
       lngDateDiffValue = timeSpan.Days/7;
       break;
     case DateInterval.Month:
       lngDateDiffValue = timeSpan.Days/30;
       break;
     case DateInterval.Quarter:
       lngDateDiffValue = (timeSpan.Days/30)/3;
       break;
     case DateInterval.Year:
       lngDateDiffValue = timeSpan.Days/365;
       break;
       }
       return (lngDateDiffValue);
 }
开发者ID:EinsteinSu,项目名称:EsuCommon,代码行数:33,代码来源:DateTimeExtensions.cs

示例11: DateAdd

        public static DateTime DateAdd(DateInterval interval, int value, DateTime date)
        {
            int ms = date.GetTime();
            DateTime result;
            switch (interval)
            {
                case DateInterval.Milliseconds:
                    result = new DateTime(ms + value);
                    break;
                case DateInterval.Seconds:
                    result = new DateTime(ms + (value * 1000));
                    break;
                case DateInterval.Minutes:
                    result = new DateTime(ms + (value * 1000 * 60));
                    break;
                case DateInterval.Hours:
                    result = new DateTime(ms + (value * 1000 * 60 * 60));
                    break;
                case DateInterval.Days:
                    result = new DateTime(ms + (value * 1000 * 60 * 60 * 24));
                    break;
                default:
                    result = date;
                    break;
            }

            return result;
        }
开发者ID:hsheild,项目名称:SparkleXrm,代码行数:28,代码来源:DateTimeEx.cs

示例12: DateTimeSearchModel

 public DateTimeSearchModel(string title, string columnName, DateInterval interval = DateInterval.Month)
 {
     this.title = title;
       ColumnName = columnName;
       endDate = DateTime.Now;
       switch (interval)
       {
     case DateInterval.Day:
       startDate = DateTime.Now.AddDays(-1);
       break;
     case DateInterval.Week:
       startDate = DateTime.Now.AddDays(-7);
       break;
     case DateInterval.Month:
       startDate = DateTime.Now.AddMonths(-1);
       break;
     case DateInterval.Quarter:
       startDate = DateTime.Now.AddMonths(-3);
       break;
     case DateInterval.Year:
       startDate = DateTime.Now.AddYears(-1);
       break;
       }
       originalDate = startDate;
 }
开发者ID:EinsteinSu,项目名称:EsuCommon,代码行数:25,代码来源:DateTimeSearchModel.cs

示例13: Construction_Properties

 public void Construction_Properties()
 {
     LocalDate start = new LocalDate(2000, 1, 1);
     LocalDate end = new LocalDate(2001, 6, 19);
     var interval = new DateInterval(start, end, false);
     Assert.AreEqual(start, interval.Start);
     Assert.AreEqual(end, interval.End);
     Assert.IsFalse(interval.Inclusive);
 }
开发者ID:ivandrofly,项目名称:nodatime,代码行数:9,代码来源:DateIntervalTest.cs

示例14: Setup

        public void Setup()
        {
            now = DateTime.Now;

            nowAndTenDaysInterval = new DateInterval(now, now.AddDays(10));
            nowAndFiveDaysInterval = new DateInterval(now, now.AddDays(5));
            twoDaysAndFiveDaysInterval = new DateInterval(now.AddDays(2), now.AddDays(5));
            threeDaysAgoAndTwelveDaysInterval = new DateInterval(now.AddDays(-3), now.AddDays(12));
            thirteenDaysAndFourteenDaysInterval = new DateInterval(now.AddDays(13), now.AddDays(14));
        }
开发者ID:Quicks01ver,项目名称:Orcomp,代码行数:10,代码来源:DateIntervalCollectionTestBase.cs

示例15: FixedStartPointNoOverlapsWithOffset

        public void FixedStartPointNoOverlapsWithOffset(IAccountForEfficiencies accountForEfficienciesCalculator)
        {
            // 1% efficiency
            var dateIntervalEfficiencies = DateIntervalCollectionGenerator.NoOverlaps(this.now, TimeSpan.FromMinutes(1), TimeSpan.FromMinutes(1), this.numberOfIntervals)
                .Select(interval => new DateIntervalEfficiency(interval, 1)).ToList();

            var initialInterval = new DateInterval(this.now, dateIntervalEfficiencies.Last().Max.Value);

            accountForEfficienciesCalculator.AccountForEfficiencies(initialInterval, dateIntervalEfficiencies, FixedEndPoint.Min);
        }
开发者ID:Jiannan,项目名称:Orcomp,代码行数:10,代码来源:AccountForEfficienciesPerfs.cs


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