Debian Codegraph @

strictyaml/ruamel/timestamp.py

raw
1 # coding: utf-8
2
3 from __future__ import print_function, absolute_import, division, unicode_literals
4
5 import datetime
6 import copy
7
8 # ToDo: at least on PY3 you could probably attach the tzinfo correctly to the object
9 # a more complete datetime might be used by safe loading as well
10
11 if False: # MYPY
12 from typing import Any, Dict, Optional, List # NOQA
13
14
15 class TimeStamp(datetime.datetime):
16 def __init__(self, *args, **kw):
17 # type: (Any, Any) -> None
18 self._yaml = dict(t=False, tz=None, delta=0) # type: Dict[Any, Any]
19
20 def __new__(cls, *args, **kw): # datetime is immutable
21 # type: (Any, Any) -> Any
22 return datetime.datetime.__new__(cls, *args, **kw) # type: ignore
23
24 def __deepcopy__(self, memo):
25 # type: (Any) -> Any
26 ts = TimeStamp(
27 self.year, self.month, self.day, self.hour, self.minute, self.second
28 )
29 ts._yaml = copy.deepcopy(self._yaml)
30 return ts
31
32 def replace(
33 self,
34 year=None,
35 month=None,
36 day=None,
37 hour=None,
38 minute=None,
39 second=None,
40 microsecond=None,
41 tzinfo=True,
42 fold=None,
43 ):
44 if year is None:
45 year = self.year
46 if month is None:
47 month = self.month
48 if day is None:
49 day = self.day
50 if hour is None:
51 hour = self.hour
52 if minute is None:
53 minute = self.minute
54 if second is None:
55 second = self.second
56 if microsecond is None:
57 microsecond = self.microsecond
58 if tzinfo is True:
59 tzinfo = self.tzinfo
60 if fold is None:
61 fold = self.fold
62 ts = type(self)(
63 year, month, day, hour, minute, second, microsecond, tzinfo, fold=fold
64 )
65 ts._yaml = copy.deepcopy(self._yaml)
66 return ts