2015-10-27 19:13:08 -04:00
|
|
|
/*
|
|
|
|
* Copyright 2015 (c) Anna Schumaker.
|
|
|
|
*/
|
|
|
|
#include <core/date.h>
|
|
|
|
#include <time.h>
|
|
|
|
|
|
|
|
|
|
|
|
void date_today(struct date *date)
|
|
|
|
{
|
|
|
|
time_t rawtime = time(NULL);
|
|
|
|
struct tm *now = localtime(&rawtime);
|
|
|
|
|
|
|
|
if (date) {
|
|
|
|
date->d_year = now->tm_year + 1900;
|
|
|
|
date->d_month = now->tm_mon + 1;
|
|
|
|
date->d_day = now->tm_mday;
|
|
|
|
}
|
|
|
|
}
|
2015-10-28 01:44:42 -04:00
|
|
|
|
|
|
|
int date_compare(const struct date *lhs, const struct date *rhs)
|
|
|
|
{
|
|
|
|
int ret = lhs->d_year - rhs->d_year;
|
|
|
|
if (ret != 0)
|
|
|
|
return ret;
|
|
|
|
ret = lhs->d_month - rhs->d_month;
|
|
|
|
if (ret != 0)
|
|
|
|
return ret;
|
|
|
|
return lhs->d_day - rhs->d_day;
|
|
|
|
}
|