Avatar of Dinesh Bali
Dinesh Bali
 asked on

Check if TimeSpam is exactly zero sec

Hi,

I am working in C#

I want to validate in my method that TimeSpan vStart is exactly 0 sec then proceed further else proceed.

I mean if the value is 0.01 sec also then proceed. How to validate?

Please advise. My code below. Is this fine the way I validated?

private ActionListStatus seperateMediaBeforeInsertingAnotherMedia(TimeSpan vStart, ActionListStatus actionListStatus)
{
         bool proceed = true;

            if (vStart.TotalSeconds==0 || vStart.TotalSeconds == 0.0)
            {
                proceed = false;
            }
         
         if(proceed)
         {
            // further stuff
         }
      return actionListStatus;
}

Open in new window


Kind Regards,

ASP.NETC#

Avatar of undefined
Last Comment
AndyAinscow

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
AndyAinscow

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Gustav Brock

Your question is not clear. If

I want to validate in my method that TimeSpan vStart is exactly 0 sec then:

if (vStart.TotalSeconds == 0)

Open in new window

> I mean if the value is 0.01 sec also then proceed. then to ignore partial seconds:

if (vStart.TotalSeconds < 1)

Open in new window

AndyAinscow

In case you didn't understand my initial comment.  You decide what is acceptably close to zero and test if the TimeSpan is is less than that limit.  In other words if you say anything less than one tenth of a second span between the two times is an equal time then use
vStart.TotalSeconds < 0.1

Open in new window

in your if statement.  If you wanted less than one fiftieth of a second then
vStart.TotalSeconds < 0.02

Open in new window


If the timespan must be exactly equal to zero then your original check is fine
vStart.TotalSeconds == 0

Open in new window


This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23