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:
arkn98 2023-12-19 23:12:17 -05:00 committed by Brandon Williams
parent 6e72cf0ee5
commit bfb5c59342
2 changed files with 7 additions and 5 deletions

View File

@ -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)

View File

@ -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()