// <copyright file="DateComparer.cs" company="GoalBook"> // Copyright © 2009 Mark Brownsword. All rights reserved. // This source code and supporting files are licensed under The Code Project // Open License (CPOL) as detailed at http://www.codeproject.com/info/cpol10.aspx. // </copyright> namespace GoalBook.Infrastructure.Comparers { using System; using System.Collections; using GoalBook.Infrastructure.Constants; /// <summary> /// Date Comparer. /// </summary> public class DateComparer : IComparer { /// <summary> /// Compare implementation. /// </summary> /// <param name="x">x parameter</param> /// <param name="y">y parameter</param> /// <returns> /// Value Condition /// Less than zero x is less than y /// Zero x equals y /// Greater than zero x is greater than y /// </returns> public int Compare(object x, object y) { if (x == y) { return 0; } if (x == null) { return -1; } if (y == null) { return 1; } if ((string)y == DateComparisonConstants.NO_DATE_SPECIFIED) { return -1; } if ((string)x == DateComparisonConstants.NO_DATE_SPECIFIED) { return 1; } DateTime t1 = DateTime.Parse((string)x); DateTime t2 = DateTime.Parse((string)y); return DateTime.Compare(t1, t2); } } }
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.
This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)