Use time_t instead of long in several places

Start converting some variables and return values to store times from
long to time_t.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
This commit is contained in:
Lukas Fleischer 2015-02-24 13:57:44 +01:00
parent 892d6edccd
commit 0145ba12ec
9 changed files with 69 additions and 89 deletions

View File

@ -310,7 +310,7 @@ date_arg_from_to(long from, long to, int add_line, const char *fmt_apt,
} }
} }
static long parse_datearg(const char *str) static time_t parse_datearg(const char *str)
{ {
struct date day; struct date day;
@ -329,12 +329,12 @@ static long parse_datearg(const char *str)
return LONG_MAX; return LONG_MAX;
} }
static long parse_datetimearg(const char *str) static time_t parse_datetimearg(const char *str)
{ {
char *date = mem_strdup(str); char *date = mem_strdup(str);
char *time; char *time;
unsigned hour, min; unsigned hour, min;
long ret; time_t ret;
time = strchr(date, ' '); time = strchr(date, ' ');
if (time) { if (time) {
@ -363,7 +363,7 @@ static long parse_datetimearg(const char *str)
return ret; return ret;
} }
static int parse_daterange(const char *str, long *date_from, long *date_to) static int parse_daterange(const char *str, time_t *date_from, time_t *date_to)
{ {
int ret = 0; int ret = 0;
char *s = xstrdup(str); char *s = xstrdup(str);
@ -438,7 +438,8 @@ int parse_args(int argc, char **argv)
int grep = 0, query = 0, next = 0; int grep = 0, query = 0, next = 0;
int status = 0, gc = 0, import = 0, export = 0; int status = 0, gc = 0, import = 0, export = 0;
/* Query ranges */ /* Query ranges */
long from = -1, range = -1, to = -1; time_t from = -1, to = -1;
int range = -1;
int limit = INT_MAX; int limit = INT_MAX;
/* Filters */ /* Filters */
struct item_filter filter = { 0, NULL, -1, -1, -1, -1, 0, 0, 0 }; struct item_filter filter = { 0, NULL, -1, -1, -1, -1, 0, 0, 0 };

View File

@ -406,10 +406,10 @@ enum item_type {
struct item_filter { struct item_filter {
int type_mask; int type_mask;
regex_t *regex; regex_t *regex;
long start_from; time_t start_from;
long start_to; time_t start_to;
long end_from; time_t end_from;
long end_to; time_t end_to;
int priority; int priority;
int completed; int completed;
int uncompleted; int uncompleted;
@ -699,7 +699,7 @@ unsigned ui_calendar_week_begins_on_monday(void);
void ui_calendar_store_current_date(struct date *); void ui_calendar_store_current_date(struct date *);
void ui_calendar_init_slctd_day(void); void ui_calendar_init_slctd_day(void);
struct date *ui_calendar_get_slctd_day(void); struct date *ui_calendar_get_slctd_day(void);
long ui_calendar_get_slctd_day_sec(void); time_t ui_calendar_get_slctd_day_sec(void);
void ui_calendar_monthly_view_cache_set_invalid(void); void ui_calendar_monthly_view_cache_set_invalid(void);
void ui_calendar_update_panel(void); void ui_calendar_update_panel(void);
void ui_calendar_goto_today(void); void ui_calendar_goto_today(void);
@ -954,11 +954,9 @@ void recur_apoint_write(struct recur_apoint *, FILE *);
void recur_event_write(struct recur_event *, FILE *); void recur_event_write(struct recur_event *, FILE *);
void recur_save_data(FILE *); void recur_save_data(FILE *);
unsigned recur_item_find_occurrence(long, long, llist_t *, int, unsigned recur_item_find_occurrence(long, long, llist_t *, int,
int, long, long, unsigned *); int, long, long, time_t *);
unsigned recur_apoint_find_occurrence(struct recur_apoint *, long, unsigned recur_apoint_find_occurrence(struct recur_apoint *, long, time_t *);
unsigned *); unsigned recur_event_find_occurrence(struct recur_event *, long, time_t *);
unsigned recur_event_find_occurrence(struct recur_event *, long,
unsigned *);
unsigned recur_item_inday(long, long, llist_t *, int, int, long, long); unsigned recur_item_inday(long, long, llist_t *, int, int, long, long);
unsigned recur_apoint_inday(struct recur_apoint *, long *); unsigned recur_apoint_inday(struct recur_apoint *, long *);
unsigned recur_event_inday(struct recur_event *, long *); unsigned recur_event_inday(struct recur_event *, long *);
@ -1053,17 +1051,17 @@ int is_all_digit(const char *);
long get_item_time(long); long get_item_time(long);
int get_item_hour(long); int get_item_hour(long);
int get_item_min(long); int get_item_min(long);
long date2sec(struct date, unsigned, unsigned); time_t date2sec(struct date, unsigned, unsigned);
long utcdate2sec(struct date, unsigned, unsigned); time_t utcdate2sec(struct date, unsigned, unsigned);
char *date_sec2date_str(long, const char *); char *date_sec2date_str(long, const char *);
void date_sec2date_fmt(long, const char *, char *); void date_sec2date_fmt(long, const char *, char *);
long date_sec_change(long, int, int); long date_sec_change(long, int, int);
long update_time_in_date(long, unsigned, unsigned); long update_time_in_date(long, unsigned, unsigned);
long get_sec_date(struct date); time_t get_sec_date(struct date);
long min2sec(unsigned); long min2sec(unsigned);
void draw_scrollbar(WINDOW *, int, int, int, int, int, unsigned); void draw_scrollbar(WINDOW *, int, int, int, int, int, unsigned);
void item_in_popup(const char *, const char *, const char *, const char *); void item_in_popup(const char *, const char *, const char *, const char *);
long get_today(void); time_t get_today(void);
long now(void); long now(void);
char *nowstr(void); char *nowstr(void);
void print_bool_option_incolor(WINDOW *, unsigned, int, int); void print_bool_option_incolor(WINDOW *, unsigned, int, int);
@ -1083,8 +1081,7 @@ int child_wait(int *, int *, int);
void press_any_key(void); void press_any_key(void);
void print_apoint(const char *, long, struct apoint *); void print_apoint(const char *, long, struct apoint *);
void print_event(const char *, long, struct event *); void print_event(const char *, long, struct event *);
void print_recur_apoint(const char *, long, unsigned, void print_recur_apoint(const char *, long, time_t, struct recur_apoint *);
struct recur_apoint *);
void print_recur_event(const char *, long, struct recur_event *); void print_recur_event(const char *, long, struct recur_event *);
void print_todo(const char *, struct todo *); void print_todo(const char *, struct todo *);
int vasprintf(char **, const char *, va_list); int vasprintf(char **, const char *, va_list);

View File

@ -308,7 +308,7 @@ static int day_store_recur_apoints(long date)
p.rapt = rapt; p.rapt = rapt;
unsigned real_start; time_t real_start;
if (recur_apoint_find_occurrence(rapt, date, &real_start)) { if (recur_apoint_find_occurrence(rapt, date, &real_start)) {
day_add_item(RECUR_APPT, real_start, p); day_add_item(RECUR_APPT, real_start, p);
a_nb++; a_nb++;
@ -358,7 +358,6 @@ day_store_items(long date, int include_captions)
*/ */
void day_process_storage(struct date *slctd_date, unsigned day_changed) void day_process_storage(struct date *slctd_date, unsigned day_changed)
{ {
long date;
struct date day; struct date day;
if (slctd_date) if (slctd_date)
@ -366,14 +365,12 @@ void day_process_storage(struct date *slctd_date, unsigned day_changed)
else else
ui_calendar_store_current_date(&day); ui_calendar_store_current_date(&day);
date = date2sec(day, 0, 0);
/* Inits */ /* Inits */
if (apad.length != 0) if (apad.length != 0)
delwin(apad.ptrwin); delwin(apad.ptrwin);
/* Store the events and appointments (recursive and normal items). */ /* Store the events and appointments (recursive and normal items). */
day_store_items(date, 1); day_store_items(date2sec(day, 0, 0), 1);
} }
/* /*
@ -508,25 +505,24 @@ void day_popup_item(struct day_item *day)
*/ */
int day_check_if_item(struct date day) int day_check_if_item(struct date day)
{ {
const long date = date2sec(day, 0, 0); const time_t t = date2sec(day, 0, 0);
if (LLIST_FIND_FIRST if (LLIST_FIND_FIRST(&recur_elist, (time_t *)&t, recur_event_inday))
(&recur_elist, (long *)&date, recur_event_inday))
return 1; return 1;
LLIST_TS_LOCK(&recur_alist_p); LLIST_TS_LOCK(&recur_alist_p);
if (LLIST_TS_FIND_FIRST if (LLIST_TS_FIND_FIRST(&recur_alist_p, (time_t *)&t,
(&recur_alist_p, (long *)&date, recur_apoint_inday)) { recur_apoint_inday)) {
LLIST_TS_UNLOCK(&recur_alist_p); LLIST_TS_UNLOCK(&recur_alist_p);
return 1; return 1;
} }
LLIST_TS_UNLOCK(&recur_alist_p); LLIST_TS_UNLOCK(&recur_alist_p);
if (LLIST_FIND_FIRST(&eventlist, (long *)&date, event_inday)) if (LLIST_FIND_FIRST(&eventlist, (time_t *)&t, event_inday))
return 1; return 1;
LLIST_TS_LOCK(&alist_p); LLIST_TS_LOCK(&alist_p);
if (LLIST_TS_FIND_FIRST(&alist_p, (long *)&date, apoint_inday)) { if (LLIST_TS_FIND_FIRST(&alist_p, (time_t *)&t, apoint_inday)) {
LLIST_TS_UNLOCK(&alist_p); LLIST_TS_UNLOCK(&alist_p);
return 1; return 1;
} }
@ -558,24 +554,24 @@ static unsigned fill_slices(int *slices, int slicesno, int first, int last)
*/ */
unsigned day_chk_busy_slices(struct date day, int slicesno, int *slices) unsigned day_chk_busy_slices(struct date day, int slicesno, int *slices)
{ {
const time_t t = date2sec(day, 0, 0);
llist_item_t *i; llist_item_t *i;
int slicelen; int slicelen;
const long date = date2sec(day, 0, 0);
slicelen = DAYINSEC / slicesno; slicelen = DAYINSEC / slicesno;
#define SLICENUM(tsec) ((tsec) / slicelen % slicesno) #define SLICENUM(tsec) ((tsec) / slicelen % slicesno)
LLIST_TS_LOCK(&recur_alist_p); LLIST_TS_LOCK(&recur_alist_p);
LLIST_TS_FIND_FOREACH(&recur_alist_p, (long *)&date, LLIST_TS_FIND_FOREACH(&recur_alist_p, (time_t *)&t,
recur_apoint_inday, i) { recur_apoint_inday, i) {
struct apoint *rapt = LLIST_TS_GET_DATA(i); struct apoint *rapt = LLIST_TS_GET_DATA(i);
long start = get_item_time(rapt->start); long start = get_item_time(rapt->start);
long end = get_item_time(rapt->start + rapt->dur); long end = get_item_time(rapt->start + rapt->dur);
if (rapt->start < date) if (rapt->start < t)
start = 0; start = 0;
if (rapt->start + rapt->dur >= date + DAYINSEC) if (rapt->start + rapt->dur >= t + DAYINSEC)
end = DAYINSEC - 1; end = DAYINSEC - 1;
if (!fill_slices if (!fill_slices
@ -587,16 +583,16 @@ unsigned day_chk_busy_slices(struct date day, int slicesno, int *slices)
LLIST_TS_UNLOCK(&recur_alist_p); LLIST_TS_UNLOCK(&recur_alist_p);
LLIST_TS_LOCK(&alist_p); LLIST_TS_LOCK(&alist_p);
LLIST_TS_FIND_FOREACH(&alist_p, (long *)&date, apoint_inday, i) { LLIST_TS_FIND_FOREACH(&alist_p, (time_t *)&t, apoint_inday, i) {
struct apoint *apt = LLIST_TS_GET_DATA(i); struct apoint *apt = LLIST_TS_GET_DATA(i);
long start = get_item_time(apt->start); long start = get_item_time(apt->start);
long end = get_item_time(apt->start + apt->dur); long end = get_item_time(apt->start + apt->dur);
if (apt->start >= date + DAYINSEC) if (apt->start >= t + DAYINSEC)
break; break;
if (apt->start < date) if (apt->start < t)
start = 0; start = 0;
if (apt->start + apt->dur >= date + DAYINSEC) if (apt->start + apt->dur >= t + DAYINSEC)
end = DAYINSEC - 1; end = DAYINSEC - 1;
if (!fill_slices if (!fill_slices

View File

@ -481,14 +481,13 @@ ical_chk_header(FILE * fd, char *buf, char *lstore, unsigned *lineno,
* *
* The timezone is not yet handled by calcurse. * The timezone is not yet handled by calcurse.
*/ */
static long ical_datetime2long(char *datestr, ical_vevent_e * type) static time_t ical_datetime2time_t(char *datestr, ical_vevent_e * type)
{ {
const int NOTFOUND = 0, FORMAT_DATE = 3, FORMAT_DATETIME = 6, const int FORMAT_DATE = 3, FORMAT_DATETIME = 6, FORMAT_DATETIMEZ = 7;
FORMAT_DATETIMEZ = 7;
struct date date; struct date date;
unsigned hour, min, sec; unsigned hour, min, sec;
char c; char c;
long datelong ; time_t t = 0;
int format; int format;
format = sscanf(datestr, "%04u%02u%02uT%02u%02u%02u%c", format = sscanf(datestr, "%04u%02u%02uT%02u%02u%02u%c",
@ -496,18 +495,16 @@ static long ical_datetime2long(char *datestr, ical_vevent_e * type)
if (format == FORMAT_DATE) { if (format == FORMAT_DATE) {
if (type) if (type)
*type = EVENT; *type = EVENT;
datelong = date2sec(date, 0, 0); t = date2sec(date, 0, 0);
} else if (format == FORMAT_DATETIME || format == FORMAT_DATETIMEZ) { } else if (format == FORMAT_DATETIME || format == FORMAT_DATETIMEZ) {
if (type) if (type)
*type = APPOINTMENT; *type = APPOINTMENT;
if (format == FORMAT_DATETIMEZ && c == 'Z') if (format == FORMAT_DATETIMEZ && c == 'Z')
datelong = utcdate2sec(date, hour, min); t = utcdate2sec(date, hour, min);
else else
datelong = date2sec(date, hour, min); t = date2sec(date, hour, min);
} else {
datelong = NOTFOUND;
} }
return datelong; return t;
} }
static long ical_durtime2long(char *timestr) static long ical_durtime2long(char *timestr)
@ -723,7 +720,7 @@ static ical_rpt_t *ical_read_rrule(FILE * log, char *rrulestr,
* specified, counts as the first occurrence. * specified, counts as the first occurrence.
*/ */
if ((p = strstr(rrulestr, "UNTIL")) != NULL) { if ((p = strstr(rrulestr, "UNTIL")) != NULL) {
rpt->until = ical_datetime2long(strchr(p, '=') + 1, NULL); rpt->until = ical_datetime2time_t(strchr(p, '=') + 1, NULL);
} else { } else {
unsigned cnt; unsigned cnt;
char *countstr; char *countstr;
@ -766,7 +763,6 @@ ical_read_exdate(llist_t * exc, FILE * log, char *exstr,
unsigned *noskipped, const int itemline) unsigned *noskipped, const int itemline)
{ {
char *p, *q; char *p, *q;
long date;
p = strchr(exstr, ':'); p = strchr(exstr, ':');
if (!p) { if (!p) {
@ -783,12 +779,10 @@ ical_read_exdate(llist_t * exc, FILE * log, char *exstr,
strncpy(buf, p, buflen); strncpy(buf, p, buflen);
buf[buflen] = '\0'; buf[buflen] = '\0';
date = ical_datetime2long(buf, NULL); ical_add_exc(exc, ical_datetime2time_t(buf, NULL));
ical_add_exc(exc, date);
p = ++q; p = ++q;
} }
date = ical_datetime2long(p, NULL); ical_add_exc(exc, ical_datetime2time_t(p, NULL));
ical_add_exc(exc, date);
} }
/* Return an allocated string containing the name of the newly created note. */ /* Return an allocated string containing the name of the newly created note. */
@ -944,7 +938,7 @@ ical_read_event(FILE * fdi, FILE * log, unsigned *noevents,
goto cleanup; goto cleanup;
} }
vevent.start = ical_datetime2long(++p, &vevent_type); vevent.start = ical_datetime2time_t(++p, &vevent_type);
if (!vevent.start) { if (!vevent.start) {
ical_log(log, ICAL_VEVENT, ITEMLINE, ical_log(log, ICAL_VEVENT, ITEMLINE,
_("could not retrieve event start time.")); _("could not retrieve event start time."));
@ -958,7 +952,7 @@ ical_read_event(FILE * fdi, FILE * log, unsigned *noevents,
goto cleanup; goto cleanup;
} }
vevent.end = ical_datetime2long(++p, &vevent_type); vevent.end = ical_datetime2time_t(++p, &vevent_type);
if (!vevent.end) { if (!vevent.end) {
ical_log(log, ICAL_VEVENT, ITEMLINE, ical_log(log, ICAL_VEVENT, ITEMLINE,
_("could not retrieve event end time.")); _("could not retrieve event end time."));

View File

@ -499,9 +499,8 @@ void notify_check_added(char *mesg, long start, char state)
/* Check if the newly repeated appointment is to be notified. */ /* Check if the newly repeated appointment is to be notified. */
void notify_check_repeated(struct recur_apoint *i) void notify_check_repeated(struct recur_apoint *i)
{ {
unsigned real_app_time; time_t current_time, real_app_time;
int update_notify = 0; int update_notify = 0;
time_t current_time;
current_time = time(NULL); current_time = time(NULL);
pthread_mutex_lock(&notify_app.mutex); pthread_mutex_lock(&notify_app.mutex);
@ -541,7 +540,7 @@ int notify_same_item(long time)
int notify_same_recur_item(struct recur_apoint *i) int notify_same_recur_item(struct recur_apoint *i)
{ {
int same = 0; int same = 0;
unsigned item_start = 0; time_t item_start = 0;
recur_item_find_occurrence(i->start, i->dur, &i->exc, i->rpt->type, recur_item_find_occurrence(i->start, i->dur, &i->exc, i->rpt->type,
i->rpt->freq, i->rpt->until, i->rpt->freq, i->rpt->until,

View File

@ -610,7 +610,7 @@ unsigned
recur_item_find_occurrence(long item_start, long item_dur, recur_item_find_occurrence(long item_start, long item_dur,
llist_t * item_exc, int rpt_type, int rpt_freq, llist_t * item_exc, int rpt_type, int rpt_freq,
long rpt_until, long day_start, long rpt_until, long day_start,
unsigned *occurrence) time_t *occurrence)
{ {
struct date start_date; struct date start_date;
long diff, span; long diff, span;
@ -696,7 +696,7 @@ recur_item_find_occurrence(long item_start, long item_dur,
unsigned unsigned
recur_apoint_find_occurrence(struct recur_apoint *rapt, long day_start, recur_apoint_find_occurrence(struct recur_apoint *rapt, long day_start,
unsigned *occurrence) time_t *occurrence)
{ {
return recur_item_find_occurrence(rapt->start, rapt->dur, return recur_item_find_occurrence(rapt->start, rapt->dur,
&rapt->exc, rapt->rpt->type, &rapt->exc, rapt->rpt->type,
@ -707,7 +707,7 @@ recur_apoint_find_occurrence(struct recur_apoint *rapt, long day_start,
unsigned unsigned
recur_event_find_occurrence(struct recur_event *rev, long day_start, recur_event_find_occurrence(struct recur_event *rev, long day_start,
unsigned *occurrence) time_t *occurrence)
{ {
return recur_item_find_occurrence(rev->day, DAYINSEC, &rev->exc, return recur_item_find_occurrence(rev->day, DAYINSEC, &rev->exc,
rev->rpt->type, rev->rpt->freq, rev->rpt->type, rev->rpt->freq,
@ -841,7 +841,7 @@ struct notify_app *recur_apoint_check_next(struct notify_app *app,
long start, long day) long start, long day)
{ {
llist_item_t *i; llist_item_t *i;
unsigned real_recur_start_time; time_t real_recur_start_time;
LLIST_TS_LOCK(&recur_alist_p); LLIST_TS_LOCK(&recur_alist_p);
LLIST_TS_FIND_FOREACH(&recur_alist_p, &app->time, LLIST_TS_FIND_FOREACH(&recur_alist_p, &app->time,

View File

@ -214,7 +214,7 @@ struct date *ui_calendar_get_slctd_day(void)
} }
/* Returned value represents the selected day in calendar (in seconds) */ /* Returned value represents the selected day in calendar (in seconds) */
long ui_calendar_get_slctd_day_sec(void) time_t ui_calendar_get_slctd_day_sec(void)
{ {
return date2sec(slctd_day, 0, 0); return date2sec(slctd_day, 0, 0);
} }

View File

@ -155,7 +155,7 @@ static void update_desc(char **desc)
static void update_rept(struct rpt **rpt, const long start) static void update_rept(struct rpt **rpt, const long start)
{ {
int newtype, newfreq; int newtype, newfreq;
long newuntil; time_t newuntil;
char *freqstr = NULL, *timstr, *outstr; char *freqstr = NULL, *timstr, *outstr;
const char *msg_rpt_prefix = _("Enter the new repetition type:"); const char *msg_rpt_prefix = _("Enter the new repetition type:");
const char *msg_rpt_daily = _("(d)aily"); const char *msg_rpt_daily = _("(d)aily");
@ -480,7 +480,7 @@ void ui_day_item_add(void)
const char *enter_str = _("Press [Enter] to continue"); const char *enter_str = _("Press [Enter] to continue");
char item_time[LDUR] = ""; char item_time[LDUR] = "";
char item_mesg[BUFSIZ] = ""; char item_mesg[BUFSIZ] = "";
long apoint_start; time_t apoint_start;
unsigned heures, minutes; unsigned heures, minutes;
unsigned apoint_duration; unsigned apoint_duration;
unsigned end_h, end_m; unsigned end_h, end_m;
@ -680,7 +680,7 @@ void ui_day_item_repeat(void)
int item_nb; int item_nb;
struct day_item *p; struct day_item *p;
struct recur_apoint *ra; struct recur_apoint *ra;
long until, date; time_t until, date;
if (day_item_count(0) <= 0) if (day_item_count(0) <= 0)
goto cleanup; goto cleanup;
@ -744,8 +744,7 @@ void ui_day_item_repeat(void)
until_date.dd = day; until_date.dd = day;
until_date.mm = month; until_date.mm = month;
until_date.yyyy = year; until_date.yyyy = year;
until = until = date2sec(until_date, lt.tm_hour, lt.tm_min);
date2sec(until_date, lt.tm_hour, lt.tm_min);
if (until >= p->start) if (until >= p->start)
break; break;
status_mesg(mesg_older, wrong_type_2); status_mesg(mesg_older, wrong_type_2);
@ -859,7 +858,7 @@ void ui_day_sel_move(int delta)
void ui_day_draw(int n, WINDOW *win, int y, int hilt, void *cb_data) void ui_day_draw(int n, WINDOW *win, int y, int hilt, void *cb_data)
{ {
struct date slctd_date = *ui_calendar_get_slctd_day(); struct date slctd_date = *ui_calendar_get_slctd_day();
long date = date2sec(slctd_date, 0, 0); time_t date = date2sec(slctd_date, 0, 0);
struct day_item *item = day_get_item(n); struct day_item *item = day_get_item(n);
int width = lb_apt.sw.w; int width = lb_apt.sw.w;

View File

@ -365,7 +365,7 @@ int get_item_min(long date)
return lt.tm_min; return lt.tm_min;
} }
long date2sec(struct date day, unsigned hour, unsigned min) time_t date2sec(struct date day, unsigned hour, unsigned min)
{ {
time_t t = now(); time_t t = now();
struct tm start; struct tm start;
@ -386,8 +386,7 @@ long date2sec(struct date day, unsigned hour, unsigned min)
return t; return t;
} }
time_t time_t utcdate2sec(struct date day, unsigned hour, unsigned min)
utcdate2sec(struct date day, unsigned hour, unsigned min)
{ {
char *tz; char *tz;
time_t t; time_t t;
@ -488,11 +487,10 @@ long update_time_in_date(long date, unsigned hr, unsigned mn)
* Returns the date in seconds from year 1900. * Returns the date in seconds from year 1900.
* If no date is entered, current date is chosen. * If no date is entered, current date is chosen.
*/ */
long get_sec_date(struct date date) time_t get_sec_date(struct date date)
{ {
struct tm ptrtime; struct tm ptrtime;
time_t timer; time_t timer;
long long_date;
char current_day[] = "dd "; char current_day[] = "dd ";
char current_month[] = "mm "; char current_month[] = "mm ";
char current_year[] = "yyyy "; char current_year[] = "yyyy ";
@ -501,16 +499,14 @@ long get_sec_date(struct date date)
timer = time(NULL); timer = time(NULL);
localtime_r(&timer, &ptrtime); localtime_r(&timer, &ptrtime);
strftime(current_day, strlen(current_day), "%d", &ptrtime); strftime(current_day, strlen(current_day), "%d", &ptrtime);
strftime(current_month, strlen(current_month), "%m", strftime(current_month, strlen(current_month), "%m", &ptrtime);
&ptrtime); strftime(current_year, strlen(current_year), "%Y", &ptrtime);
strftime(current_year, strlen(current_year), "%Y",
&ptrtime);
date.mm = atoi(current_month); date.mm = atoi(current_month);
date.dd = atoi(current_day); date.dd = atoi(current_day);
date.yyyy = atoi(current_year); date.yyyy = atoi(current_year);
} }
long_date = date2sec(date, 0, 0);
return long_date; return date2sec(date, 0, 0);
} }
long min2sec(unsigned minutes) long min2sec(unsigned minutes)
@ -566,11 +562,10 @@ item_in_popup(const char *a_start, const char *a_end, const char *msg,
} }
/* Returns the beginning of current day in seconds from 1900. */ /* Returns the beginning of current day in seconds from 1900. */
long get_today(void) time_t get_today(void)
{ {
struct tm lt; struct tm lt;
time_t current_time; time_t current_time;
long current_day;
struct date day; struct date day;
current_time = time(NULL); current_time = time(NULL);
@ -578,9 +573,8 @@ long get_today(void)
day.mm = lt.tm_mon + 1; day.mm = lt.tm_mon + 1;
day.dd = lt.tm_mday; day.dd = lt.tm_mday;
day.yyyy = lt.tm_year + 1900; day.yyyy = lt.tm_year + 1900;
current_day = date2sec(day, 0, 0);
return current_day; return date2sec(day, 0, 0);
} }
/* Returns the current time in seconds. */ /* Returns the current time in seconds. */
@ -1500,7 +1494,7 @@ void print_event(const char *format, long day, struct event *ev)
/* Print a formatted recurrent appointment to stdout. */ /* Print a formatted recurrent appointment to stdout. */
void void
print_recur_apoint(const char *format, long day, unsigned occurrence, print_recur_apoint(const char *format, long day, time_t occurrence,
struct recur_apoint *rapt) struct recur_apoint *rapt)
{ {
struct apoint apt; struct apoint apt;