BaconographyW8.Converters.TimeRelationConverter.DateTimeSpan.CompareDates C# (CSharp) Method

CompareDates() public static method

public static CompareDates ( System.DateTime date1, System.DateTime date2 ) : DateTimeSpan
date1 System.DateTime
date2 System.DateTime
return DateTimeSpan
            public static DateTimeSpan CompareDates(DateTime date1, DateTime date2)
            {

                if (date2 < date1)
                {
                    var sub = date1;
                    date1 = date2;
                    date2 = sub;
                }

                DateTime current = date2;
                int years = 0;
                int months = 0;
                int days = 0;

                Phase phase = Phase.Years;
                DateTimeSpan span = new DateTimeSpan();

                while (phase != Phase.Done)
                {
                    switch (phase)
                    {
                        case Phase.Years:
                            if (current.Year == 1 || current.AddYears(-1) < date1)
                            {
                                phase = Phase.Months;
                            }
                            else
                            {
                                current = current.AddYears(-1);
                                years++;
                            }
                            break;
                        case Phase.Months:
                            if (current.AddMonths(-1) < date1)
                            {
                                phase = Phase.Days;
                            }
                            else
                            {
                                current = current.AddMonths(-1);
                                months++;
                            }
                            break;
                        case Phase.Days:
                            if (current.AddDays(-1) < date1)
                            {
                                var timespan = current - date1;
                                span = new DateTimeSpan(years, months, days, timespan.Hours, timespan.Minutes, timespan.Seconds, timespan.Milliseconds);
                                phase = Phase.Done;
                            }
                            else
                            {
                                current = current.AddDays(-1);
                                days++;
                            }
                            break;
                    }
                }

                return span;

            }
        }
TimeRelationConverter.DateTimeSpan