Click here to Skip to main content
12,509,269 members (62,599 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as

Stats

1.7K views
1 bookmarked
Posted

Partial DateTime Object Equality

, 6 Feb 2011 CPOL
Rate this:
Please Sign up or sign in to vote.
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;

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

jswolf19
Software Developer
Japan Japan
No Biography provided

You may also be interested in...

Pro
Pro

Comments and Discussions

 
-- There are no messages in this forum --
| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.160927.1 | Last Updated 7 Feb 2011
Article Copyright 2011 by jswolf19
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid