bool check_date_comparison () { CFDateRef date1, date2; // Standard Core Foundation comparison result. CFComparisonResult result; CFShow(CFSTR("Checking date comparison functions:")); // Create two CFDates from absolute time. date1 = CFDateCreate(kCFAllocatorDefault, CFAbsoluteTimeGetCurrent()); date2 = CFDateCreate(kCFAllocatorDefault, CFAbsoluteTimeGetCurrent()); // Pass NULL for the context param. result = CFDateCompare(date1, date2, NULL); switch (result) { case kCFCompareLessThan: CFShow(CFSTR("date1 is before date2!\n")); break; case kCFCompareEqualTo: CFShow(CFSTR("date1 is the same as date2!\n")); break; case kCFCompareGreaterThan: CFShow(CFSTR("date1 is after date2!\n")); break; } printf("\n"); return true; }
/* * * isEntryValidAndFuturistic * Returns true if the CFDictionary is validly formed * AND if the date is in the future * Returns false if anything about the dictionary is invalid * OR if the CFDate is prior to the current time * */ static bool isEntryValidAndFuturistic(CFDictionaryRef wakeup_dict, CFDateRef date_now) { CFDateRef wakeup_date; bool ret = true; wakeup_dict = isA_CFDictionary(wakeup_dict); if(!wakeup_dict) { // bogus entry! ret = false; } else { // valid entry wakeup_date = isA_CFDate(CFDictionaryGetValue(wakeup_dict, CFSTR(kIOPMPowerEventTimeKey))); if( !wakeup_date || (kCFCompareLessThan == CFDateCompare(wakeup_date, date_now, 0))) { // date is too early ret = false; } // otherwise date is after now, and ret = true } return ret; }