Partial Date/Time Utility: Date_Time matching predicates
Phil Weinstein, CADSWES, RiverWare 6.1, edit 7-14-2011

Added Date_Time / PartialDateTime "matching" functions:

--------------------------------
Utils/PartialDateTimeEncoder.hpp
Utils/PartialDateTimeEncoder.cpp
--------------------------------

class PartialDateTimeEncoder

   // Note: the static version of this method is faster if the partial
   // date time value is absolute. It avoids unnecessary construction 
   // of an encoder instance.

   bool matchesDateTime (const Date_Time& refDT) const;
   static bool matchesDateTime (double, const Date_Time& refDT);

***************
***  USAGE  ***
***************

If you happen to have a PartialDateTimeEncoder already constructed for 
the slot value, use the non-static version.

   double stdVal ...
   PartialDateTimeEncoder enc (stdVal);
   bool matches = enc.matchesDateTime (refDT);

BUT IF you don't have an encoder constructed AND IF the DateTime slot
value MIGHT BE an "absolute" (not actually partial) date/time, then use
the static method:

   double stdVal ...
   bool matches = PartialDateTimeEncoder::matchesDateTime (stdVal, refDT);

---

Implementation:

// Note: the static version of this method (see below) is faster if the 
// partial date/time value is absolute. It avoids unnecessary construction 
// of an encoder instance.
 
// public
bool PartialDateTimeEncoder::matchesDateTime (const Date_Time& refDT) const
{
   // First check if this partial date/time is "absolute". If so, just
   // use regular DateTime comparison.

   if (_negPartBits == PartialDateTime::NegPartBits_Absolute)
   {
      return (_dtime == refDT);
   }
 
   // Compare the relevant date/time parts. Return false if any relevant
   // differences are detected.
 
   if (showYear()  && (_dtime.get_year() != refDT.get_year())) return (false);
   if (showMonth() && (_dtime.get_mon()  != refDT.get_mon()))  return (false);
   if (showDay()   && (_dtime.get_mday() != refDT.get_mday())) return (false);
   if (showHour()  && (_dtime.get_hour() != refDT.get_hour())) return (false);
   if (showMins()  && (_dtime.get_min()  != refDT.get_min()))  return (false);
   if (showSecs()  && (_dtime.get_sec()  != refDT.get_sec()))  return (false);
 
   // No relevant date/time parts differed.
   return (true); // matchesDateTime
}
 
// public static
bool PartialDateTimeEncoder::matchesDateTime (double val, 
                                              const Date_Time& refDT)
{
   if (floor (val) == val)
   {
      // The partial date/time is "absolute". So just compare the DateTime 
      // "seconds_t" field.
      return (seconds_t (val) == refDT.getAbsSeconds());
   }
 
   const PartialDateTimeEncoder enc (val);
   const bool matches = enc.matchesDateTime (refDT);
   return (matches);
}