Time Module Documentation
This module provides functions for working with time.
Functions:
| Name | Description |
|---|---|
time_now |
Returns the current time in microseconds since the epoch in local time. |
time_now_utc |
Returns the current time in microseconds since the epoch in UTC. |
utime2datestr |
Converts a Unix timestamp to a date string. |
datestr2utime |
Converts a date string to a Unix timestamp. |
datestr2utime(datestr, datefmt='%Y/%m/%d %H:%M:%S')
Converts date strings to a Unix timestamp in microseconds.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
datestr
|
Union[str, List[str], ndarray]
|
Date string or list of date strings. |
required |
datefmt
|
str
|
Date format. Defaults to "%Y/%m/%d %H:%M:%S". |
'%Y/%m/%d %H:%M:%S'
|
Returns:
| Name | Type | Description |
|---|---|---|
unix_ms |
Union[float, List[float]]
|
Unix timestamp in microseconds or list of timestamps. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If the input datestr is not a string, list of strings or numpy array. |
ValueError
|
If the input datestr list is empty or if the date format is incorrect. |
Examples:
>>> datestr2utime("2020/05/28 12:09:10")
1590678950000000.0
Source code in navlib/time/time.py
196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 | |
time_interval_indices(time, t0, tn)
Given a set of timestamps, return the range of indices that is between t0 and tn. This function is useful for filtering timestamps within a specific time interval.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
time
|
Union[List[float], ndarray]
|
Non-saturated values as a list of floats or as a numpy array. |
required |
t0
|
Union[int, float]
|
Lower boundary as a float or int. |
required |
tn
|
Union[int, float]
|
Upper boundary as a float or int. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
idx_range |
Union[List[float], ndarray]
|
Index range between t0 and tn. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If the input time is not a list or numpy array, or if t0 and tn are not int or float. |
ValueError
|
If the input time is not 1D, if it is empty, or if tn is not greater than t0. |
Source code in navlib/time/time.py
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 | |
time_now()
Returns the current time in microseconds since the epoch in local time.
Returns:
| Name | Type | Description |
|---|---|---|
unix_ms |
float
|
Current time in microseconds since the epoch. |
Examples:
>>> time_now()
1590678950000000.0
Source code in navlib/time/time.py
108 109 110 111 112 113 114 115 116 117 118 119 120 121 | |
time_now_utc()
Returns the current time in microseconds since the epoch in UTC.
Returns:
| Name | Type | Description |
|---|---|---|
unix_utc_ms |
float
|
Current time in microseconds since the epoch. |
Examples:
>>> time_now_utc()
1590678950000000.0
Source code in navlib/time/time.py
124 125 126 127 128 129 130 131 132 133 134 135 136 137 | |
timestamps_make_uniform(timestamps)
Given a set of timestamps with non-uniform intervals or non-monotonic order, return a new set of timestamps with uniform intervals. This new set of timestamps will be evenly spaced between the minimum and maximum timestamps of the input.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
timestamps
|
Union[List[float], ndarray]
|
Non-saturated values as a list of floats or as a numpy array. |
required |
Raises:
| Type | Description |
|---|---|
TypeError
|
If the input timestamps is not a list or numpy array. |
ValueError
|
If the input timestamps is not 1D or if it is empty. |
Source code in navlib/time/time.py
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 | |
utime2datestr(utime, datefmt='%Y/%m/%d %H:%M:%S')
Converts unix timestamp in microseconds to a date string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
utime
|
Union[List[float], ndarray, int, float]
|
Unix timestamp in microseconds. |
required |
datefmt
|
str
|
Date format. Defaults to "%Y/%m/%d %H:%M:%S". |
'%Y/%m/%d %H:%M:%S'
|
Returns:
| Name | Type | Description |
|---|---|---|
data |
Union[List[str], str]
|
Date string or list of date strings. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If the input utime is not a list, numpy array, int, or float. |
ValueError
|
If the input utime list is empty or if the date format is incorrect. |
Examples:
>>> utime2datestr(1590678950000000.0)
'2020/05/28 12:09:10'
Source code in navlib/time/time.py
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 | |