Index: misc.cc
===================================================================
RCS file: /home/lav/cvsroot/lftp/src/misc.cc,v
retrieving revision 1.77
diff -u -p -r1.77 misc.cc
--- misc.cc	25 Oct 2005 12:16:43 -0000	1.77
+++ misc.cc	1 Dec 2005 13:24:19 -0000
@@ -407,17 +407,31 @@ const char *format_perms(int p)
    return s;
 }
 
-const char month_names[][4]={
-   "Jan","Feb","Mar","Apr","May","Jun",
-   "Jul","Aug","Sep","Oct","Nov","Dec",
-   ""
+const char *month_names[] =
+{
+    "Jan", "Feb", "Mar", "Apr", "May", "Jun",
+    "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
+};
+
+const int month_days[] =
+{
+    31, 28, 31, 30, 31, 30,
+    31, 31, 30, 31, 30, 31
 };
+
 int parse_month(const char *m)
 {
-   for(int i=0; month_names[i][0]; i++)
-      if(!strcasecmp(month_names[i],m))
-	 return(i%12);
-   return -1;
+    unsigned int i;
+
+    for (i = 0; i < (sizeof(month_names) / sizeof(month_names[0])); i++)
+    {
+        if (strcasecmp(m, month_names[i]) == 0)
+        {
+            return(i);
+        }
+    }
+
+    return(-1);
 }
 
 int parse_year_or_time(const char *year_or_time,int *year,int *hour,int *minute)
@@ -436,15 +450,65 @@ int parse_year_or_time(const char *year_
    }
    return 0;
 }
+
+bool last_day_of_month(int month, int day, int year)
+{
+    if (month == 1)
+    {
+        // Month is February, check if this is a leap year
+
+        if ((year % 4) == 0)
+        {
+            if (((year % 100) != 0) || ((year % 400) == 0))
+            {
+                // This is a leap year, add 1 day to February
+
+                return(day == (month_days[month] + 1));
+            }
+        }
+    }
+
+    return(day == month_days[month]);
+}
+
 int guess_year(int month,int day,int hour,int minute)
 {
-   const struct tm &now=SMTask::now;
-   int year=now.tm_year+1900;
-   if(month     *32+        day
-    > now.tm_mon*32+now.tm_mday+1)
-      year--;
-   return year;
+    const struct tm &now=SMTask::now;
+    int year=now.tm_year+1900;
+
+    /*
+     * Due to the possibility of a time difference up to 1 day between the
+     * client and the server, the client should make sure that the file's date
+     * is greater than 1 day away before assuming it is from last year.
+     */
+
+    if (month == now.tm_mon)
+    {
+        if (day > (now.tm_mday + 1))
+        {
+            year--;
+        }
+    }
+    else if (month == (now.tm_mon + 1))
+    {
+        /* If the day is not the first of next month or we are not on the last
+         * day of this month then the file is from last year
+         */
+
+        if ((day != 1) ||
+            (last_day_of_month(now.tm_mon, now.tm_mday, year) == false))
+        {
+            year--;
+        }
+    }
+    else if (month > (now.tm_mon + 1))
+    {
+        year--;
+    }
+
+    return(year);
 }
+
 int percent(off_t offset,off_t size)
 {
    if(offset>=size)
Index: misc.h
===================================================================
RCS file: /home/lav/cvsroot/lftp/src/misc.h,v
retrieving revision 1.38
diff -u -p -r1.38 misc.h
--- misc.h	18 Oct 2005 06:37:33 -0000	1.38
+++ misc.h	1 Dec 2005 13:24:21 -0000
@@ -74,9 +74,11 @@ int percent(off_t offset,off_t size);
 #define HOUR   (60*MINUTE)
 #define DAY    (24*HOUR)
 
-extern const char month_names[][4];
+extern const char *month_names[];
+extern const int month_days[];
 
-int parse_month(const char *);
+int parse_month(const char *m);
+bool last_day_of_month(int month, int day, int year);
 int parse_perms(const char *);
 const char *format_perms(int p);
 int parse_year_or_time(const char *year_or_time,int *year,int *hour,int *minute);
