[GRASS-SVN] r67935 - grass/trunk/lib/python/temporal

svn_grass at osgeo.org svn_grass at osgeo.org
Wed Feb 24 04:59:01 PST 2016


Author: lucadelu
Date: 2016-02-24 04:59:01 -0800 (Wed, 24 Feb 2016)
New Revision: 67935

Modified:
   grass/trunk/lib/python/temporal/datetime_math.py
Log:
temporal library: added functions to create time and numeric suffix

Modified: grass/trunk/lib/python/temporal/datetime_math.py
===================================================================
--- grass/trunk/lib/python/temporal/datetime_math.py	2016-02-24 09:35:56 UTC (rev 67934)
+++ grass/trunk/lib/python/temporal/datetime_math.py	2016-02-24 12:59:01 UTC (rev 67935)
@@ -861,6 +861,42 @@
     global suffix_units
     return start_time.strftime(suffix_units[granularity.split(' ')[1]])
 
+def create_time_suffix(mapp, end=False):
+    """Create a datetime string based on a map datetime object
+    
+       :param mapp: a temporal map dataset
+       :param end: True if you want add also end time to the suffix    
+    """
+    start = mapp.temporal_extent.get_start_time()
+    sstring = start.isoformat().replace(':', '.').replace('-', '_')
+    if end:
+        end = mapp.temporal_extent.get_end_time()
+        estring = end.isoformat().replace(':', '.').replace('-', '_')
+        return "{st}_{en}".format(st=sstring, en=estring)
+    return sstring
+
+def create_numeric_suffic(base, count, zeros):
+    """Create a string based on count and number of zeros decided by zeros
+
+       :param base: the basename for new map
+       :param count: a number
+       :param zeros: a string containing the expected number, coming from suffix option
+    """
+    spli = zeros.split('%')
+    if len(spli) == 2:
+        suff = spli[1]
+        if suff.isdigit():
+            if int(suff[0]) == 0:
+                zero = suff
+            else:
+                zero = "0{nu}".format(nu=suff)
+        else:
+            zero = '05'
+    else:
+        zero = '05'
+    s = '{ba}_{i:' + zero + 'd}'
+    return s.format(ba=base, i=count)
+
 if __name__ == "__main__":
     import doctest
     doctest.testmod()



More information about the grass-commit mailing list