/usr/lib/python3/dist-packages/tango/time_val.py is in python3-tango 9.2.2-1build1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 | # ------------------------------------------------------------------------------
# This file is part of PyTango (http://pytango.rtfd.io)
#
# Copyright 2006-2012 CELLS / ALBA Synchrotron, Bellaterra, Spain
# Copyright 2013-2014 European Synchrotron Radiation Facility, Grenoble, France
#
# Distributed under the terms of the GNU Lesser General Public License,
# either version 3 of the License, or (at your option) any later version.
# See LICENSE.txt for more info.
# ------------------------------------------------------------------------------
"""
This is an internal PyTango module.
"""
__all__ = ["time_val_init"]
__docformat__ = "restructuredtext"
import time
import datetime
from ._tango import TimeVal
import numbers
def __TimeVal__init(self, a=None, b=None, c=None):
TimeVal.__init_original(self)
if a is None:
return
if isinstance(a, datetime.datetime):
assert (b is None and c is None)
a = time.mktime(a.timetuple()) + a.microsecond * 1E-6
elif isinstance(a, numbers.Number):
if b is None:
self.tv_sec = int(a)
usec = (a - self.tv_sec) * 1E6
self.tv_usec = int(usec)
self.tv_nsec = int((usec - self.tv_usec) * 1E3)
else:
self.tv_sec, self.tv_usec, self.tv_nsec = a, b, c
def __TimeVal__totime(self):
"""
totime(self) -> float
Returns a float representing this time value
Parameters : None
Return : a float representing the time value
.. versionadded:: 7.1.0"""
return self.tv_sec + 1E-6 * self.tv_usec + 1E-9 * self.tv_nsec
def __TimeVal__todatetime(self):
"""
todatetime(self) -> datetime.datetime
Returns a :class:`datetime.datetime` object representing
the same time value
Parameters : None
Return : (datetime.datetime) the time value in datetime format
.. versionadded:: 7.1.0"""
return datetime.datetime.fromtimestamp(self.totime())
def __TimeVal__fromtimestamp(ts):
"""
fromtimestamp(ts) -> TimeVal
A static method returning a :class:`tango.TimeVal` object representing
the given timestamp
Parameters :
- ts : (float) a timestamp
Return : (TimeVal) representing the given timestamp
.. versionadded:: 7.1.0"""
return TimeVal(ts)
def __TimeVal__fromdatetime(dt):
"""
fromdatetime(dt) -> TimeVal
A static method returning a :class:`tango.TimeVal` object representing
the given :class:`datetime.datetime`
Parameters :
- dt : (datetime.datetime) a datetime object
Return : (TimeVal) representing the given timestamp
.. versionadded:: 7.1.0
.. versionadded:: 7.1.2
Documented
"""
return TimeVal(dt)
def __TimeVal__now():
"""
now() -> TimeVal
A static method returning a :class:`tango.TimeVal` object representing
the current time
Parameters : None
Return : (TimeVal) representing the current time
.. versionadded:: 7.1.0
.. versionadded:: 7.1.2
Documented
"""
return TimeVal(time.time())
def __TimeVal__strftime(self, format):
"""
strftime(self, format) -> str
Convert a time value to a string according to a format specification.
Parameters :
format : (str) See the python library reference manual for formatting codes
Return : (str) a string representing the time according to a format specification.
.. versionadded:: 7.1.0
.. versionadded:: 7.1.2
Documented
"""
return self.todatetime().strftime(format)
def __TimeVal__isoformat(self, sep='T'):
"""
isoformat(self, sep='T') -> str
Returns a string in ISO 8601 format, YYYY-MM-DDTHH:MM:SS[.mmmmmm][+HH:MM]
Parameters :
sep : (str) sep is used to separate the year from the time, and defaults to 'T'
Return : (str) a string representing the time according to a format specification.
.. versionadded:: 7.1.0
.. versionadded:: 7.1.2
Documented
.. versionchanged:: 7.1.2
The `sep` parameter is not mandatory anymore and defaults to 'T' (same as :meth:`datetime.datetime.isoformat`)
"""
return self.todatetime().isoformat(sep)
def __TimeVal__str__(self):
"""
__str__(self) -> str
Returns a string representation of TimeVal
Parameters : None
Return : (str) a string representing the time (same as :class:`datetime.datetime`)
.. versionadded:: 7.1.0
.. versionadded:: 7.1.2
Documented
"""
return str(self.todatetime())
def __init_TimeVal():
TimeVal.__init_original = TimeVal.__init__
TimeVal.__init__ = __TimeVal__init
TimeVal.totime = __TimeVal__totime
TimeVal.todatetime = __TimeVal__todatetime
TimeVal.fromtimestamp = staticmethod(__TimeVal__fromtimestamp)
TimeVal.fromdatetime = staticmethod(__TimeVal__fromdatetime)
TimeVal.now = staticmethod(__TimeVal__now)
TimeVal.strftime = __TimeVal__strftime
TimeVal.isoformat = __TimeVal__isoformat
TimeVal.__str__ = __TimeVal__str__
def time_val_init(doc=True):
__init_TimeVal()
|