Added "date.get_timestamp()" function
authorThierry Florac <tflorac@ulthar.net>
Mon, 28 Sep 2020 15:19:28 +0200
changeset 441 b3b41d340a04
parent 440 3403121fc6d6
child 442 63e3acc6e4d6
Added "date.get_timestamp()" function
src/pyams_utils/date.py
--- a/src/pyams_utils/date.py	Mon Jun 29 22:32:45 2020 +0200
+++ b/src/pyams_utils/date.py	Mon Sep 28 15:19:28 2020 +0200
@@ -257,6 +257,18 @@
     return result
 
 
+def get_timestamp(context, formatting=None):
+    """Get timestamp matching context modification time"""
+    if formatting == 'iso':
+        format_func = datetime.isoformat
+    else:
+        format_func = datetime.timestamp
+    zdc = IZopeDublinCore(context, None)
+    if zdc is not None:
+        return format_func(tztime(zdc.modified))
+    return format_func(tztime(datetime.utcnow()))
+
+
 @adapter_config(name='timestamp', context=(Interface, Interface, Interface),
                 provides=ITALESExtension)
 class TimestampTalesAdapter(ContextRequestViewAdapter):
@@ -269,11 +281,4 @@
         """Render TALES extension"""
         if context is None:
             context = self.request.context
-        if formatting == 'iso':
-            format_func = datetime.isoformat
-        else:
-            format_func = datetime.timestamp
-        zdc = IZopeDublinCore(context, None)
-        if zdc is None:
-            return format_func(tztime(zdc.modified))
-        return format_func(tztime(datetime.utcnow()))
+        return get_timestamp(context, formatting)