mirror of https://github.com/apache/cassandra
Fix datetime_from_utc_to_local in cqlshlib
Patch by Arun Ganesh; reviewed by brads and brandonwilliams for CASSANDRA-18879
This commit is contained in:
parent
6e72cf0ee5
commit
bfb5c59342
|
|
@ -1,4 +1,5 @@
|
|||
5.1
|
||||
* Modernize CQLSH datetime conversions (CASSANDRA-18879)
|
||||
* Harry model and in-JVM tests for partition-restricted 2i queries (CASSANDRA-18275)
|
||||
* Refactor cqlshmain global constants (CASSANDRA-19201)
|
||||
* Remove native_transport_port_ssl (CASSANDRA-19397)
|
||||
|
|
|
|||
|
|
@ -14,8 +14,7 @@
|
|||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
from datetime import datetime
|
||||
import time
|
||||
from datetime import datetime, timezone
|
||||
|
||||
from cassandra.query import QueryTrace, TraceUnavailable
|
||||
from cqlshlib.displaying import MAGENTA
|
||||
|
|
@ -85,6 +84,8 @@ def total_micro_seconds(td):
|
|||
|
||||
|
||||
def datetime_from_utc_to_local(utc_datetime):
|
||||
now_timestamp = time.time()
|
||||
offset = datetime.fromtimestamp(now_timestamp) - datetime.utcfromtimestamp(now_timestamp)
|
||||
return utc_datetime + offset
|
||||
"""
|
||||
Convert a naive UTC datetime to the local timezone.
|
||||
This is necessary because the driver always returns naive datetime objects.
|
||||
"""
|
||||
return utc_datetime.replace(tzinfo=timezone.utc).astimezone()
|
||||
|
|
|
|||
Loading…
Reference in New Issue