65.9K
CodeProject is changing. Read more.
Home

Partial DateTime Object Equality

starIconstarIconstarIconstarIcon
emptyStarIcon
starIcon

4.50/5 (2 votes)

Feb 3, 2011

CPOL
viewsIcon

3647

If you use the logic from your FlagIsSet function, you can remove half of your tests: DatePartFlags equalFlags = DatePartFlags.Ticks; equalFlags |= (now.Year == then.Year) ? DatePartFlags.Year : 0; equalFlags |= (now.Month == then.Month) ? DatePartFlags.Month : 0; ...

If you use the logic from your FlagIsSet function, you can remove half of your tests:
    DatePartFlags equalFlags = DatePartFlags.Ticks;
    equalFlags |= (now.Year == then.Year) ? DatePartFlags.Year : 0;
    equalFlags |= (now.Month == then.Month) ? DatePartFlags.Month : 0;
    equalFlags |= (now.Day == then.Day) ? DatePartFlags.Day : 0;
    equalFlags |= (now.Hour == then.Hour) ? DatePartFlags.Hour : 0;
    equalFlags |= (now.Minute == then.Minute) ? DatePartFlags.Minute : 0;
    equalFlags |= (now.Second == then.Second) ? DatePartFlags.Second : 0;
    equalFlags |= (now.Millisecond == then.Millisecond) ? DatePartFlags.Millisecond : 0;
    isEqual = (flags & equalFlags) == flags;