fork download
#include 
#include 

struct SYSTEMTIME
{
    int wHour;
    int wDayOfWeek;
    int wMinute;
} ;

// store a table of the difference in days to account for the 
// rollover of days (Saturday/Sunday, Friday/Monday, etc.)
size_t day_difference_table[7][7] = 
{
   {0, 1, 2, 3, 3, 2, 1},
   {1, 0, 1, 2, 3, 3, 2},
   {2, 1, 0, 1, 2, 3, 3},
   {3, 2, 1, 0, 1, 2, 3},
   {3, 3, 2, 1, 0, 1, 2},
   {2, 3, 3, 2, 1, 0, 1},
   {1, 2, 3, 3, 2, 1, 0}
};

// returns a single size_t value for the difference in times
// by having the days->hours->minutes shifted over 8 bits each    
size_t timediff(const SYSTEMTIME& t0, const SYSTEMTIME& t1)
{
   // start with an assumption of an absolute match
   size_t diff = 0;

   // get the absolute value of the difference in the days
   // as the day exerts the biggest influence on the result
   diff = day_difference_table[t0.wDayOfWeek][t1.wDayOfWeek];

   // shift right, since days are "worth more" than hours or minutes...
   diff <<= 8;

   // then the hours...
   diff += std::abs(t0.wHour - t1.wHour);

   // shift right, since hours are "worth more" than minutes
   diff <<= 8;

   // then the minutes
   diff += std::abs(t0.wMinute - t1.wMinute);

   // nothing left to shift ;)

   return diff;
}



int main()
{
   SYSTEMTIME m_MatchTime[3];

   //current time
   m_MatchTime[0].wDayOfWeek = 0;
   m_MatchTime[0].wHour = 23;
   m_MatchTime[0].wMinute = 59;

   // 23:59 from 0
   m_MatchTime[1].wDayOfWeek = 0;
   m_MatchTime[1].wHour = 0;
   m_MatchTime[1].wMinute = 0;

    // 0:01 from 0
    m_MatchTime[2].wDayOfWeek = 1;
    m_MatchTime[2].wHour = 0;
    m_MatchTime[2].wMinute = 0;

   std::cout << "Difference (23:59 actuallty): " << timediff(m_MatchTime[0], m_MatchTime[1]) << "\n";
   std::cout << "Difference: (0:01 actually)" << timediff(m_MatchTime[0], m_MatchTime[2]) << "\n";
}
Success #stdin #stdout 0.01s 2724KB
stdin
Standard input is empty
stdout
Difference (23:59 actuallty): 5947
Difference: (0:01 actually)71483