summaryrefslogtreecommitdiffstats
path: root/timestamp.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-04 00:30:09 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-04 00:30:09 +0000
commit4dd6e896edac1096089a9cd54296266436ffec03 (patch)
treea3da8663c704704177ad944ae5a680c302f29f55 /timestamp.py
parentInitial commit. (diff)
downloadruamel.yaml-4dd6e896edac1096089a9cd54296266436ffec03.tar.xz
ruamel.yaml-4dd6e896edac1096089a9cd54296266436ffec03.zip
Adding upstream version 0.18.5.upstream/0.18.5
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'timestamp.py')
-rw-r--r--timestamp.py58
1 files changed, 58 insertions, 0 deletions
diff --git a/timestamp.py b/timestamp.py
new file mode 100644
index 0000000..753dfc1
--- /dev/null
+++ b/timestamp.py
@@ -0,0 +1,58 @@
+# coding: utf-8
+
+import datetime
+import copy
+
+# ToDo: at least on PY3 you could probably attach the tzinfo correctly to the object
+# a more complete datetime might be used by safe loading as well
+#
+# add type information (iso8601, spaced)
+
+from typing import Any, Dict, Optional, List # NOQA
+
+
+class TimeStamp(datetime.datetime):
+ def __init__(self, *args: Any, **kw: Any) -> None:
+ self._yaml: Dict[Any, Any] = dict(t=False, tz=None, delta=0)
+
+ def __new__(cls, *args: Any, **kw: Any) -> Any: # datetime is immutable
+ return datetime.datetime.__new__(cls, *args, **kw)
+
+ def __deepcopy__(self, memo: Any) -> Any:
+ ts = TimeStamp(self.year, self.month, self.day, self.hour, self.minute, self.second)
+ ts._yaml = copy.deepcopy(self._yaml)
+ return ts
+
+ def replace(
+ self,
+ year: Any = None,
+ month: Any = None,
+ day: Any = None,
+ hour: Any = None,
+ minute: Any = None,
+ second: Any = None,
+ microsecond: Any = None,
+ tzinfo: Any = True,
+ fold: Any = None,
+ ) -> Any:
+ if year is None:
+ year = self.year
+ if month is None:
+ month = self.month
+ if day is None:
+ day = self.day
+ if hour is None:
+ hour = self.hour
+ if minute is None:
+ minute = self.minute
+ if second is None:
+ second = self.second
+ if microsecond is None:
+ microsecond = self.microsecond
+ if tzinfo is True:
+ tzinfo = self.tzinfo
+ if fold is None:
+ fold = self.fold
+ ts = type(self)(year, month, day, hour, minute, second, microsecond, tzinfo, fold=fold)
+ ts._yaml = copy.deepcopy(self._yaml)
+ return ts