[GRASS-SVN] r50313 - in grass/trunk: include/defs lib/gis lib/python/temporal raster/r.timestamp raster/r.timestamp/test_suite raster3d/r3.info raster3d/r3.timestamp raster3d/r3.timestamp/test_suite vector/v.timestamp vector/v.timestamp/test_suite

svn_grass at osgeo.org svn_grass at osgeo.org
Fri Jan 20 05:24:53 EST 2012


Author: huhabla
Date: 2012-01-20 02:24:53 -0800 (Fri, 20 Jan 2012)
New Revision: 50313

Added:
   grass/trunk/raster/r.timestamp/test_suite/
   grass/trunk/raster/r.timestamp/test_suite/test.r.timestamp.sh
   grass/trunk/raster3d/r3.timestamp/test_suite/
   grass/trunk/raster3d/r3.timestamp/test_suite/test.r3.timestamp.sh
   grass/trunk/vector/v.timestamp/test_suite/
   grass/trunk/vector/v.timestamp/test_suite/test.v.timestamp.sh
Modified:
   grass/trunk/include/defs/gis.h
   grass/trunk/lib/gis/timestamp.c
   grass/trunk/lib/python/temporal/datetime_math.py
   grass/trunk/raster/r.timestamp/main.c
   grass/trunk/raster3d/r3.info/r3.info.main.c
   grass/trunk/raster3d/r3.timestamp/r3.timestamp.main.c
   grass/trunk/vector/v.timestamp/main.c
Log:
More robust timestamp implementation. Added timestamp tests and renamed grid3 timestamp functions in raster3d.


Modified: grass/trunk/include/defs/gis.h
===================================================================
--- grass/trunk/include/defs/gis.h	2012-01-20 10:02:18 UTC (rev 50312)
+++ grass/trunk/include/defs/gis.h	2012-01-20 10:24:53 UTC (rev 50313)
@@ -614,17 +614,20 @@
 int G__read_timestamp(FILE *, struct TimeStamp *);
 int G__write_timestamp(FILE *, const struct TimeStamp *);
 void G_get_timestamps(const struct TimeStamp *, struct DateTime *, struct DateTime *, int *);
+int G_format_timestamp(const struct TimeStamp *, char *);
+int G_scan_timestamp(struct TimeStamp *, const char *);
+int G_has_raster_timestamp(const char *, const char *);
 int G_read_raster_timestamp(const char *, const char *, struct TimeStamp *);
+int G_write_raster_timestamp(const char *, const struct TimeStamp *);
+int G_remove_raster_timestamp(const char *);
+int G_has_vector_timestamp(const char *, const char *);
 int G_read_vector_timestamp(const char *, const char *, struct TimeStamp *);
-int G_write_raster_timestamp(const char *, const struct TimeStamp *);
 int G_write_vector_timestamp(const char *, const struct TimeStamp *);
-int G_format_timestamp(const struct TimeStamp *, char *);
-int G_scan_timestamp(struct TimeStamp *, const char *);
-int G_remove_raster_timestamp(const char *);
 int G_remove_vector_timestamp(const char *);
-int G_read_grid3_timestamp(const char *, const char *, struct TimeStamp *);
-int G_remove_grid3_timestamp(const char *);
-int G_write_grid3_timestamp(const char *, const struct TimeStamp *);
+int G_has_raster3d_timestamp(const char *, const char *);
+int G_read_raster3d_timestamp(const char *, const char *, struct TimeStamp *);
+int G_remove_raster3d_timestamp(const char *);
+int G_write_raster3d_timestamp(const char *, const struct TimeStamp *);
 
 /* token.c */
 char **G_tokenize(const char *, const char *);

Modified: grass/trunk/lib/gis/timestamp.c
===================================================================
--- grass/trunk/lib/gis/timestamp.c	2012-01-20 10:02:18 UTC (rev 50312)
+++ grass/trunk/lib/gis/timestamp.c	2012-01-20 10:24:53 UTC (rev 50313)
@@ -72,7 +72,8 @@
  * (>=v2). Read the file COPYING that comes with GRASS for details.
  *
  * \author Michael Shapiro & Bill Brown, CERL
- * \author grid3 functions by Michael Pelizzari, LMCO
+ * \author raster3d functions by Michael Pelizzari, LMCO
+ * \author Soeren Gebbert, vector timestamp implementation update
  */
 
 #include <string.h>
@@ -268,7 +269,6 @@
     }
 }
 
-
 /*!
   \brief Write timestamp file
 
@@ -343,6 +343,23 @@
 }
 
 /*!
+  \brief Check if timestamp for raster map exists
+  
+  \param name map name
+  \param mapset mapset name
+
+  \return 1 on success
+  \return 0 no timestamp present
+*/
+int G_has_raster_timestamp(const char *name, const char *mapset)
+{
+    if (!G_find_file2_misc(RAST_MISC, "timestamp", name, mapset))
+	return 0;
+
+    return 1;
+}
+
+/*!
   \brief Read timestamp from raster map
   
   \param name map name
@@ -359,6 +376,22 @@
 }
 
 /*!
+  \brief Write timestamp of raster map
+
+  \param name map name
+  \param[out] ts TimeStamp struct to populate
+  
+  \return 1 on success
+  \return -1 error - can't create timestamp file
+  \return -2 error - invalid datetime in ts
+
+ */
+int G_write_raster_timestamp(const char *name, const struct TimeStamp *ts)
+{
+    return write_timestamp("raster", RAST_MISC, name, ts);
+}
+
+/*!
   \brief Remove timestamp from raster map
   
   Only timestamp files in current mapset can be removed.
@@ -375,6 +408,29 @@
 }
 
 /*!
+  \brief Check if timestamp for vector map exists
+  
+  \param name map name
+  \param mapset mapset name
+
+  \return 1 on success
+  \return 0 no timestamp present
+*/
+int G_has_vector_timestamp(const char *name, const char *mapset)
+{
+    char dir[GPATH_MAX];
+    char path[GPATH_MAX + GNAME_MAX];
+
+    G_snprintf(dir, GPATH_MAX, "%s/%s", GV_DIRECTORY, name);
+    G_file_name(path, dir, GV_TIMESTAMP_ELEMENT, mapset);
+
+    if (access(path, R_OK) != 0)
+	return 0;
+
+    return 1;
+}
+
+/*!
   \brief Read timestamp from vector map
   
   \param name map name
@@ -392,17 +448,12 @@
     FILE *fd;
     int stat;
     char dir[GPATH_MAX];
-    char path[GPATH_MAX + GNAME_MAX];
 
-    G_snprintf(dir, GPATH_MAX, "%s/%s", GV_DIRECTORY, name);
-    G_file_name(path, dir, GV_TIMESTAMP_ELEMENT, mapset);
-
-    G_debug(1, "Reading vector timestamp file: %s", path);
-
     /* In case no timestamp file is present return 0 */
-    if (access(path, R_OK) != 0)
+    if (G_has_vector_timestamp(name, mapset) != 1)
 	return 0;
 
+    G_snprintf(dir, GPATH_MAX, "%s/%s", GV_DIRECTORY, name);
     fd = G_fopen_old(dir, GV_TIMESTAMP_ELEMENT, mapset);
     
     if (fd == NULL) {
@@ -421,6 +472,42 @@
 }
 
 /*!
+  \brief Write timestamp of vector map
+
+  \param name map name
+  \param[out] ts TimeStamp struct to populate
+  
+  \return 1 on success
+  \return -1 error - can't create timestamp file
+  \return -2 error - invalid datetime in ts
+
+ */
+int G_write_vector_timestamp(const char *name, const struct TimeStamp *ts)
+{
+    FILE *fd;
+    int stat;
+    char dir[GPATH_MAX];
+
+    G_snprintf(dir, GPATH_MAX, "%s/%s", GV_DIRECTORY, name);
+
+    fd = G_fopen_new(dir, GV_TIMESTAMP_ELEMENT);
+    
+    if (fd == NULL) {
+	G_warning(_("Unable to create timestamp file for vector map <%s@%s>"),
+		  name, G_mapset());
+	return -1;
+    }
+
+    stat = G__write_timestamp(fd, ts);
+    fclose(fd);
+    if (stat == 0)
+	return 1;
+    G_warning(_("Invalid timestamp specified for vector map <%s@%s>"),
+	      name, G_mapset());
+    return -2;
+}
+
+/*!
   \brief Remove timestamp from vector map
   
   Only timestamp files in current mapset can be removed.
@@ -440,39 +527,40 @@
 }
 
 /*!
-  \brief Read timestamp from 3D raster map
+  \brief Check if timestamp for 3D raster map exists
   
   \param name map name
   \param mapset mapset name
-  \param[out] ts TimeStamp struct to populate
 
   \return 1 on success
-  \return 0 or negative on error
+  \return 0 no timestamp present
 */
-int G_read_grid3_timestamp(const char *name, const char *mapset,
-			   struct TimeStamp *ts)
+int G_has_raster3d_timestamp(const char *name, const char *mapset)
 {
-    return read_timestamp("grid3", GRID3, name, mapset, ts);
+    if (!G_find_file2_misc(GRID3, "timestamp", name, mapset))
+	return 0;
+
+    return 1;
 }
 
 /*!
-  \brief Remove timestamp from 3D raster map
+  \brief Read timestamp from 3D raster map
   
-  Only timestamp files in current mapset can be removed.
-
   \param name map name
+  \param mapset mapset name
+  \param[out] ts TimeStamp struct to populate
 
-  \return 0 if no file
   \return 1 on success
-  \return -1 on failure
+  \return 0 or negative on error
 */
-int G_remove_grid3_timestamp(const char *name)
+int G_read_raster3d_timestamp(const char *name, const char *mapset,
+			   struct TimeStamp *ts)
 {
-    return G_remove_misc(GRID3, "timestamp", name);
+    return read_timestamp("raster3d", GRID3, name, mapset, ts);
 }
 
 /*!
-  \brief Write timestamp of raster map
+  \brief Write timestamp of 3D raster map
 
   \param name map name
   \param[out] ts TimeStamp struct to populate
@@ -482,59 +570,24 @@
   \return -2 error - invalid datetime in ts
 
  */
-int G_write_raster_timestamp(const char *name, const struct TimeStamp *ts)
+int G_write_raster3d_timestamp(const char *name, const struct TimeStamp *ts)
 {
-    return write_timestamp("raster", RAST_MISC, name, ts);
+    return write_timestamp("raster3d", GRID3, name, ts);
 }
 
 /*!
-  \brief Write timestamp of vector map
+  \brief Remove timestamp from 3D raster map
+  
+  Only timestamp files in current mapset can be removed.
 
   \param name map name
-  \param[out] ts TimeStamp struct to populate
-  
+
+  \return 0 if no file
   \return 1 on success
-  \return -1 error - can't create timestamp file
-  \return -2 error - invalid datetime in ts
-
- */
-int G_write_vector_timestamp(const char *name, const struct TimeStamp *ts)
+  \return -1 on failure
+*/
+int G_remove_raster3d_timestamp(const char *name)
 {
-    FILE *fd;
-    int stat;
-    char dir[GPATH_MAX];
-
-    G_snprintf(dir, GPATH_MAX, "%s/%s", GV_DIRECTORY, name);
-
-    fd = G_fopen_new(dir, GV_TIMESTAMP_ELEMENT);
-    
-    if (fd == NULL) {
-	G_warning(_("Unable to create timestamp file for vector map <%s@%s>"),
-		  name, G_mapset());
-	return -1;
-    }
-
-    stat = G__write_timestamp(fd, ts);
-    fclose(fd);
-    if (stat == 0)
-	return 1;
-    G_warning(_("Invalid timestamp specified for vector map <%s@%s>"),
-	      name, G_mapset());
-    return -2;
+    return G_remove_misc(GRID3, "timestamp", name);
 }
 
-/*!
-  \brief Write timestamp of 3D raster map
-
-  \param name map name
-  \param[out] ts TimeStamp struct to populate
-  
-  \return 1 on success
-  \return -1 error - can't create timestamp file
-  \return -2 error - invalid datetime in ts
-
- */
-int G_write_grid3_timestamp(const char *name, const struct TimeStamp *ts)
-{
-    return write_timestamp("grid3", GRID3, name, ts);
-}

Modified: grass/trunk/lib/python/temporal/datetime_math.py
===================================================================
--- grass/trunk/lib/python/temporal/datetime_math.py	2012-01-20 10:02:18 UTC (rev 50312)
+++ grass/trunk/lib/python/temporal/datetime_math.py	2012-01-20 10:24:53 UTC (rev 50313)
@@ -33,7 +33,6 @@
        into a timedelta object.
     """
 
-
     days = int(value)
     seconds = value % 1
     seconds = round(seconds * 86400)

Modified: grass/trunk/raster/r.timestamp/main.c
===================================================================
--- grass/trunk/raster/r.timestamp/main.c	2012-01-20 10:02:18 UTC (rev 50312)
+++ grass/trunk/raster/r.timestamp/main.c	2012-01-20 10:24:53 UTC (rev 50313)
@@ -26,6 +26,7 @@
     struct Option *map, *date;
     struct TimeStamp ts;
     char *name;
+    const char *mapset;
     int modify;
 
     G_gisinit(argv[0]);
@@ -54,6 +55,17 @@
 
     modify = date->answer != NULL;
 
+    if (modify)
+	mapset = G_find_raster(name, G_mapset());
+    else
+	mapset = G_find_raster(name, "");
+
+    if (mapset == NULL) {
+	G_fatal_error(_("Raster map <%s> not found %s"), name,
+		      modify ? "in current mapset" : "");
+	exit(EXIT_FAILURE);
+    }
+
     if (!modify) {
 	if (G_read_raster_timestamp(name, "", &ts) == 1) {
 	    G__write_timestamp(stdout, &ts);
@@ -67,12 +79,10 @@
 	exit(EXIT_SUCCESS);
     }
 
-    if (1 == G_scan_timestamp(&ts, date->answer)) {
-	G_write_raster_timestamp(name, &ts);
-	exit(EXIT_SUCCESS);
-    }
-    else
-	G_fatal_error(_("Invalid timestamp"));
+    if(G_scan_timestamp(&ts, date->answer) != 1)
+        G_fatal_error("Timestamp format is invalid");
 
+    G_write_raster_timestamp(name, &ts);
+
     exit(EXIT_SUCCESS);
 }

Added: grass/trunk/raster/r.timestamp/test_suite/test.r.timestamp.sh
===================================================================
--- grass/trunk/raster/r.timestamp/test_suite/test.r.timestamp.sh	                        (rev 0)
+++ grass/trunk/raster/r.timestamp/test_suite/test.r.timestamp.sh	2012-01-20 10:24:53 UTC (rev 50313)
@@ -0,0 +1,56 @@
+# This is a simple timestamp check, creation and removal test
+
+# We need to set a specific region in the
+# @preprocess step of this test. We generate
+# raster data with r.mapcalc.
+# The region setting should work for UTM and LL test locations
+g.region s=0 n=80 w=0 e=120 b=0 t=50 res=10 res3=10 -p3
+
+# Lets gerenate a test map
+r.mapcalc --o expr="map = 1"
+
+# The first @test uses several different absolute datum formats
+r.timestamp map=map date=none
+r.timestamp map=map 
+r.timestamp map=map date="2003"
+r.timestamp map=map 
+r.timestamp map=map date="Jul 2003"
+r.timestamp map=map 
+r.timestamp map=map date="14 Jul 2003"
+r.timestamp map=map 
+r.timestamp map=map date="14 Jul 2003 10"
+r.timestamp map=map 
+r.timestamp map=map date="14 Jul 2003 10:30 +0700"
+r.timestamp map=map 
+r.timestamp map=map date="14 Jul 2003 10:30:25"
+r.timestamp map=map 
+r.timestamp map=map date="14 Jul 2003 10:30:25 +0700 / 15 Jul 2003 11:35:12 +0700"
+r.timestamp map=map 
+r.timestamp map=map date="14 Jul 2003 10:30:25 +0700 / 15 Jul 2003"
+r.timestamp map=map 
+r.timestamp map=map date=none
+r.timestamp map=map 
+
+# The second @test uses several different relative datum formats
+r.timestamp map=map date=none
+r.timestamp map=map 
+r.timestamp map=map date="2 years"
+r.timestamp map=map 
+r.timestamp map=map date="2 years 3 months"
+r.timestamp map=map 
+r.timestamp map=map date="5 days"
+r.timestamp map=map 
+r.timestamp map=map date="3 hours"
+r.timestamp map=map 
+r.timestamp map=map date="5 minutes 30 seconds"
+r.timestamp map=map 
+r.timestamp map=map date="2 years 2 months / 5 years 8 months"
+r.timestamp map=map 
+r.timestamp map=map date=none
+
+# The third @test to check @failure with wrong time stamps
+r.timestamp map=map date="2 years 3 months 8 days"
+r.timestamp map=map date="1 month 5 days"
+r.timestamp map=map date="July 2003"
+r.timestamp map=map date="14 Jul 2003 +0700"
+

Modified: grass/trunk/raster3d/r3.info/r3.info.main.c
===================================================================
--- grass/trunk/raster3d/r3.info/r3.info.main.c	2012-01-20 10:02:18 UTC (rev 50312)
+++ grass/trunk/raster3d/r3.info/r3.info.main.c	2012-01-20 10:24:53 UTC (rev 50313)
@@ -45,7 +45,7 @@
 /**************************************************************************/
 int main(int argc, char *argv[])
 {
-    char *mapset;
+    const char *mapset;
     char *line = NULL;
     char tmp1[TMP_LENGTH], tmp2[TMP_LENGTH], tmp3[TMP_LENGTH];
     char timebuff[256];
@@ -140,7 +140,7 @@
     hist_ok = Rast3d_read_history(name, mapset, &hist) >= 0;
     cats_ok = Rast3d_read_cats(name, mapset, &cats) >= 0;
     /*Check the Timestamp */
-    time_ok = G_read_grid3_timestamp(name, mapset, &ts) > 0;
+    time_ok = G_read_raster3d_timestamp(name, mapset, &ts) > 0;
 
     /*Check for valid entries, show none if no entire available! */
     if (time_ok) {

Modified: grass/trunk/raster3d/r3.timestamp/r3.timestamp.main.c
===================================================================
--- grass/trunk/raster3d/r3.timestamp/r3.timestamp.main.c	2012-01-20 10:02:18 UTC (rev 50312)
+++ grass/trunk/raster3d/r3.timestamp/r3.timestamp.main.c	2012-01-20 10:24:53 UTC (rev 50313)
@@ -5,7 +5,7 @@
  * AUTHOR(S):    Michael Pelizzari <michael.pelizzari lmco.com> 
  *                     (original contributor)
  *               Glynn Clements <glynn gclements.plus.com> Markus Neteler <neteler itc.it>
- * PURPOSE:      Stamps grid3 files with date and time.  
+ * PURPOSE:      Stamps raster3d files with date and time.  
  * COPYRIGHT:    (C) 2001-2006 by the GRASS Development Team
  *
  *               This program is free software under the GNU General Public
@@ -16,7 +16,7 @@
 
 /* based on r.timestamp by Michael Shapiro and v.timestamp by Markus Neteler:
  * 
- * Stamps grid3 files with date and time.  This main.c is linked to functions 
+ * Stamps raster3d files with date and time.  This main.c is linked to functions 
  * currently residing in lib/gis/timestamp.c
  *
  */
@@ -33,7 +33,7 @@
     struct Option *map, *date;
     struct TimeStamp ts;
     char *name;
-    char *mapset;
+    const char *mapset;
     int modify;
     struct GModule *module;
 
@@ -45,12 +45,7 @@
     module->description =
 	_("Print/add/remove a timestamp for a 3D raster map");
 
-    map = G_define_option();
-    map->key = "map";
-    map->required = YES;
-    map->type = TYPE_STRING;
-    map->gisprompt = "old,grid3,3d raster";
-    map->description = _("Input grid3 filename");
+    map = G_define_standard_option(G_OPT_R3_MAP);
 
     date = G_define_option();
     date->key = "date";
@@ -72,13 +67,13 @@
 	mapset = G_find_raster3d(name, "");
 
     if (mapset == NULL) {
-	G_fatal_error(_("Grid3 <%s> not found %s"), name,
+	G_fatal_error(_("Raster3d map <%s> not found %s"), name,
 		      modify ? "in current mapset" : "");
 	exit(EXIT_FAILURE);
     }
 
     if (!modify) {
-	if (G_read_grid3_timestamp(name, mapset, &ts) == 1) {
+	if (G_read_raster3d_timestamp(name, mapset, &ts) == 1) {
 	    G__write_timestamp(stdout, &ts);
 	    exit(EXIT_SUCCESS);
 	}
@@ -86,11 +81,13 @@
 	    exit(EXIT_FAILURE);
     }
     if (strcmp(date->answer, "none") == 0) {
-	G_remove_grid3_timestamp(name);
+	G_remove_raster3d_timestamp(name);
 	exit(EXIT_SUCCESS);
     }
 
-    G_scan_timestamp(&ts, date->answer);
-    G_write_grid3_timestamp(name, &ts);
+    if(G_scan_timestamp(&ts, date->answer) != 1)
+        G_fatal_error("Timestamp format is invalid");
+
+    G_write_raster3d_timestamp(name, &ts);
     exit(EXIT_SUCCESS);
 }

Added: grass/trunk/raster3d/r3.timestamp/test_suite/test.r3.timestamp.sh
===================================================================
--- grass/trunk/raster3d/r3.timestamp/test_suite/test.r3.timestamp.sh	                        (rev 0)
+++ grass/trunk/raster3d/r3.timestamp/test_suite/test.r3.timestamp.sh	2012-01-20 10:24:53 UTC (rev 50313)
@@ -0,0 +1,56 @@
+# This is a simple timestamp check, creation and removal test
+
+# We need to set a specific region in the
+# @preprocess step of this test. We generate
+# voxel data with r3.mapcalc.
+# The region setting should work for UTM and LL test locations
+g.region s=0 n=80 w=0 e=120 b=0 t=50 res=10 res3=10 -p3
+
+# Lets gerenate a test map
+r3.mapcalc --o expr="map3d = 1"
+
+# The first @test uses several different absolute datum formats
+r3.timestamp map=map3d date=none
+r3.timestamp map=map3d 
+r3.timestamp map=map3d date="2003"
+r3.timestamp map=map3d 
+r3.timestamp map=map3d date="Jul 2003"
+r3.timestamp map=map3d 
+r3.timestamp map=map3d date="14 Jul 2003"
+r3.timestamp map=map3d 
+r3.timestamp map=map3d date="14 Jul 2003 10"
+r3.timestamp map=map3d 
+r3.timestamp map=map3d date="14 Jul 2003 10:30 +0700"
+r3.timestamp map=map3d 
+r3.timestamp map=map3d date="14 Jul 2003 10:30:25"
+r3.timestamp map=map3d 
+r3.timestamp map=map3d date="14 Jul 2003 10:30:25 +0700 / 15 Jul 2003 11:35:12 +0700"
+r3.timestamp map=map3d 
+r3.timestamp map=map3d date="14 Jul 2003 10:30:25 +0700 / 15 Jul 2003"
+r3.timestamp map=map3d 
+r3.timestamp map=map3d date=none
+r3.timestamp map=map3d 
+
+# The second @test uses several different relative datum formats
+r3.timestamp map=map3d date=none
+r3.timestamp map=map3d 
+r3.timestamp map=map3d date="2 years"
+r3.timestamp map=map3d 
+r3.timestamp map=map3d date="2 years 3 months"
+r3.timestamp map=map3d 
+r3.timestamp map=map3d date="5 days"
+r3.timestamp map=map3d 
+r3.timestamp map=map3d date="3 hours"
+r3.timestamp map=map3d 
+r3.timestamp map=map3d date="5 minutes 30 seconds"
+r3.timestamp map=map3d 
+r3.timestamp map=map3d date="2 years 2 months / 5 years 8 months"
+r3.timestamp map=map3d 
+r3.timestamp map=map3d date=none
+
+# The third @test to check @failure with wrong time stamps
+r3.timestamp map=map3d date="2 years 3 months 8 days"
+r3.timestamp map=map3d date="1 month 5 days"
+r3.timestamp map=map3d date="July 2003"
+r3.timestamp map=map3d date="14 Jul 2003 +0700"
+

Modified: grass/trunk/vector/v.timestamp/main.c
===================================================================
--- grass/trunk/vector/v.timestamp/main.c	2012-01-20 10:02:18 UTC (rev 50312)
+++ grass/trunk/vector/v.timestamp/main.c	2012-01-20 10:24:53 UTC (rev 50313)
@@ -27,6 +27,7 @@
     struct Option *map, *date;
     struct TimeStamp ts;
     char *name;
+    const char *mapset;
     int modify;
 
     G_gisinit(argv[0]);
@@ -55,6 +56,17 @@
 
     modify = date->answer != NULL;
 
+    if (modify)
+	mapset = G_find_vector(name, G_mapset());
+    else
+	mapset = G_find_vector(name, "");
+
+    if (mapset == NULL) {
+	G_fatal_error(_("Vector map <%s> not found %s"), name,
+		      modify ? "in current mapset" : "");
+	exit(EXIT_FAILURE);
+    }
+
     if (!modify) {
 	if (G_read_vector_timestamp(name, "", &ts) == 1) {
 	    G__write_timestamp(stdout, &ts);
@@ -68,12 +80,10 @@
 	exit(EXIT_SUCCESS);
     }
 
-    if (1 == G_scan_timestamp(&ts, date->answer)) {
-	G_write_vector_timestamp(name, &ts);
-	exit(EXIT_SUCCESS);
-    }
-    else
-	G_fatal_error(_("Invalid timestamp"));
+    if(G_scan_timestamp(&ts, date->answer) != 1)
+        G_fatal_error("Timestamp format is invalid");
 
+    G_write_vector_timestamp(name, &ts);
+
     exit(EXIT_SUCCESS);
 }

Added: grass/trunk/vector/v.timestamp/test_suite/test.v.timestamp.sh
===================================================================
--- grass/trunk/vector/v.timestamp/test_suite/test.v.timestamp.sh	                        (rev 0)
+++ grass/trunk/vector/v.timestamp/test_suite/test.v.timestamp.sh	2012-01-20 10:24:53 UTC (rev 50313)
@@ -0,0 +1,56 @@
+# This is a simple timestamp check, creation and removal test
+
+# We need to set a specific region in the
+# @preprocess step of this test. We generate
+# raster data with r.mapcalc.
+# The region setting should work for UTM and LL test locations
+g.region s=0 n=80 w=0 e=120 b=0 t=50 res=10 res3=10 -p3
+
+# Lets gerenate a test map
+v.random --o seed=1 n=20 output=map
+
+# The first @test uses several different absolute datum formats
+v.timestamp map=map date=none
+v.timestamp map=map 
+v.timestamp map=map date="2003"
+v.timestamp map=map 
+v.timestamp map=map date="Jul 2003"
+v.timestamp map=map 
+v.timestamp map=map date="14 Jul 2003"
+v.timestamp map=map 
+v.timestamp map=map date="14 Jul 2003 10"
+v.timestamp map=map 
+v.timestamp map=map date="14 Jul 2003 10:30 +0700"
+v.timestamp map=map 
+v.timestamp map=map date="14 Jul 2003 10:30:25"
+v.timestamp map=map 
+v.timestamp map=map date="14 Jul 2003 10:30:25 +0700 / 15 Jul 2003 11:35:12 +0700"
+v.timestamp map=map 
+v.timestamp map=map date="14 Jul 2003 10:30:25 +0700 / 15 Jul 2003"
+v.timestamp map=map 
+v.timestamp map=map date=none
+v.timestamp map=map 
+
+# The second @test uses several different relative datum formats
+v.timestamp map=map date=none
+v.timestamp map=map 
+v.timestamp map=map date="2 years"
+v.timestamp map=map 
+v.timestamp map=map date="2 years 3 months"
+v.timestamp map=map 
+v.timestamp map=map date="5 days"
+v.timestamp map=map 
+v.timestamp map=map date="3 hours"
+v.timestamp map=map 
+v.timestamp map=map date="5 minutes 30 seconds"
+v.timestamp map=map 
+v.timestamp map=map date="2 years 2 months / 5 years 8 months"
+v.timestamp map=map 
+v.timestamp map=map date=none
+
+# The third @test to check @failure with wrong time stamps
+v.timestamp map=map date="2 years 3 months 8 days"
+v.timestamp map=map date="1 month 5 days"
+v.timestamp map=map date="July 2003"
+v.timestamp map=map date="14 Jul 2003 +0700"
+



More information about the grass-commit mailing list