Added 'date' element type accepting YYYYMMDD
[pazpar2-moved-to-github.git] / src / normalize7bit.c
index 2bbfc2c..d5464e6 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: normalize7bit.c,v 1.3 2007-09-07 10:27:14 adam Exp $
+/* $Id: normalize7bit.c,v 1.5 2007-10-31 05:29:08 quinn Exp $
    Copyright (c) 2006-2007, Index Data.
 
    This file is part of Pazpar2.
@@ -34,6 +34,7 @@
 #include "normalize7bit.h"
 
 
+/** \brief removes leading whitespace.. Removes suffix cahrs in rm_chars */
 char * normalize7bit_generic(char * str, const char * rm_chars)
 {
     char *p, *pe;
@@ -90,7 +91,8 @@ char * normalize7bit_mergekey(char *buf, int skiparticle)
 
 // Extract what appears to be years from buf, storing highest and
 // lowest values.
-int extract7bit_years(const char *buf, int *first, int *last)
+// longdate==1, look for YYYYMMDD, longdate=0 look only for YYYY
+int extract7bit_dates(const char *buf, int *first, int *last, int longdate)
 {
     *first = -1;
     *last = -1;
@@ -104,9 +106,11 @@ int extract7bit_years(const char *buf, int *first, int *last)
         len = 0;
         for (e = buf; *e && isdigit(*e); e++)
             len++;
-        if (len == 4)
+        if ((len == 4 && !longdate) || (longdate && len >= 4 && len <= 8))
         {
             int value = atoi(buf);
+            if (longdate && len == 4)
+                value *= 10000; //  should really suffix 0101?
             if (*first < 0 || value < *first)
                 *first = value;
             if (*last < 0 || value > *last)