ASP.NET / C#: Using GetTimeSpan() Function

Error: 'System.DateTime' does not contain a definition for 'GetTimeSpan' and no extension method 'GetTimeSpan' accepting a first argument of type 'System.DateTime' could be found (are you missing a using directive or an assembly reference?)
using System;
using System.Linq;
using cAlgo.API;
using cAlgo.API.Internals;

namespace cAlgo
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class RoboRobot : Robot
    {
        [Parameter(DefaultValue = 0.0)]
        public double Parameter { get; set; }


        protected override void OnTick()
        {

            Print(DateTime.Now.GetTimeSpan());
        }


        public static string GetTimeSpan(DateTime postDate)
        {
            string stringy = string.Empty;
            TimeSpan diff = DateTime.Now.Subtract(postDate);
            double days = diff.Days;
            double hours = diff.Hours + days * 24;
            double minutes = diff.Minutes + hours * 60;
            if (minutes <= 1)
            {
                return "Just Now";
            }
            double years = Math.Floor(diff.TotalDays / 365);
            if (years >= 1)
            {
                return string.Format("{0} year{1} ago", years, years >= 2 ? "s" : null);
            }
            double weeks = Math.Floor(diff.TotalDays / 7);
            if (weeks >= 1)
            {
                double partOfWeek = days - weeks * 7;
                if (partOfWeek > 0)
                {
                    stringy = string.Format(", {0} day{1}", partOfWeek, partOfWeek > 1 ? "s" : null);
                }
                return string.Format("{0} week{1}{2} ago", weeks, weeks >= 2 ? "s" : null, stringy);
            }
            if (days >= 1)
            {
                double partOfDay = hours - days * 24;
                if (partOfDay > 0)
                {
                    stringy = string.Format(", {0} hour{1}", partOfDay, partOfDay > 1 ? "s" : null);
                }
                return string.Format("{0} day{1}{2} ago", days, days >= 2 ? "s" : null, stringy);
            }
            if (hours >= 1)
            {
                double partOfHour = minutes - hours * 60;
                if (partOfHour > 0)
                {
                    stringy = string.Format(", {0} minute{1}", partOfHour, partOfHour > 1 ? "s" : null);
                }
                return string.Format("{0} hour{1}{2} ago", hours, hours >= 2 ? "s" : null, stringy);
            }
            return minutes.ToString("{0} minutes ago");
        }

    }
}

Open in new window

LVL 10
skijAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

käµfm³d 👽Commented:
What is your question?
0
anarki_jimbelSenior DeveloperCommented:
You do not invoke your custom method GetTimeSpan() correctly.

I believe, should be something like:

        protected override void OnTick()
        {

            Print(GetTimeSpan(mySomeDateTime));
        }

Open in new window


where mySomeDateTime - DateTime value, against which you need to get TimeSpan .
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
skijAuthor Commented:
Thank you!  I have posted a related question here:
http://www.experts-exchange.com/Programming/Languages/C_Sharp/Q_28675951.html
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.