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


C# TimeSpan.Equals方法代码示例

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


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

示例1: Start

        public static Task Start(Func<CancellationToken, Task<bool>> action, TimeSpan delay, CancellationToken cancellationToken)
        {
            Ensure.IsInfiniteOrGreaterThanOrEqualToZero(delay, "delay");

            Func<CancellationToken, Task> delayTask = null;
            if (delay.Equals(TimeSpan.Zero))
            {
                delayTask = ct => Task.FromResult<object>(null);
            }
            else if (!delay.Equals(Timeout.InfiniteTimeSpan))
            {
                delayTask = ct => Task.Delay(delay, ct);
            }
            
            return Start(action, delayTask, cancellationToken);
        }
开发者ID:Nakro,项目名称:mongo-csharp-driver,代码行数:16,代码来源:AsyncBackgroundTask.cs

示例2: PosTest2

    public bool PosTest2()
    {
        bool retVal = true;
        long randValue = 0;

        TestLibrary.TestFramework.BeginScenario("PosTest2: Equals should return true when compare with equal instance");

        try
        {
            randValue = TestLibrary.Generator.GetInt64(-55);
            TimeSpan ts1 = new TimeSpan(randValue);
            TimeSpan ts2 = new TimeSpan(randValue);

            if (!ts1.Equals(ts2 as Object))
            {
                TestLibrary.TestFramework.LogError("002.1", "Equals does not return true when compare with self instance");
                TestLibrary.TestFramework.LogInformation("WARNING [LOCAL VARIABLE] ts1.Ticks = " + ts1.Ticks + ", ts2.Ticks = " + ts2.Ticks + ", randValue = " + randValue);
                retVal = false;
            }
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("002.0", "Unexpected exception: " + e);
            TestLibrary.TestFramework.LogInformation(e.StackTrace);
            retVal = false;
        }

        return retVal;
    }
开发者ID:l1183479157,项目名称:coreclr,代码行数:29,代码来源:timespanequals1.cs

示例3: ToInches

        public static float ToInches(TimeSpan pulse)
        {
            if (pulse.Equals(TimeSpan.MaxValue))
                return Single.MaxValue;

            float result = pulse.TotalMicroseconds()/148f;
            return result;
        }
开发者ID:dario-l,项目名称:kodfilemon.blogspot.com,代码行数:8,代码来源:HCSR04.cs

示例4: AreTimesEqualToTheSecond

        public static bool AreTimesEqualToTheSecond(DateTime dt1, DateTime dt2)
        {
            //STRIP THE MILLISECONDS OUT
            var timeNowToTheSeconds = new TimeSpan(dt1.TimeOfDay.Hours, dt1.TimeOfDay.Minutes, dt1.TimeOfDay.Seconds);
            var triggerToTheSeconds = new TimeSpan(dt2.TimeOfDay.Hours, dt2.TimeOfDay.Minutes, dt2.TimeOfDay.Seconds);

            return timeNowToTheSeconds.Equals(triggerToTheSeconds);
        }
开发者ID:m19brandon,项目名称:zVirtualScenes,代码行数:8,代码来源:TimeHelpers.cs

示例5: EqualsWorks

		public void EqualsWorks() {
			var time1 = new TimeSpan(15, 10, 20, 5, 14);
			var time2 = new TimeSpan(14, 10, 20, 5, 14);
			var time3 = new TimeSpan(15, 10, 20, 5, 14);

			Assert.IsFalse(time1.Equals(time2));
			Assert.IsTrue (time1.Equals(time3));
		}
开发者ID:pdavis68,项目名称:SaltarelleCompiler,代码行数:8,代码来源:TimeSpanTests.cs

示例6: GetPPD

      /// <summary>
      /// Gets the points per day measurement based the given frame time, work unit information, and the unit completion time.
      /// </summary>
      /// <param name="frameTime">The work unit frame time.</param>
      /// <param name="frames">The number of frames in the work unit.</param>
      /// <param name="baseCredit">The base credit assigned to the work unit.</param>
      /// <param name="kFactor">The KFactor assigned to the work unit.</param>
      /// <param name="preferredDays">The preferred deadline (in decimal days).</param>
      /// <param name="maximumDays">The final deadline (in decimal days).</param>
      /// <param name="unitTime">The overall unit completion time.</param>
      /// <returns>The points per day for the work unit.</returns>
      public static double GetPPD(TimeSpan frameTime, int frames, double baseCredit, double kFactor, double preferredDays, double maximumDays, TimeSpan unitTime)
      {
         if (frameTime.Equals(TimeSpan.Zero)) return 0;

         double basePPD = GetUPD(frameTime, frames) * baseCredit;
         double bonusMulti = GetMultiplier(kFactor, preferredDays, maximumDays, unitTime);
         double bonusPPD = Math.Round((basePPD * bonusMulti), MaxDecimalPlaces);

         return bonusPPD;
      }
开发者ID:harlam357,项目名称:hfm-net,代码行数:21,代码来源:ProductionCalculator.cs

示例7: bBonusContinue_Click

        private void bBonusContinue_Click(object sender, EventArgs e)
        {
            var t = new TimeSpan((int)numUpDBonusHours.Value, (int)numUpDBonusMinutes.Value, (int)numUpDBonusSeconds.Value);
            if (t.Equals(new TimeSpan()))
            {
                t = new TimeSpan();
            }

            DiscountRedactorController.InstanceDiscountRedactorController()
                .CreateNewBonus(t, tbBonusItem.Text, (int)numUpDBonusNumOfItem.Value,
                    (double)numUpDBonusMoneySum.Value, (double)numUpBonusSumDiscount.Value);
        }
开发者ID:kimslava93,项目名称:Boom,代码行数:12,代码来源:DiscountsRedactor.cs

示例8: bRequirementsContinue_Click

        private void bRequirementsContinue_Click(object sender, EventArgs e)
        {
            var t = new TimeSpan((int)numUpDHoursRequirement.Value, (int)numUpDMinutesRequirements.Value, (int)numUpDSecondsRequirements.Value);
            if (t.Equals(new TimeSpan()))
            {
                t = new TimeSpan();
            }

            DiscountRedactorController.InstanceDiscountRedactorController()
                .CreateNewRequirement(t, tbItemRequiredToBuy.Text, (int) numUpDNumOfItemsRequired.Value,
                    (double) numUpDMOneySumRequiredToPay.Value);
        }
开发者ID:kimslava93,项目名称:Boom,代码行数:12,代码来源:DiscountsRedactor.cs

示例9: timer_Tick

        void timer_Tick(object sender, EventArgs e)
        {
            try { FrameworkDispatcher.Update(); } catch { }
            local = local.Subtract(new TimeSpan(0,0,1));
            //if timeout, ring bell
            if(local.Equals(new TimeSpan(0,0,-1)))
            {
                ringbell();

                if (current == Status.work)
                {
                    //CurrentStatus.Text = "Revise and Rest";
                    local = BreakTime.Value.Value;
                    //local = new TimeSpan(0,0,2);
                    current = Status.play;
                    message = "Rest\n";
                }
                else
                {
                    //CurrentStatus.Text = "Start your work again!";
                    local = WorkTime.Value.Value;
                    //local = new TimeSpan(0,0,4);
                    current = Status.work;
                    message = "Work\n";
                }
            }
            ForOutput.Text = message + local.ToString();
            //CurrentStatus.Text = audioPlay.Source.ToString();
        }
开发者ID:snisarg,项目名称:WorkBreakTimer,代码行数:29,代码来源:MainPage.xaml.cs

示例10: FormatTime

 public static string FormatTime(TimeSpan ts)
 {
     string txt = "";
     if (ts.Equals(TimeSpan.Zero))
     {
         return "0 seconds";
     }
     if (ts.Days > 0)
     {
         txt += ts.Days.ToString() + " day" + (ts.Days == 1 ? "" : "s");
     }
     if (ts.Hours > 0)
     {
         if (txt.Length > 0)
         {
             txt += " ";
         }
         txt += ts.Hours.ToString() + " hour" + (ts.Hours == 1 ? "" : "s");
     }
     if (ts.Minutes > 0)
     {
         if (txt.Length > 0)
         {
             txt += " ";
         }
         txt += ts.Minutes.ToString() + " minute" + (ts.Minutes == 1 ? "" : "s");
     }
     if (ts.Seconds > 0)
     {
         if (txt.Length > 0)
         {
             txt += " ";
         }
         txt += ts.Seconds.ToString() + " second" + (ts.Seconds == 1 ? "" : "s");
     }
     return txt;
 }
开发者ID:rburchell,项目名称:obsidian,代码行数:37,代码来源:Obsidian.cs

示例11: GetTimeString

        public string GetTimeString(EventCalendar ev)
        {
            if (ev.customer.Length == 0)
            {
                TimeSpan to_time = new TimeSpan(Convert.ToInt32(ev.to_time.Split(':')[0]), Convert.ToInt32(ev.to_time.Split(':')[1]), 0);
                TimeSpan from_time = new TimeSpan(Convert.ToInt32(ev.from_time.Split(':')[0]), Convert.ToInt32(ev.from_time.Split(':')[1]), 0);
                DateTime event_date = DateTime.Parse(ev.date, cinfo_us, DateTimeStyles.None);

                if (from_time.Hours <= 12 && to_time.Hours >= 13)
                {
                    return ((to_time - from_time - TimeSpan.Parse("01:00:00")).Hours >= 1 ? (to_time - from_time - TimeSpan.Parse("01:00:00")).Hours.ToString() + ((to_time - from_time - TimeSpan.Parse("01:00:00")).Minutes > 1 ? ":" + (to_time - from_time - TimeSpan.Parse("01:00:00")).Minutes.ToString() + " ชม." : " ชม.") : (to_time - from_time - TimeSpan.Parse("01:00:00")).Minutes.ToString() + " นาที") + ((event_date.GetDayIntOfWeek() >= 2 && event_date.GetDayIntOfWeek() <= 6) && (from_time.Equals(TimeSpan.Parse("08:30:00")) && to_time.Equals(TimeSpan.Parse("17:30:00"))) ? "(เต็มวัน)" : "(" + from_time.ToString().Substring(0, 5) + " - " + to_time.ToString().Substring(0, 5) + ")");
                }
                else
                {
                    return ((to_time - from_time).Hours >= 1 ? (to_time - from_time).Hours.ToString() + ((to_time - from_time).Minutes > 1 ? ":" + (to_time - from_time).Minutes.ToString() + " ชม." : " ชม.") : (to_time - from_time).Minutes.ToString() + " นาที") + ((event_date.GetDayIntOfWeek() >= 2 && event_date.GetDayIntOfWeek() <= 6) && (from_time.Equals(TimeSpan.Parse("08:30:00")) && to_time.Equals(TimeSpan.Parse("17:30:00"))) ? "(เต็มวัน)" : "(" + from_time.ToString().Substring(0, 5) + " - " + to_time.ToString().Substring(0, 5) + ")");
                }
            }
            else
            {
                return ev.customer;
            }
        }
开发者ID:wee2tee,项目名称:SN_Net,代码行数:22,代码来源:CustomDateEvent.cs

示例12: TestEquals

        public void TestEquals()
        {
            TimeSpan t1 = new TimeSpan(1);
            TimeSpan t2 = new TimeSpan(2);
            string s = "justastring";

            Assert.AreEqual(true, t1.Equals(t1), "A1");
            Assert.AreEqual(false, t1.Equals(t2), "A2");
            Assert.AreEqual(false, t1.Equals(s), "A3");
            Assert.AreEqual(false, t1.Equals(null), "A4");
            Assert.AreEqual(true, TimeSpan.Equals(t1, t1), "A5");
            Assert.AreEqual(false, TimeSpan.Equals(t1, t2), "A6");
            Assert.AreEqual(false, TimeSpan.Equals(t1, null), "A7");
            Assert.AreEqual(false, TimeSpan.Equals(t1, s), "A8");
            Assert.AreEqual(false, TimeSpan.Equals(s, t2), "A9");
            Assert.AreEqual(true, TimeSpan.Equals(null, null), "A10");
        }
开发者ID:Xtremrules,项目名称:dot42,代码行数:17,代码来源:TestTimeSpan.cs

示例13: GetTimeZoneByOffset

 /// <summary>
 /// Gets the time zone by offset.
 /// </summary>
 /// <param name="utcOffsetTime">The utc offset time.</param>
 /// <returns></returns>
 public static TzTimeZone GetTimeZoneByOffset(TimeSpan utcOffsetTime)
 {
     if (utcOffsetTime.Equals(TimeSpan.Zero))
     {
         return TzTimeZone.ZoneUTC;
     }
     else
     {
         // We pick the most "well-known" time zone in the set for each offset
         string zoneName;
         if (s_mainTimeZones.TryGetValue(DateTimeUtlities.ConvertTimeSpanToDouble(utcOffsetTime), out zoneName))
         {
             return GetTimeZone(zoneName);
         }
         else
         {
             // TODO do a manual search
         }
     }
     throw new TzDatabase.TzException("Cannot find time zone with UTC offset {0}.", utcOffsetTime);
 }
开发者ID:numerodix,项目名称:solarbeam,代码行数:26,代码来源:TzTimeZone.cs

示例14: GetUPD

 /// <summary>
 /// Gets the units per day measurement based the given frame time and number of frames.
 /// </summary>
 /// <param name="frameTime">The work unit frame time.</param>
 /// <param name="frames">The number of frames in the work unit.</param>
 /// <returns>The units per day for the work unit.</returns>
 public static double GetUPD(TimeSpan frameTime, int frames)
 {
    double totalTime = (frameTime.TotalSeconds * frames);
    if (totalTime <= 0.0)
    {
       return 0.0;
    }
    return frameTime.Equals(TimeSpan.Zero) ? 0.0 : 86400 / totalTime;
 }
开发者ID:harlam357,项目名称:hfm-net,代码行数:15,代码来源:ProductionCalculator.cs

示例15: GetTimeSpanToFormat

        /// <summary>
        /// �^�C���X�p������t�H�[�}�b�g�����������擾
        /// </summary>
        /// <param name="timeSpan"></param>
        /// <returns></returns>
        private String GetTimeSpanToFormat(TimeSpan timeSpan)
        {
            if (timeSpan.Equals(TimeSpan.Zero) == true)
            {
                return Properties.Resources.UnKown;
            }

            StringBuilder result = new StringBuilder();
            result.Append(Properties.Resources.AlsoTime);

            // ����
            if (timeSpan.Hours > 0)
            {
                timeSpan.Add(new TimeSpan(0, 60 - timeSpan.Minutes, 60 - timeSpan.Seconds));

                result.AppendFormat(Properties.Resources.HoursFormat, timeSpan.Hours);
            }

            // ��
            if (timeSpan.Minutes > 0)
            {
                timeSpan.Add(new TimeSpan(0, 0, 60 - timeSpan.Seconds));

                result.AppendFormat(Properties.Resources.MinutesFormat, timeSpan.Minutes);
            }

            // �b
            if (timeSpan.Seconds > 0)
            {
                int second = (int) (Math.Floor(timeSpan.Seconds % 5.0) * 5);
                result.AppendFormat(Properties.Resources.SecondsFormat, second);
            }

            // �~���b
            if (timeSpan.Seconds == 0 && timeSpan.Milliseconds >= 0)
            {
                int second = timeSpan.Milliseconds / 200;
                result.AppendFormat(Properties.Resources.SecondsFormat, second);
            }

            return result.ToString();
        }
开发者ID:todesmarz,项目名称:folder_wacher,代码行数:47,代码来源:ProgressForm.cs


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