visiannot.tools.datetime_converter¶
Summary¶
Module with functions for date-time management
Data¶
(str) Default time string format |
Functions¶
API¶
Functions¶
-
visiannot.tools.datetime_converter.convert_absolute_datetime_string_to_frame(fps, beginning_datetime, *args, **kwargs)[source]¶ Converts absolute date-time string to frame number
The input beginning datetime is substracted to the absolute datetime to convert, so that the converted frame number is relative to the input beginning datetime.
- Parameters
fps (int or float) – frequency related to the converted frame number
beginning_datetime (datetime.datetime) – beginning datetime which is the reference for the converted frame number
args – positional arguments of
convert_string_to_datetime()kwargs – keyword argument of
convert_string_to_datetime()
- Returns
frame number
- Return type
int
-
visiannot.tools.datetime_converter.convert_absolute_datetime_to_frame(date_time, fps, beginning_datetime)[source]¶ Converts absolute datetime to frame number
The input beginning datetime is substracted to the absolute datetime to convert, so that the converted frame number is relative to the input beginning datetime.
- Parameters
content (instace of datetime.datetime) – absolute datetime
fps (int or float) – frequency related to the converted frame number
beginning_datetime (datetime.datetime) – beginning datetime which is the reference for the converted frame number
- Returns
frame number
- Return type
int
-
visiannot.tools.datetime_converter.convert_datetime_to_string(date_time, fmt='%H:%M:%S')[source]¶ Converts a datetime to a string
- Parameters
date_time (datetime.datetime or datetime.time) –
fmt (str) – output string format, might be
posixor any format supported by datetime (see https://docs.python.org/3/library/datetime.html#strftime-and-strptime-format-codes), it is also possible to use the code%sfor milliseconds (in this case, it must be the last code of the format)
- Returns
formatted datetime string
- Return type
str
-
visiannot.tools.datetime_converter.convert_frame_to_absolute_datetime(frame_nb, fps, beginning_datetime)[source]¶ Converts frame number to absolute datetime
The input beginning datetime is added to the frame number, so that the converted datetime is absolute.
- Parameters
frame_nb (int) – frame number to convert
fps (int or float) – frequency related to the frame number
beginning_datetime (datetime.datetime) – reference datetime to get absolute datetime
- Returns
absolute datetime
- Return type
datetime.datetime
-
visiannot.tools.datetime_converter.convert_frame_to_absolute_datetime_string(frame_nb, fps, beginning_datetime, **kwargs)[source]¶ Converts frame number to absolute datetime string
The input beginning datetime is added to the frame number, so that the converted datetimetime string is absolute.
- Parameters
frame_nb (int) – frame number to convert
fps (int or float) – frequency related to the frame number
beginning_datetime (datetime.datetime) – reference datetime to get absolute datetime
kwargs – keyword arguments
convert_datetime_to_string()
- Returns
absolute datetime
- Return type
str
-
visiannot.tools.datetime_converter.convert_frame_to_string(frame_nb, fps, **kwargs)[source]¶ Converts frame number to time string
- Parameters
frame_nb (int) – frame number to convert
fps (int or float) – frequency related to the frame number
kwargs – keyword arguments of
convert_time_to_string()(msecis ignored)
- Returns
time string
- Return type
str
-
visiannot.tools.datetime_converter.convert_frame_to_time(frame_nb, fps)[source]¶ Converts frame number to time as hour/minute/second/microsecond
- Parameters
frame_nb (int) – frame number
fps (int or float) – frequency related to the frame number
- Returns
see output of
convert_seconds_to_time()
-
visiannot.tools.datetime_converter.convert_seconds_to_time(time_sec)[source]¶ Converts time in seconds to time as hour/minute/second/microsecond
- Parameters
time (int or float) – time in seconds
- Returns
hour (int)
minute (int)
second (int)
microsecond (int)
-
visiannot.tools.datetime_converter.convert_string_to_datetime(datetime_str, fmt, time_zone=None)[source]¶ Converts datetime string to datetime
- Parameters
content (str) – date-time string
fmt (str) – date-time string format, might be
posixor any format supported by datetime (see https://docs.python.org/3/library/datetime.html#strftime-and-strptime-format-codes), it is also possible to use the code%sfor milliseconds (in this case, it must be the last code of the format)time_zone (str) – timezone compliant with package pytz
- Returns
datetime
- Return type
datetime.datetime
-
visiannot.tools.datetime_converter.convert_time_to_frame(fps, hour=0, minute=0, sec=0, msec=0)[source]¶ Converts time as hour/minute/second/microsecond to frame number
- Parameters
fps (int or float) – frequency related to the converted frame number
hour (int) –
minute (int) –
sec (int) –
msec (int) – microsecond
- Returns
frame number
- Return type
int
-
visiannot.tools.datetime_converter.convert_time_to_string(hour, minute, sec, msec=0, **kwargs)[source]¶ Converts time as hour/minute/second/microsecond to time string
- Parameters
hour (int) –
minute (int) –
sec (int) –
msec (int) – microsecond
kwargs – keyword arguments of
convert_datetime_to_string()
- Returns
time string
- Return type
str
-
visiannot.tools.datetime_converter.convert_timedelta_to_absolute_datetime_string(beginning_datetime, delta_dict, **kwargs)[source]¶ Converts a time delta to absolute datetime string
The time delta is added to the beginning datetime, so that the output datetime string is absolute.
- Parameters
beginning_datetime (datetime.datetime) – reference datetime to get absolute datetime
delta_dict (dict) – keyword arguments of https://docs.python.org/3/library/datetime.html#timedelta-objects (e.g.
{"milliseconds": 500})kwargs – keyword arguments
convert_datetime_to_string()
- Returns
absolute datetime
- Return type
str
-
visiannot.tools.datetime_converter.get_datetime_from_path(path, datetime_del, datetime_pos, fmt, **kwargs)[source]¶ Gets datetime contained in a file name
- Parameters
path (str) – path where to find datetime
datetime_del (str) – delimiter to get beginning datetime in the file name
datetime_pos (str) – position of the beginning datetime in the file name, according to the delimiter
fmt (str) – format of the beginning datetime in the file name (either
"posix"or a format compliant withdatetime.strptime(), see https://docs.python.org/3/library/datetime.html#strftime-and-strptime-format-codes)kwargs – keyword arguments of
convert_string_to_datetime()
If datetime is not in the file name, then set to
Noneone of the following positional argument:datetime_del,datetime_pos,fmt.If datetime is not found in the path, by default the function returns
datetime(2000, 1, 1, 0, 0, 0).- Returns
datetime
- Return type
datetime.datetime