# HG changeset patch # User Thierry Florac # Date 1601299168 -7200 # Node ID b3b41d340a0481234ac8e8d94b93be52f249c79f # Parent 3403121fc6d671b9234d651941874ef008111bd2 Added "date.get_timestamp()" function diff -r 3403121fc6d6 -r b3b41d340a04 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)