diff options
author | A. Wilcox <AWilcox@Wilcox-Tech.com> | 2020-09-29 18:33:23 -0500 |
---|---|---|
committer | A. Wilcox <AWilcox@Wilcox-Tech.com> | 2020-09-29 18:33:23 -0500 |
commit | dbdd9b5a935b802ce51a794d68cf18d52556a793 (patch) | |
tree | 727e67ebefffcdaffb8e18dc2a2221bbf2aa2301 /ncserver | |
parent | 15d8e63671efc5e17dcac52630b7b400d9dd3829 (diff) | |
download | netconfapk-dbdd9b5a935b802ce51a794d68cf18d52556a793.tar.gz netconfapk-dbdd9b5a935b802ce51a794d68cf18d52556a793.tar.bz2 netconfapk-dbdd9b5a935b802ce51a794d68cf18d52556a793.tar.xz netconfapk-dbdd9b5a935b802ce51a794d68cf18d52556a793.zip |
util: Add fn for creating YANG date-and-time string
Diffstat (limited to 'ncserver')
-rw-r--r-- | ncserver/base/util.py | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/ncserver/base/util.py b/ncserver/base/util.py index cbeeed4..5df4704 100644 --- a/ncserver/base/util.py +++ b/ncserver/base/util.py @@ -11,6 +11,7 @@ SPDX-License-Identifier: NCSA """ +from datetime import datetime, timezone from netconf import error @@ -45,6 +46,13 @@ def node_operation(node, def_op='merge') -> str: return node.attrib.get(nc11, node.attrib.get(nc10, def_op)) +def yang_dt_for_timestamp(timestamp) -> str: + """Provide a yang:date-and-time string for a given timestamp.""" + now = datetime.now(timezone.utc) + zone = now.astimezone().tzinfo + return datetime.fromtimestamp(timestamp, tz=zone).isoformat() + + def _index_for_list_op(the_list: list, operation: str, insert_value) -> int: """Determine the index for a leaf-list insertion. |