Index: trunk/psModules/src/concepts/pmConceptsStandard.c
===================================================================
--- trunk/psModules/src/concepts/pmConceptsStandard.c	(revision 7017)
+++ trunk/psModules/src/concepts/pmConceptsStandard.c	(revision 7253)
@@ -288,15 +288,50 @@
     }
 
+    // Work out how the time is represented
+    bool usaTime = false;               // Is the time specified in USA (MM-DD-YYYY) order?
+    bool backwardsTime = false;         // Is the time specified in backwards (DD-MM-YYYY) order?
+    bool pre2000Time = false;           // Is the time specified pre-2000 (where the year only has two digits)
+    bool mjdTime = false;               // Is the time specified a MJD?
+    bool jdTime = false;                // Is the time specified a JD?
+
     // Get format
     psMetadata *formats = psMetadataLookupMD(&mdok, cameraFormat, "FORMATS");
-    if (!mdok || !formats) {
-        psError(PS_ERR_IO, false, "Unable to find FORMATS in camera configuration.\n");
-        return NULL;
-    }
-
-    psString timeFormat = psMetadataLookupStr(&mdok, formats, "CELL.TIME");
-    if (!mdok || strlen(timeFormat) == 0) {
-        psError(PS_ERR_IO, false, "Unable to find CELL.TIME in FORMATS.\n");
-        return NULL;
+    if (mdok && formats) {
+        psString timeFormat = psMetadataLookupStr(&mdok, formats, "CELL.TIME");
+        if (mdok && timeFormat && strlen(timeFormat) > 0) {
+            // Parse the time format
+            psList *timeFormats = psStringSplit(timeFormat, " ,;", false); // List of the format options
+            psListIterator *timeFormatsIter = psListIteratorAlloc(timeFormats, PS_LIST_HEAD, false); // Iter
+            while ((timeFormat = psListGetAndIncrement(timeFormatsIter))) {
+                if (strcasecmp(timeFormat, "USA") == 0) {
+                    usaTime = true;
+                    backwardsTime = false;
+                    jdTime = false;
+                    mjdTime = false;
+                } else if (strcasecmp(timeFormat, "BACKWARDS") == 0) {
+                    backwardsTime = true;
+                    usaTime = false;
+                    jdTime = false;
+                    mjdTime = false;
+                } else if (strcasecmp(timeFormat, "PRE2000") == 0) {
+                    pre2000Time = true;
+                } else if (strcasecmp(timeFormat, "MJD") == 0) {
+                    mjdTime = true;
+                    jdTime = false;
+                    backwardsTime = false;
+                    usaTime = false;
+                } else if (strcasecmp(timeFormat, "JD") == 0) {
+                    jdTime = true;
+                    mjdTime = false;
+                    backwardsTime = false;
+                    usaTime = false;
+                } else {
+                    psLogMsg(__func__, PS_LOG_WARN, "Unrecognised FORMATS option for CELL.TIME: %s --- "
+                             "ignored.\n", timeFormat);
+                }
+            }
+            psFree(timeFormatsIter);
+            psFree(timeFormats);
+        }
     }
 
@@ -315,18 +350,25 @@
             psString dateString = dateItem->data.V; // The string with the date
             int day = 0, month = 0, year = 0;
-            if (sscanf(dateString, "%d-%d-%d", &day, &month, &year) != 3 &&
-                    sscanf(dateString, "%d/%d/%d", &day, &month, &year) != 3) {
+            if (sscanf(dateString, "%d-%d-%d", &year, &month, &day) != 3 &&
+                    sscanf(dateString, "%d/%d/%d", &year, &month, &day) != 3) {
                 psError(PS_ERR_IO, true, "Unable to read date: %s\n", dateString);
                 return NULL;
             }
-            if (strstr(timeFormat, "BACKWARDS")) {
+            if (backwardsTime) {
+                // Need to switch days and years
                 int temp = day;
                 day = year;
                 year = temp;
             }
-            if (strstr(timeFormat, "PRE2000") || year < 2000) {
+            if (usaTime) {
+                // Need to switch everything around.... Yanks!
+                int temp = day;
+                day = month;
+                month = year;
+                year = temp;
+            }
+            if (pre2000Time || year < 2000) {
                 year += 2000;
             }
-
             psString timeString = NULL; // The string with the time
             if (timeItem->type == PS_DATA_STRING) {
@@ -362,16 +404,12 @@
     case PS_DATA_STRING: {
             psString timeString = concept->data.V;   // String with the time
-            if (strcasecmp(timeFormat, "ISO") == 0) {
-                // timeString contains an ISO time
-                time = psTimeFromISO(timeString, timeSys);
-            } else if (strcasecmp(timeFormat, "JD") == 0) {
+            if (jdTime) {
                 double timeValue = strtod (timeString, NULL);
                 time = psTimeFromJD(timeValue);
-            } else if (strcasecmp(timeFormat, "MJD") == 0) {
+            } else if (mjdTime) {
                 double timeValue = strtod (timeString, NULL);
                 time = psTimeFromMJD(timeValue);
             } else {
-                psError(PS_ERR_IO, true, "Not sure how to parse CELL.TIME (%s) --- trying "
-                        "ISO\n", timeString);
+                // It's ISO
                 time = psTimeFromISO(timeString, timeSys);
             } // Interpreting the time string
@@ -380,11 +418,10 @@
     case PS_TYPE_F32: {
             double timeValue = (double)concept->data.F32;
-            if (strcasecmp(timeFormat, "JD") == 0) {
+            if (jdTime) {
                 time = psTimeFromJD(timeValue);
-            } else if (strcasecmp(timeFormat, "MJD") == 0) {
+            } else if (mjdTime) {
                 time = psTimeFromMJD(timeValue);
             } else {
-                psError(PS_ERR_IO, true, "Not sure how to parse CELL.TIME (%f) --- trying "
-                        "JD\n", timeValue);
+                psError(PS_ERR_IO, true, "Not sure how to parse CELL.TIME (%f) --- trying JD\n", timeValue);
                 time = psTimeFromJD(timeValue);
             }
@@ -393,11 +430,10 @@
     case PS_TYPE_F64: {
             double timeValue = (double)concept->data.F64;
-            if (strcasecmp(timeFormat, "JD") == 0) {
+            if (jdTime) {
                 time = psTimeFromJD(timeValue);
-            } else if (strcasecmp(timeFormat, "MJD") == 0) {
+            } else if (mjdTime) {
                 time = psTimeFromMJD(timeValue);
             } else {
-                psError(PS_ERR_IO, true, "Not sure how to parse CELL.TIME (%f) --- trying "
-                        "JD\n", timeValue);
+                psError(PS_ERR_IO, true, "Not sure how to parse CELL.TIME (%f) --- trying JD\n", timeValue);
                 time = psTimeFromJD(timeValue);
             }
@@ -557,14 +593,56 @@
 {
     psTime *time = concept->data.V;     // The time
-    psMetadata *formats = psMetadataLookupMD(NULL, cameraFormat, "FORMATS");
-    psString format = psMetadataLookupStr(NULL, formats, "CELL.TIME");
-
-    if (strlen(format) == 0 || strcasecmp(format, "ISO") == 0) {
-        psString dateTimeString = psTimeToISO(time); // String representation
-        psMetadataItem *item = psMetadataItemAllocStr(concept->name, concept->comment, dateTimeString);
-        psFree(dateTimeString);
-        return item;
-    }
-    if (strstr(format, "SEPARATE")) {
+
+    // Work out the format
+    bool separateTime = false;          // Are the date and time stored separately?
+    bool pre2000Time = false;           // Is the year in pre-2000 format (two digits only)?
+    bool backwardsTime = false;         // Is the date stored backwards (DD-MM-YYYY)?
+    bool usaTime = false;               // Is the date stored in USA order (MM-DD-YYYY)?
+    bool jdTime = false;                // Is the date stored as a JD?
+    bool mjdTime = false;               // Is the date stored as a MJD?
+
+    bool mdok = true;                   // Status of MD lookup
+    psMetadata *formats = psMetadataLookupMD(&mdok, cameraFormat, "FORMATS"); // The formats
+    if (mdok && formats) {
+        psString format = psMetadataLookupStr(&mdok, formats, "CELL.TIME"); // The formats for CELL.TIME
+        if (mdok && format && strlen(format) > 0) {
+            psList *formatList = psStringSplit(format, " ,;", false); // List of formats specified
+            psListIterator *formatListIter = psListIteratorAlloc(formatList, PS_LIST_HEAD, false); // Iterator
+            while ((format = psListGetAndIncrement(formatListIter))) {
+                if (strcasecmp(format, "SEPARATE") == 0) {
+                    separateTime = true;
+                } else if (strcasecmp(format, "PRE2000") == 0) {
+                    pre2000Time = true;
+                } else if (strcasecmp(format, "BACKWARDS") == 0) {
+                    backwardsTime = true;
+                    usaTime = false;
+                    mjdTime = false;
+                    jdTime = false;
+                } else if (strcasecmp(format, "USA") == 0) {
+                    usaTime = true;
+                    backwardsTime = false;
+                    jdTime = false;
+                    mjdTime = false;
+                } else if (strcasecmp(format, "JD") == 0) {
+                    jdTime = true;
+                    usaTime = false;
+                    backwardsTime = false;
+                    mjdTime = false;
+                    separateTime = false;
+                } else if (strcasecmp(format, "MJD") == 0) {
+                    mjdTime = true;
+                    usaTime = false;
+                    backwardsTime = false;
+                    jdTime = false;
+                    separateTime = false;
+                } else {
+                    psLogMsg(__func__, PS_LOG_WARN, "Unrecognised FORMATS option for CELL.TIME: %s --- "
+                             "ignored.\n", format);
+                }
+            }
+        }
+    }
+
+    if (separateTime) {
         // We're working with two separate headers --- construct a list with the date and time separately
         psString dateTimeString = psTimeToISO(time); // String representation
@@ -576,10 +654,14 @@
         // Need to format the strings....
         // XXX: Couldn't be bothered doing these right now
-        if (strstr(format, "PRE2000")) {
+        if (pre2000Time) {
             psError(PS_ERR_IO, true, "Don't you realise it's the twenty-first century?\n");
             return NULL;
         }
-        if (strstr(format, "BACKWARDS")) {
+        if (backwardsTime) {
             psError(PS_ERR_IO, true, "You want it BACKWARDS?  Not right now, thanks.\n");
+            return NULL;
+        }
+        if (usaTime) {
+            psError(PS_ERR_IO, true, "USA?  No OK --- yet.\n");
             return NULL;
         }
@@ -601,15 +683,18 @@
         return item;
     }
-    if (strcasecmp(format, "MJD") == 0) {
+    if (jdTime) {
+        double jd = psTimeToMJD(time);
+        return psMetadataItemAllocF64(concept->name, concept->comment, jd);
+    }
+    if (mjdTime) {
         double mjd = psTimeToMJD(time);
         return psMetadataItemAllocF64(concept->name, concept->comment, mjd);
     }
-    if (strcasecmp(format, "JD") == 0) {
-        double jd = psTimeToMJD(time);
-        return psMetadataItemAllocF64("CELL.TIME", "JD of observation", jd);
-    }
-
-    psError(PS_ERR_IO, true, "Not sure how to format concept CELL.TIME\n");
-    return NULL;
+
+    // If we've gotten this far, so it's straight ISO.
+    psString dateTimeString = psTimeToISO(time); // String representation
+    psMetadataItem *item = psMetadataItemAllocStr(concept->name, concept->comment, dateTimeString);
+    psFree(dateTimeString);
+    return item;
 }
 
