feat: adding the check for the older one

This commit is contained in:
Raphael 2024-10-15 00:51:11 +02:00
parent 513f0a44ea
commit 77c225d31e

View file

@ -6,11 +6,40 @@
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/09/20 19:42:14 by rparodi #+# #+# */
/* Updated: 2024/10/15 00:33:56 by rparodi ### ########.fr */
/* Updated: 2024/10/15 00:50:51 by rparodi ### ########.fr */
/* */
/* ************************************************************************** */
#include "phonebook.hpp"
#include <ctime>
#include <iostream>
int get_older_contact(contact array_contact[8])
{
int ret = 0;
time_t remain = 0;
for (int i = 0; i < 8; i++)
{
time_t tmp = mktime(array_contact[i].creation_time);
if (tmp == -1)
{
std::cerr << RED << "\nError: during the time process\n" << RESET << std::endl;
exit(1);
}
if (tmp > remain)
{
remain = mktime(array_contact[i].creation_time);
if (remain == -1)
{
std::cerr << RED << "\nError: during the time process\n" << RESET << std::endl;
exit(1);
}
ret = i;
}
}
return (ret);
}
/**
* @brief Adding a new contact