Patch to correct the wrong calculation of recurrent items' dates after a
turn of year (submitted by Lukas Fleischer, thanks!).
This commit is contained in:
parent
2ec8ab17ac
commit
b2321a7567
11
ChangeLog
11
ChangeLog
@ -1,3 +1,14 @@
|
|||||||
|
2010-03-08 Frederic Culot <frederic@culot.org>
|
||||||
|
|
||||||
|
* src/recur.c (diff_days, diff_weeks, diff_months, diff_years):
|
||||||
|
new functions provided by Lukas Fleischer
|
||||||
|
* src/recur.c (recur_item_inday): patch provided by Lukas
|
||||||
|
Fleischer to correct the wrong calculation of recurrent dates
|
||||||
|
after a turn of years
|
||||||
|
|
||||||
|
* src/calendar.h: defines related to dates moved from calendar.c
|
||||||
|
and vars.h
|
||||||
|
|
||||||
2010-03-01 Frederic Culot <frederic@culot.org>
|
2010-03-01 Frederic Culot <frederic@culot.org>
|
||||||
|
|
||||||
* src/calendar.c (calendar_date_thread): avoid compilation
|
* src/calendar.c (calendar_date_thread): avoid compilation
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
/* $calcurse: calendar.c,v 1.31 2010/03/01 18:55:45 culot Exp $ */
|
/* $calcurse: calendar.c,v 1.32 2010/03/08 08:44:44 culot Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Calcurse - text-based organizer
|
* Calcurse - text-based organizer
|
||||||
*
|
*
|
||||||
* Copyright (c) 2004-2009 Frederic Culot <frederic@culot.org>
|
* Copyright (c) 2004-2010 Frederic Culot <frederic@culot.org>
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@ -64,7 +64,6 @@
|
|||||||
#define lzero 318.351648 /* lunar mean long at EPOCH */
|
#define lzero 318.351648 /* lunar mean long at EPOCH */
|
||||||
#define Pzero 36.340410 /* lunar mean long of perigee at EPOCH */
|
#define Pzero 36.340410 /* lunar mean long of perigee at EPOCH */
|
||||||
#define Nzero 318.510107 /* lunar mean long of node at EPOCH */
|
#define Nzero 318.510107 /* lunar mean long of node at EPOCH */
|
||||||
#define TM_YEAR_BASE 1900
|
|
||||||
|
|
||||||
#define isleap(y) ((((y) % 4) == 0 && ((y) % 100) != 0) || ((y) % 400) == 0)
|
#define isleap(y) ((((y) % 4) == 0 && ((y) % 100) != 0) || ((y) % 400) == 0)
|
||||||
|
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
/* $calcurse: calendar.h,v 1.18 2009/10/28 15:15:43 culot Exp $ */
|
/* $calcurse: calendar.h,v 1.19 2010/03/08 08:44:44 culot Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Calcurse - text-based organizer
|
* Calcurse - text-based organizer
|
||||||
*
|
*
|
||||||
* Copyright (c) 2004-2009 Frederic Culot <frederic@culot.org>
|
* Copyright (c) 2004-2010 Frederic Culot <frederic@culot.org>
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@ -60,6 +60,14 @@
|
|||||||
#define CALHEIGHT 12
|
#define CALHEIGHT 12
|
||||||
#define CALWIDTH 30
|
#define CALWIDTH 30
|
||||||
|
|
||||||
|
#define DAYINSEC 86400
|
||||||
|
#define HOURINSEC 3600
|
||||||
|
#define MININSEC 60
|
||||||
|
#define YEARINDAYS 365
|
||||||
|
#define YEARINMONTHS 12
|
||||||
|
#define WEEKINDAYS 7
|
||||||
|
#define TM_YEAR_BASE 1900
|
||||||
|
|
||||||
typedef enum
|
typedef enum
|
||||||
{ /* days of week */
|
{ /* days of week */
|
||||||
SUNDAY,
|
SUNDAY,
|
||||||
|
81
src/recur.c
81
src/recur.c
@ -1,9 +1,9 @@
|
|||||||
/* $calcurse: recur.c,v 1.52 2009/07/19 08:20:01 culot Exp $ */
|
/* $calcurse: recur.c,v 1.53 2010/03/08 08:44:44 culot Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Calcurse - text-based organizer
|
* Calcurse - text-based organizer
|
||||||
*
|
*
|
||||||
* Copyright (c) 2004-2009 Frederic Culot <frederic@culot.org>
|
* Copyright (c) 2004-2010 Frederic Culot <frederic@culot.org>
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@ -55,6 +55,7 @@ struct recur_event_s *recur_elist;
|
|||||||
static struct recur_event_s bkp_cut_recur_event;
|
static struct recur_event_s bkp_cut_recur_event;
|
||||||
static recur_apoint_llist_node_t bkp_cut_recur_apoint;
|
static recur_apoint_llist_node_t bkp_cut_recur_apoint;
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
free_exc (struct days_s *exc)
|
free_exc (struct days_s *exc)
|
||||||
{
|
{
|
||||||
@ -589,11 +590,78 @@ recur_save_data (FILE *f)
|
|||||||
pthread_mutex_unlock (&(recur_alist_p->mutex));
|
pthread_mutex_unlock (&(recur_alist_p->mutex));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The two following defines together with the diff_days, diff_weeks,
|
||||||
|
* diff_months and diff_years functions were provided by Lukas Fleischer to
|
||||||
|
* correct the wrong calculation of recurrent dates after a turn of year.
|
||||||
|
*/
|
||||||
|
#define bc(start, end, bs) \
|
||||||
|
(((end) - (start) + ((start) % bs) - ((end) % bs)) / bs \
|
||||||
|
+ ((((start) % bs) == 0) ? 1 : 0))
|
||||||
|
|
||||||
|
#define leapcount(start, end) \
|
||||||
|
(bc(start, end, 4) - bc(start, end, 100) + bc(start, end, 400))
|
||||||
|
|
||||||
|
|
||||||
|
/* Calculate the difference in days between two dates. */
|
||||||
|
static long
|
||||||
|
diff_days (struct tm lt_start, struct tm lt_end)
|
||||||
|
{
|
||||||
|
long diff;
|
||||||
|
|
||||||
|
if (lt_end.tm_year < lt_start.tm_year)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
diff = lt_end.tm_yday - lt_start.tm_yday;
|
||||||
|
|
||||||
|
if (lt_end.tm_year > lt_start.tm_year)
|
||||||
|
{
|
||||||
|
diff += (lt_end.tm_year - lt_start.tm_year) * YEARINDAYS;
|
||||||
|
diff += leapcount (lt_start.tm_year + TM_YEAR_BASE,
|
||||||
|
lt_end.tm_year + TM_YEAR_BASE - 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
return diff;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Calculate the difference in weeks between two dates. */
|
||||||
|
static long
|
||||||
|
diff_weeks (struct tm lt_start, struct tm lt_end)
|
||||||
|
{
|
||||||
|
return diff_days (lt_start, lt_end) / WEEKINDAYS;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Calculate the difference in months between two dates. */
|
||||||
|
static long
|
||||||
|
diff_months (struct tm lt_start, struct tm lt_end)
|
||||||
|
{
|
||||||
|
long diff;
|
||||||
|
|
||||||
|
if (lt_end.tm_year < lt_start.tm_year)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
diff = lt_end.tm_mon - lt_start.tm_mon;
|
||||||
|
diff += (lt_end.tm_year - lt_start.tm_year) * YEARINMONTHS;
|
||||||
|
|
||||||
|
return diff;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Calculate the difference in years between two dates. */
|
||||||
|
static long
|
||||||
|
diff_years (struct tm lt_start, struct tm lt_end)
|
||||||
|
{
|
||||||
|
return lt_end.tm_year - lt_start.tm_year;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Check if the recurrent item belongs to the selected day,
|
* Check if the recurrent item belongs to the selected day,
|
||||||
* and if yes, return the real start time.
|
* and if yes, return the real start time.
|
||||||
|
*
|
||||||
* This function was improved thanks to Tony's patch.
|
* This function was improved thanks to Tony's patch.
|
||||||
* Thanks also to youshe for reporting daylight saving time related problems.
|
* Thanks also to youshe for reporting daylight saving time related problems.
|
||||||
|
* And finally thanks to Lukas for providing a patch to correct the wrong
|
||||||
|
* calculation of recurrent dates after a turn of years.
|
||||||
*/
|
*/
|
||||||
unsigned
|
unsigned
|
||||||
recur_item_inday (long item_start, struct days_s *item_exc, int rpt_type,
|
recur_item_inday (long item_start, struct days_s *item_exc, int rpt_type,
|
||||||
@ -625,7 +693,7 @@ recur_item_inday (long item_start, struct days_s *item_exc, int rpt_type,
|
|||||||
switch (rpt_type)
|
switch (rpt_type)
|
||||||
{
|
{
|
||||||
case RECUR_DAILY:
|
case RECUR_DAILY:
|
||||||
diff = lt_day.tm_yday - lt_item.tm_yday;
|
diff = diff_days (lt_item, lt_day);
|
||||||
if (diff % rpt_freq != 0)
|
if (diff % rpt_freq != 0)
|
||||||
return (0);
|
return (0);
|
||||||
lt_item.tm_mday = lt_day.tm_mday;
|
lt_item.tm_mday = lt_day.tm_mday;
|
||||||
@ -637,7 +705,7 @@ recur_item_inday (long item_start, struct days_s *item_exc, int rpt_type,
|
|||||||
return (0);
|
return (0);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
diff = ((lt_day.tm_yday - lt_item.tm_yday) / WEEKINDAYS);
|
diff = diff_weeks (lt_item, lt_day);
|
||||||
if (diff % rpt_freq != 0)
|
if (diff % rpt_freq != 0)
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
@ -646,15 +714,14 @@ recur_item_inday (long item_start, struct days_s *item_exc, int rpt_type,
|
|||||||
lt_item.tm_year = lt_day.tm_year;
|
lt_item.tm_year = lt_day.tm_year;
|
||||||
break;
|
break;
|
||||||
case RECUR_MONTHLY:
|
case RECUR_MONTHLY:
|
||||||
diff = (((lt_day.tm_year - lt_item.tm_year) * 12)
|
diff = diff_months (lt_item, lt_day);
|
||||||
+ (lt_day.tm_mon - lt_item.tm_mon));
|
|
||||||
if (diff % rpt_freq != 0)
|
if (diff % rpt_freq != 0)
|
||||||
return (0);
|
return (0);
|
||||||
lt_item.tm_mon = lt_day.tm_mon;
|
lt_item.tm_mon = lt_day.tm_mon;
|
||||||
lt_item.tm_year = lt_day.tm_year;
|
lt_item.tm_year = lt_day.tm_year;
|
||||||
break;
|
break;
|
||||||
case RECUR_YEARLY:
|
case RECUR_YEARLY:
|
||||||
diff = lt_day.tm_year - lt_item.tm_year;
|
diff = diff_years (lt_item, lt_day);
|
||||||
if (diff % rpt_freq != 0)
|
if (diff % rpt_freq != 0)
|
||||||
return (0);
|
return (0);
|
||||||
lt_item.tm_year = lt_day.tm_year;
|
lt_item.tm_year = lt_day.tm_year;
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
/* $calcurse: vars.h,v 1.37 2009/08/01 13:31:21 culot Exp $ */
|
/* $calcurse: vars.h,v 1.38 2010/03/08 08:44:44 culot Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Calcurse - text-based organizer
|
* Calcurse - text-based organizer
|
||||||
*
|
*
|
||||||
* Copyright (c) 2004-2009 Frederic Culot <frederic@culot.org>
|
* Copyright (c) 2004-2010 Frederic Culot <frederic@culot.org>
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@ -82,11 +82,6 @@
|
|||||||
#define ATTR_HIGH 5
|
#define ATTR_HIGH 5
|
||||||
#define ATTR_HIGHEST 6
|
#define ATTR_HIGHEST 6
|
||||||
|
|
||||||
#define DAYINSEC 86400
|
|
||||||
#define HOURINSEC 3600
|
|
||||||
#define MININSEC 60
|
|
||||||
#define WEEKINDAYS 7
|
|
||||||
|
|
||||||
#define STATUSHEIGHT 2
|
#define STATUSHEIGHT 2
|
||||||
#define NOTESIZ 6
|
#define NOTESIZ 6
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user