chdb 3.6.0__cp38-abi3-macosx_11_0_arm64.whl → 3.7.0__cp38-abi3-macosx_11_0_arm64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of chdb might be problematic. Click here for more details.
- chdb/.flake8 +5 -0
- chdb/__init__.py +132 -11
- chdb/_chdb.abi3.so +0 -0
- chdb/build-musl.sh +166 -0
- chdb/build.sh +370 -0
- chdb/build_linux_arm64.sh +63 -0
- chdb/build_mac_arm64.sh +121 -0
- chdb/build_pybind11.sh +131 -0
- chdb/dataframe/__init__.py +7 -2
- chdb/dataframe/query.py +211 -23
- chdb/dbapi/__init__.py +57 -2
- chdb/dbapi/connections.py +169 -12
- chdb/dbapi/converters.py +352 -34
- chdb/dbapi/cursors.py +264 -70
- chdb/dbapi/err.py +269 -30
- chdb/dbapi/times.py +171 -0
- chdb/libpybind11nonlimitedapi_chdb_3.10.dylib +0 -0
- chdb/libpybind11nonlimitedapi_chdb_3.11.dylib +0 -0
- chdb/libpybind11nonlimitedapi_chdb_3.12.dylib +0 -0
- chdb/libpybind11nonlimitedapi_chdb_3.13.dylib +0 -0
- chdb/libpybind11nonlimitedapi_chdb_3.8.dylib +0 -0
- chdb/libpybind11nonlimitedapi_chdb_3.9.dylib +0 -0
- chdb/libpybind11nonlimitedapi_stubs.dylib +0 -0
- chdb/session/state.py +167 -4
- chdb/state/sqlitelike.py +608 -34
- chdb/test_smoke.sh +32 -0
- chdb/udf/__init__.py +7 -0
- chdb/udf/udf.py +41 -25
- chdb/utils/__init__.py +6 -0
- chdb/utils/trace.py +31 -0
- chdb/utils/types.py +62 -64
- chdb/vars.sh +48 -0
- {chdb-3.6.0.dist-info → chdb-3.7.0.dist-info}/METADATA +29 -18
- chdb-3.7.0.dist-info/RECORD +43 -0
- chdb-3.6.0.dist-info/RECORD +0 -35
- {chdb-3.6.0.dist-info → chdb-3.7.0.dist-info}/LICENSE.txt +0 -0
- {chdb-3.6.0.dist-info → chdb-3.7.0.dist-info}/WHEEL +0 -0
- {chdb-3.6.0.dist-info → chdb-3.7.0.dist-info}/top_level.txt +0 -0
chdb/dbapi/err.py
CHANGED
|
@@ -1,61 +1,300 @@
|
|
|
1
|
+
"""Exception classes for chdb database operations.
|
|
2
|
+
|
|
3
|
+
This module provides a complete hierarchy of exception classes for handling
|
|
4
|
+
database-related errors in chdb, following the Python Database API Specification v2.0.
|
|
5
|
+
|
|
6
|
+
The exception hierarchy is structured as follows::
|
|
7
|
+
|
|
8
|
+
StandardError
|
|
9
|
+
├── Warning
|
|
10
|
+
└── Error
|
|
11
|
+
├── InterfaceError
|
|
12
|
+
└── DatabaseError
|
|
13
|
+
├── DataError
|
|
14
|
+
├── OperationalError
|
|
15
|
+
├── IntegrityError
|
|
16
|
+
├── InternalError
|
|
17
|
+
├── ProgrammingError
|
|
18
|
+
└── NotSupportedError
|
|
19
|
+
|
|
20
|
+
Each exception class represents a specific category of database errors:
|
|
21
|
+
|
|
22
|
+
- **Warning**: Non-fatal warnings during database operations
|
|
23
|
+
- **InterfaceError**: Problems with the database interface itself
|
|
24
|
+
- **DatabaseError**: Base class for all database-related errors
|
|
25
|
+
- **DataError**: Problems with data processing (invalid values, type errors)
|
|
26
|
+
- **OperationalError**: Database operational issues (connectivity, resources)
|
|
27
|
+
- **IntegrityError**: Constraint violations (foreign keys, uniqueness)
|
|
28
|
+
- **InternalError**: Database internal errors and corruption
|
|
29
|
+
- **ProgrammingError**: SQL syntax errors and API misuse
|
|
30
|
+
- **NotSupportedError**: Unsupported features or operations
|
|
31
|
+
|
|
32
|
+
.. note::
|
|
33
|
+
These exception classes are compliant with Python DB API 2.0 specification
|
|
34
|
+
and provide consistent error handling across different database operations.
|
|
35
|
+
|
|
36
|
+
.. seealso::
|
|
37
|
+
- `Python Database API Specification v2.0 <https://peps.python.org/pep-0249/>`_
|
|
38
|
+
- :mod:`chdb.dbapi.connections` - Database connection management
|
|
39
|
+
- :mod:`chdb.dbapi.cursors` - Database cursor operations
|
|
40
|
+
|
|
41
|
+
Examples:
|
|
42
|
+
>>> try:
|
|
43
|
+
... cursor.execute("SELECT * FROM nonexistent_table")
|
|
44
|
+
... except ProgrammingError as e:
|
|
45
|
+
... print(f"SQL Error: {e}")
|
|
46
|
+
...
|
|
47
|
+
SQL Error: Table 'nonexistent_table' doesn't exist
|
|
48
|
+
|
|
49
|
+
>>> try:
|
|
50
|
+
... cursor.execute("INSERT INTO users (id) VALUES (1), (1)")
|
|
51
|
+
... except IntegrityError as e:
|
|
52
|
+
... print(f"Constraint violation: {e}")
|
|
53
|
+
...
|
|
54
|
+
Constraint violation: Duplicate entry '1' for key 'PRIMARY'
|
|
55
|
+
"""
|
|
56
|
+
|
|
57
|
+
|
|
1
58
|
class StandardError(Exception):
|
|
2
|
-
"""Exception related to operation with chdb.
|
|
59
|
+
"""Exception related to operation with chdb.
|
|
60
|
+
|
|
61
|
+
This is the base class for all chdb-related exceptions. It inherits from
|
|
62
|
+
Python's built-in Exception class and serves as the root of the exception
|
|
63
|
+
hierarchy for database operations.
|
|
64
|
+
|
|
65
|
+
.. note::
|
|
66
|
+
This exception class follows the Python DB API 2.0 specification
|
|
67
|
+
for database exception handling.
|
|
68
|
+
"""
|
|
3
69
|
|
|
4
70
|
|
|
5
71
|
class Warning(StandardError):
|
|
6
|
-
"""Exception raised for important warnings like data truncations
|
|
7
|
-
|
|
72
|
+
"""Exception raised for important warnings like data truncations while inserting, etc.
|
|
73
|
+
|
|
74
|
+
This exception is raised when the database operation completes but with
|
|
75
|
+
important warnings that should be brought to the attention of the application.
|
|
76
|
+
Common scenarios include:
|
|
77
|
+
|
|
78
|
+
- Data truncation during insertion
|
|
79
|
+
- Precision loss in numeric conversions
|
|
80
|
+
- Character set conversion warnings
|
|
81
|
+
|
|
82
|
+
.. note::
|
|
83
|
+
This follows the Python DB API 2.0 specification for warning exceptions.
|
|
84
|
+
"""
|
|
8
85
|
|
|
9
86
|
|
|
10
87
|
class Error(StandardError):
|
|
11
|
-
"""Exception that is the base class of all other error exceptions
|
|
12
|
-
|
|
88
|
+
"""Exception that is the base class of all other error exceptions (not Warning).
|
|
89
|
+
|
|
90
|
+
This is the base class for all error exceptions in chdb, excluding warnings.
|
|
91
|
+
It serves as the parent class for all database error conditions that prevent
|
|
92
|
+
successful completion of operations.
|
|
93
|
+
|
|
94
|
+
.. note::
|
|
95
|
+
This exception hierarchy follows the Python DB API 2.0 specification.
|
|
96
|
+
|
|
97
|
+
.. seealso::
|
|
98
|
+
:class:`Warning` - For non-fatal warnings that don't prevent operation completion
|
|
99
|
+
"""
|
|
13
100
|
|
|
14
101
|
|
|
15
102
|
class InterfaceError(Error):
|
|
16
|
-
"""Exception raised for errors that are related to the database
|
|
17
|
-
|
|
103
|
+
"""Exception raised for errors that are related to the database interface rather than the database itself.
|
|
104
|
+
|
|
105
|
+
This exception is raised when there are problems with the database interface
|
|
106
|
+
implementation, such as:
|
|
107
|
+
|
|
108
|
+
- Invalid connection parameters
|
|
109
|
+
- API misuse (calling methods on closed connections)
|
|
110
|
+
- Interface-level protocol errors
|
|
111
|
+
- Module import or initialization failures
|
|
112
|
+
|
|
113
|
+
:raises InterfaceError: When database interface encounters errors unrelated to database operations
|
|
114
|
+
|
|
115
|
+
.. note::
|
|
116
|
+
These errors are typically programming errors or configuration issues
|
|
117
|
+
that can be resolved by fixing the client code or configuration.
|
|
118
|
+
"""
|
|
18
119
|
|
|
19
120
|
|
|
20
121
|
class DatabaseError(Error):
|
|
21
|
-
"""Exception raised for errors that are related to the
|
|
22
|
-
|
|
122
|
+
"""Exception raised for errors that are related to the database.
|
|
123
|
+
|
|
124
|
+
This is the base class for all database-related errors. It encompasses
|
|
125
|
+
all errors that occur during database operations and are related to the
|
|
126
|
+
database itself rather than the interface.
|
|
127
|
+
|
|
128
|
+
Common scenarios include:
|
|
129
|
+
|
|
130
|
+
- SQL execution errors
|
|
131
|
+
- Database connectivity issues
|
|
132
|
+
- Transaction-related problems
|
|
133
|
+
- Database-specific constraints violations
|
|
134
|
+
|
|
135
|
+
.. note::
|
|
136
|
+
This serves as the parent class for more specific database error types
|
|
137
|
+
such as :class:`DataError`, :class:`OperationalError`, etc.
|
|
138
|
+
"""
|
|
23
139
|
|
|
24
140
|
|
|
25
141
|
class DataError(DatabaseError):
|
|
26
|
-
"""Exception raised for errors that are due to problems with the
|
|
27
|
-
|
|
28
|
-
|
|
142
|
+
"""Exception raised for errors that are due to problems with the processed data.
|
|
143
|
+
|
|
144
|
+
This exception is raised when database operations fail due to issues with
|
|
145
|
+
the data being processed, such as:
|
|
146
|
+
|
|
147
|
+
- Division by zero operations
|
|
148
|
+
- Numeric values out of range
|
|
149
|
+
- Invalid date/time values
|
|
150
|
+
- String truncation errors
|
|
151
|
+
- Type conversion failures
|
|
152
|
+
- Invalid data format for column type
|
|
153
|
+
|
|
154
|
+
:raises DataError: When data validation or processing fails
|
|
155
|
+
|
|
156
|
+
Examples:
|
|
157
|
+
>>> # Division by zero in SQL
|
|
158
|
+
>>> cursor.execute("SELECT 1/0")
|
|
159
|
+
DataError: Division by zero
|
|
160
|
+
|
|
161
|
+
>>> # Invalid date format
|
|
162
|
+
>>> cursor.execute("INSERT INTO table VALUES ('invalid-date')")
|
|
163
|
+
DataError: Invalid date format
|
|
164
|
+
"""
|
|
29
165
|
|
|
30
166
|
|
|
31
167
|
class OperationalError(DatabaseError):
|
|
32
|
-
"""Exception raised for errors that are related to the database's
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
168
|
+
"""Exception raised for errors that are related to the database's operation.
|
|
169
|
+
|
|
170
|
+
This exception is raised for errors that occur during database operation
|
|
171
|
+
and are not necessarily under the control of the programmer, including:
|
|
172
|
+
|
|
173
|
+
- Unexpected disconnection from database
|
|
174
|
+
- Database server not found or unreachable
|
|
175
|
+
- Transaction processing failures
|
|
176
|
+
- Memory allocation errors during processing
|
|
177
|
+
- Disk space or resource exhaustion
|
|
178
|
+
- Database server internal errors
|
|
179
|
+
- Authentication or authorization failures
|
|
180
|
+
|
|
181
|
+
:raises OperationalError: When database operations fail due to operational issues
|
|
182
|
+
|
|
183
|
+
.. note::
|
|
184
|
+
These errors are typically transient and may be resolved by retrying
|
|
185
|
+
the operation or addressing system-level issues.
|
|
186
|
+
|
|
187
|
+
.. warning::
|
|
188
|
+
Some operational errors may indicate serious system problems that
|
|
189
|
+
require administrative intervention.
|
|
190
|
+
"""
|
|
37
191
|
|
|
38
192
|
|
|
39
193
|
class IntegrityError(DatabaseError):
|
|
40
|
-
"""Exception raised when the relational integrity of the database
|
|
41
|
-
|
|
42
|
-
|
|
194
|
+
"""Exception raised when the relational integrity of the database is affected.
|
|
195
|
+
|
|
196
|
+
This exception is raised when database operations violate integrity constraints,
|
|
197
|
+
including:
|
|
198
|
+
|
|
199
|
+
- Foreign key constraint violations
|
|
200
|
+
- Primary key or unique constraint violations (duplicate keys)
|
|
201
|
+
- Check constraint violations
|
|
202
|
+
- NOT NULL constraint violations
|
|
203
|
+
- Referential integrity violations
|
|
204
|
+
|
|
205
|
+
:raises IntegrityError: When database integrity constraints are violated
|
|
206
|
+
|
|
207
|
+
Examples:
|
|
208
|
+
>>> # Duplicate primary key
|
|
209
|
+
>>> cursor.execute("INSERT INTO users (id, name) VALUES (1, 'John')")
|
|
210
|
+
>>> cursor.execute("INSERT INTO users (id, name) VALUES (1, 'Jane')")
|
|
211
|
+
IntegrityError: Duplicate entry '1' for key 'PRIMARY'
|
|
212
|
+
|
|
213
|
+
>>> # Foreign key violation
|
|
214
|
+
>>> cursor.execute("INSERT INTO orders (user_id) VALUES (999)")
|
|
215
|
+
IntegrityError: Cannot add or update a child row: foreign key constraint fails
|
|
216
|
+
"""
|
|
43
217
|
|
|
44
218
|
|
|
45
219
|
class InternalError(DatabaseError):
|
|
46
|
-
"""Exception raised when the database encounters an internal
|
|
47
|
-
|
|
48
|
-
|
|
220
|
+
"""Exception raised when the database encounters an internal error.
|
|
221
|
+
|
|
222
|
+
This exception is raised when the database system encounters internal
|
|
223
|
+
errors that are not caused by the application, such as:
|
|
224
|
+
|
|
225
|
+
- Invalid cursor state (cursor is not valid anymore)
|
|
226
|
+
- Transaction state inconsistencies (transaction is out of sync)
|
|
227
|
+
- Database corruption issues
|
|
228
|
+
- Internal data structure corruption
|
|
229
|
+
- System-level database errors
|
|
230
|
+
|
|
231
|
+
:raises InternalError: When database encounters internal inconsistencies
|
|
232
|
+
|
|
233
|
+
.. warning::
|
|
234
|
+
Internal errors may indicate serious database problems that require
|
|
235
|
+
database administrator attention. These errors are typically not
|
|
236
|
+
recoverable through application-level retry logic.
|
|
237
|
+
|
|
238
|
+
.. note::
|
|
239
|
+
These errors are generally outside the control of the application
|
|
240
|
+
and may require database restart or repair operations.
|
|
241
|
+
"""
|
|
49
242
|
|
|
50
243
|
|
|
51
244
|
class ProgrammingError(DatabaseError):
|
|
52
|
-
"""Exception raised for programming errors
|
|
53
|
-
|
|
54
|
-
|
|
245
|
+
"""Exception raised for programming errors in database operations.
|
|
246
|
+
|
|
247
|
+
This exception is raised when there are programming errors in the
|
|
248
|
+
application's database usage, including:
|
|
249
|
+
|
|
250
|
+
- Table or column not found
|
|
251
|
+
- Table or index already exists when creating
|
|
252
|
+
- SQL syntax errors in statements
|
|
253
|
+
- Wrong number of parameters specified in prepared statements
|
|
254
|
+
- Invalid SQL operations (e.g., DROP on non-existent objects)
|
|
255
|
+
- Incorrect usage of database API methods
|
|
256
|
+
|
|
257
|
+
:raises ProgrammingError: When SQL statements or API usage contains errors
|
|
258
|
+
|
|
259
|
+
Examples:
|
|
260
|
+
>>> # Table not found
|
|
261
|
+
>>> cursor.execute("SELECT * FROM nonexistent_table")
|
|
262
|
+
ProgrammingError: Table 'nonexistent_table' doesn't exist
|
|
263
|
+
|
|
264
|
+
>>> # SQL syntax error
|
|
265
|
+
>>> cursor.execute("SELCT * FROM users")
|
|
266
|
+
ProgrammingError: You have an error in your SQL syntax
|
|
267
|
+
|
|
268
|
+
>>> # Wrong parameter count
|
|
269
|
+
>>> cursor.execute("INSERT INTO users (name, age) VALUES (%s)", ('John',))
|
|
270
|
+
ProgrammingError: Column count doesn't match value count
|
|
271
|
+
"""
|
|
55
272
|
|
|
56
273
|
|
|
57
274
|
class NotSupportedError(DatabaseError):
|
|
58
|
-
"""Exception raised
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
275
|
+
"""Exception raised when a method or database API is not supported.
|
|
276
|
+
|
|
277
|
+
This exception is raised when the application attempts to use database
|
|
278
|
+
features or API methods that are not supported by the current database
|
|
279
|
+
configuration or version, such as:
|
|
280
|
+
|
|
281
|
+
- Requesting rollback() on connections without transaction support
|
|
282
|
+
- Using advanced SQL features not supported by the database version
|
|
283
|
+
- Calling methods not implemented by the current driver
|
|
284
|
+
- Attempting to use disabled database features
|
|
285
|
+
|
|
286
|
+
:raises NotSupportedError: When unsupported database features are accessed
|
|
287
|
+
|
|
288
|
+
Examples:
|
|
289
|
+
>>> # Transaction rollback on non-transactional connection
|
|
290
|
+
>>> connection.rollback()
|
|
291
|
+
NotSupportedError: Transactions are not supported
|
|
292
|
+
|
|
293
|
+
>>> # Using unsupported SQL syntax
|
|
294
|
+
>>> cursor.execute("SELECT * FROM table WITH (NOLOCK)")
|
|
295
|
+
NotSupportedError: WITH clause not supported in this database version
|
|
296
|
+
|
|
297
|
+
.. note::
|
|
298
|
+
Check database documentation and driver capabilities to avoid
|
|
299
|
+
these errors. Consider graceful fallbacks where possible.
|
|
300
|
+
"""
|
chdb/dbapi/times.py
CHANGED
|
@@ -1,20 +1,191 @@
|
|
|
1
|
+
"""Date and time type constructors for chdb database operations.
|
|
2
|
+
|
|
3
|
+
This module provides Python DB API 2.0 compliant date and time constructors
|
|
4
|
+
for converting between Unix timestamps and Python datetime objects. These
|
|
5
|
+
functions are essential for handling temporal data in database operations.
|
|
6
|
+
|
|
7
|
+
The module provides the following type aliases and constructor functions:
|
|
8
|
+
|
|
9
|
+
Type Aliases:
|
|
10
|
+
- **Date**: Alias for :class:`datetime.date`
|
|
11
|
+
- **Time**: Alias for :class:`datetime.time`
|
|
12
|
+
- **TimeDelta**: Alias for :class:`datetime.timedelta`
|
|
13
|
+
- **Timestamp**: Alias for :class:`datetime.datetime`
|
|
14
|
+
|
|
15
|
+
Constructor Functions:
|
|
16
|
+
- :func:`DateFromTicks`: Convert Unix timestamp to date object
|
|
17
|
+
- :func:`TimeFromTicks`: Convert Unix timestamp to time object
|
|
18
|
+
- :func:`TimestampFromTicks`: Convert Unix timestamp to datetime object
|
|
19
|
+
|
|
20
|
+
These constructors are particularly useful when working with database systems
|
|
21
|
+
that store temporal data as Unix timestamps or when interfacing with APIs
|
|
22
|
+
that use timestamp representations.
|
|
23
|
+
|
|
24
|
+
.. note::
|
|
25
|
+
All constructor functions use the local timezone for timestamp conversion.
|
|
26
|
+
For UTC conversions, consider using :func:`datetime.datetime.utcfromtimestamp`.
|
|
27
|
+
|
|
28
|
+
.. seealso::
|
|
29
|
+
- :mod:`datetime` - Core datetime functionality
|
|
30
|
+
- :mod:`time` - Time access and conversions
|
|
31
|
+
- `Python DB API Specification v2.0 <https://peps.python.org/pep-0249/>`_
|
|
32
|
+
|
|
33
|
+
Examples:
|
|
34
|
+
>>> import time
|
|
35
|
+
>>> timestamp = time.time() # Current Unix timestamp
|
|
36
|
+
>>>
|
|
37
|
+
>>> # Convert to different temporal types
|
|
38
|
+
>>> date_obj = DateFromTicks(timestamp)
|
|
39
|
+
>>> time_obj = TimeFromTicks(timestamp)
|
|
40
|
+
>>> datetime_obj = TimestampFromTicks(timestamp)
|
|
41
|
+
>>>
|
|
42
|
+
>>> print(f"Date: {date_obj}")
|
|
43
|
+
>>> print(f"Time: {time_obj}")
|
|
44
|
+
>>> print(f"DateTime: {datetime_obj}")
|
|
45
|
+
Date: 2023-12-25
|
|
46
|
+
Time: 14:30:45
|
|
47
|
+
DateTime: 2023-12-25 14:30:45
|
|
48
|
+
"""
|
|
49
|
+
|
|
1
50
|
from time import localtime
|
|
2
51
|
from datetime import date, datetime, time, timedelta
|
|
3
52
|
|
|
4
53
|
|
|
5
54
|
Date = date
|
|
55
|
+
"""Type alias for :class:`datetime.date`.
|
|
56
|
+
|
|
57
|
+
This provides a standard DB API 2.0 compliant alias for the date class,
|
|
58
|
+
allowing portable code across different database drivers.
|
|
59
|
+
|
|
60
|
+
:type: type[datetime.date]
|
|
61
|
+
"""
|
|
62
|
+
|
|
6
63
|
Time = time
|
|
64
|
+
"""Type alias for :class:`datetime.time`.
|
|
65
|
+
|
|
66
|
+
This provides a standard DB API 2.0 compliant alias for the time class,
|
|
67
|
+
allowing portable code across different database drivers.
|
|
68
|
+
|
|
69
|
+
:type: type[datetime.time]
|
|
70
|
+
"""
|
|
71
|
+
|
|
7
72
|
TimeDelta = timedelta
|
|
73
|
+
"""Type alias for :class:`datetime.timedelta`.
|
|
74
|
+
|
|
75
|
+
This provides a standard DB API 2.0 compliant alias for the timedelta class,
|
|
76
|
+
useful for representing time intervals and durations in database operations.
|
|
77
|
+
|
|
78
|
+
:type: type[datetime.timedelta]
|
|
79
|
+
"""
|
|
80
|
+
|
|
8
81
|
Timestamp = datetime
|
|
82
|
+
"""Type alias for :class:`datetime.datetime`.
|
|
83
|
+
|
|
84
|
+
This provides a standard DB API 2.0 compliant alias for the datetime class,
|
|
85
|
+
allowing portable code across different database drivers.
|
|
86
|
+
|
|
87
|
+
:type: type[datetime.datetime]
|
|
88
|
+
"""
|
|
9
89
|
|
|
10
90
|
|
|
11
91
|
def DateFromTicks(ticks):
|
|
92
|
+
"""Convert a Unix timestamp to a date object.
|
|
93
|
+
|
|
94
|
+
This function takes a Unix timestamp (seconds since epoch) and converts
|
|
95
|
+
it to a Python date object representing the date in local time.
|
|
96
|
+
|
|
97
|
+
Args:
|
|
98
|
+
ticks (float): Unix timestamp (seconds since January 1, 1970, 00:00 UTC)
|
|
99
|
+
|
|
100
|
+
Returns:
|
|
101
|
+
datetime.date: Date object representing the local date for the given timestamp
|
|
102
|
+
|
|
103
|
+
Note:
|
|
104
|
+
The conversion uses the local timezone. The time component is ignored,
|
|
105
|
+
only the date portion is extracted.
|
|
106
|
+
|
|
107
|
+
Examples:
|
|
108
|
+
>>> # Convert current timestamp to date
|
|
109
|
+
>>> import time
|
|
110
|
+
>>> current_time = time.time()
|
|
111
|
+
>>> today = DateFromTicks(current_time)
|
|
112
|
+
>>> print(today)
|
|
113
|
+
2023-12-25
|
|
114
|
+
|
|
115
|
+
>>> # Convert specific timestamp
|
|
116
|
+
>>> timestamp = 1640995200.0 # 2022-01-01 00:00:00 UTC
|
|
117
|
+
>>> date_obj = DateFromTicks(timestamp)
|
|
118
|
+
>>> print(date_obj)
|
|
119
|
+
2021-12-31 # Local time (assuming UTC-5 timezone)
|
|
120
|
+
"""
|
|
12
121
|
return date(*localtime(ticks)[:3])
|
|
13
122
|
|
|
14
123
|
|
|
15
124
|
def TimeFromTicks(ticks):
|
|
125
|
+
"""Convert a Unix timestamp to a time object.
|
|
126
|
+
|
|
127
|
+
This function takes a Unix timestamp (seconds since epoch) and converts
|
|
128
|
+
it to a Python time object representing the time of day in local time.
|
|
129
|
+
|
|
130
|
+
Args:
|
|
131
|
+
ticks (float): Unix timestamp (seconds since January 1, 1970, 00:00 UTC)
|
|
132
|
+
|
|
133
|
+
Returns:
|
|
134
|
+
datetime.time: Time object representing the local time for the given timestamp
|
|
135
|
+
|
|
136
|
+
Note:
|
|
137
|
+
The conversion uses the local timezone. The date component is ignored,
|
|
138
|
+
only the time-of-day portion is extracted.
|
|
139
|
+
|
|
140
|
+
Examples:
|
|
141
|
+
>>> # Convert timestamp to time
|
|
142
|
+
>>> timestamp = 1640995200.0 # 2022-01-01 00:00:00 UTC
|
|
143
|
+
>>> time_obj = TimeFromTicks(timestamp)
|
|
144
|
+
>>> print(time_obj)
|
|
145
|
+
19:00:00 # Local time (assuming UTC-5 timezone)
|
|
146
|
+
|
|
147
|
+
>>> # Extract current time
|
|
148
|
+
>>> import time
|
|
149
|
+
>>> current_time = time.time()
|
|
150
|
+
>>> now_time = TimeFromTicks(current_time)
|
|
151
|
+
>>> print(f"Current time: {now_time}")
|
|
152
|
+
"""
|
|
16
153
|
return time(*localtime(ticks)[3:6])
|
|
17
154
|
|
|
18
155
|
|
|
19
156
|
def TimestampFromTicks(ticks):
|
|
157
|
+
"""Convert a Unix timestamp to a datetime object.
|
|
158
|
+
|
|
159
|
+
This function takes a Unix timestamp (seconds since epoch) and converts
|
|
160
|
+
it to a Python datetime object representing the complete date and time
|
|
161
|
+
in local time.
|
|
162
|
+
|
|
163
|
+
Args:
|
|
164
|
+
ticks (float): Unix timestamp (seconds since January 1, 1970, 00:00 UTC)
|
|
165
|
+
|
|
166
|
+
Returns:
|
|
167
|
+
datetime.datetime: DateTime object representing the local datetime for the given timestamp
|
|
168
|
+
|
|
169
|
+
Note:
|
|
170
|
+
The conversion uses the local timezone. This provides both date and time
|
|
171
|
+
components, making it the most complete temporal conversion function.
|
|
172
|
+
|
|
173
|
+
Examples:
|
|
174
|
+
>>> # Convert timestamp to datetime
|
|
175
|
+
>>> timestamp = 1640995200.0 # 2022-01-01 00:00:00 UTC
|
|
176
|
+
>>> dt_obj = TimestampFromTicks(timestamp)
|
|
177
|
+
>>> print(dt_obj)
|
|
178
|
+
2021-12-31 19:00:00 # Local time (assuming UTC-5 timezone)
|
|
179
|
+
|
|
180
|
+
>>> # Convert current timestamp
|
|
181
|
+
>>> import time
|
|
182
|
+
>>> current_time = time.time()
|
|
183
|
+
>>> now_dt = TimestampFromTicks(current_time)
|
|
184
|
+
>>> print(f"Current datetime: {now_dt}")
|
|
185
|
+
Current datetime: 2023-12-25 14:30:45
|
|
186
|
+
|
|
187
|
+
>>> # Use in database operations
|
|
188
|
+
>>> cursor.execute("INSERT INTO events (created_at) VALUES (%s)",
|
|
189
|
+
... (TimestampFromTicks(time.time()),))
|
|
190
|
+
"""
|
|
20
191
|
return datetime(*localtime(ticks)[:6])
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|