summaryrefslogtreecommitdiff
path: root/src/libical/icaltime.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/libical/icaltime.c')
-rw-r--r--src/libical/icaltime.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/src/libical/icaltime.c b/src/libical/icaltime.c
index 223ebb0a..fe03aee5 100644
--- a/src/libical/icaltime.c
+++ b/src/libical/icaltime.c
@@ -111,6 +111,7 @@ static time_t icaltime_timegm(const struct tm *tm)
static time_t make_time(struct tm *tm, int tzm)
{
time_t tim;
+ int febs;
static int days[] = { -1, 30, 58, 89, 119, 150, 180, 211, 242, 272, 303, 333, 364 };
@@ -145,12 +146,17 @@ static time_t make_time(struct tm *tm, int tzm)
tim = (time_t) ((tm->tm_year - 70) * 365 + ((tm->tm_year - 1) / 4) - 17);
+ /* adjust: no leap days every 100 years, except every 400 years. */
+
+ febs = (tm->tm_year - 100) - ((tm->tm_mon <= 1) ? 1 : 0);
+ tim -= febs / 100;
+ tim += febs / 400;
+
/* add number of days elapsed in the current year */
tim += days[tm->tm_mon];
- /* check and adjust for leap years (the leap year check only valid
- during the 32-bit era */
+ /* check and adjust for leap years */
if ((tm->tm_year & 3) == 0 && tm->tm_mon > 1)
tim += 1;