aboutsummaryrefslogtreecommitdiffstats
path: root/src/utils.c
diff options
context:
space:
mode:
authorLars Henriksen <LarsHenriksen@get2net.dk>2017-11-19 22:51:57 +0100
committerLukas Fleischer <lfleischer@calcurse.org>2017-11-23 08:56:38 +0100
commit691d6b33ee7454f9559239b86387bb5673274bec (patch)
tree419631c296cc4a5dba2e385611fb40713e285e7f /src/utils.c
parent97c3e7f95726533897c3e65a09ffd2cd02d7e187 (diff)
downloadcalcurse-691d6b33ee7454f9559239b86387bb5673274bec.tar.gz
calcurse-691d6b33ee7454f9559239b86387bb5673274bec.zip
Check for the year span 1902-2037
Reintroduce year check for systems with a 32-bit time_t type. Remove the lower limit (1902) for systems with a 64-bit time_t. This limits movements in the calendar (for 32-bit systems) and in no way ensures constistency of data. Commit a12833e (Handle dates past January 19th, 2038, 2015-01-19) removed the upper limit (2037) on dates but left the lower limit (1902). It did not ensure the support of the target system. Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
Diffstat (limited to 'src/utils.c')
-rw-r--r--src/utils.c14
1 files changed, 8 insertions, 6 deletions
diff --git a/src/utils.c b/src/utils.c
index f3739ea..c046ad5 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -481,7 +481,7 @@ void date_sec2date_fmt(long sec, const char *fmt, char *datef)
}
/*
- * Used to change date by adding a certain amount of days or weeks.
+ * Used to change date by adding a certain amount of days or months.
* Returns 0 on success, 1 otherwise.
*/
int date_change(struct tm *date, int delta_month, int delta_day)
@@ -501,7 +501,7 @@ int date_change(struct tm *date, int delta_month, int delta_day)
}
/*
- * Used to change date by adding a certain amount of days or weeks.
+ * Used to change date by adding a certain amount of days or months.
*/
long date_sec_change(long date, int delta_month, int delta_day)
{
@@ -540,7 +540,7 @@ 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 1970.
* If no date is entered, current date is chosen.
*/
time_t get_sec_date(struct date date)
@@ -617,7 +617,7 @@ item_in_popup(const char *a_start, const char *a_end, const char *msg,
delwin(popup_win);
}
-/* Returns the beginning of current day in seconds from 1900. */
+/* Returns the beginning of current day in seconds from 1970. */
time_t get_today(void)
{
struct tm lt;
@@ -749,11 +749,13 @@ static void get_weekday_ymd(int *year, int *month, int *day, int weekday)
}
/*
- * Check if a date is valid.
+ * Check if a calcurse date is valid.
*/
int check_date(unsigned year, unsigned month, unsigned day)
{
- return (year >= 1902 && month >= 1 && month <= 12 && day >= 1 &&
+ return ((YEAR1902_2037 ? year >= 1902 && year <= 2037 : 1) &&
+ month >= 1 && month <= 12 &&
+ day >= 1 &&
day <= days[month - 1] + (month == 2 && ISLEAP(year)) ? 1 : 0);
}