Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ Changes in Apache Libcloud 4.0.0
Common
~~~~~~

- Preserve explicit UTC (``Z``) in ISO 8601 timestamps when a non-UTC or
``None`` fallback timezone is supplied. The fallback now applies only to
timestamps without a timezone.
(GITHUB-2254)
[khushalx - @khushalx]

- Remove obsolete Dimension Data (Compute, Backup, and Load Balancer) and
Internet Solutions (Compute) drivers, along with their associated documentation
and tests.
Expand Down
23 changes: 23 additions & 0 deletions libcloud/test/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import platform
import unittest
import warnings
from datetime import timedelta
from itertools import chain

import pytest
Expand All @@ -30,6 +31,7 @@
from libcloud.utils.misc import get_driver, set_driver, get_secure_random_string
from libcloud.common.types import LibcloudError
from libcloud.compute.types import Provider
from libcloud.utils.iso8601 import UTC, FixedOffset, parse_date, parse_timezone
from libcloud.utils.publickey import (
get_pubkey_comment,
get_pubkey_ssh2_fingerprint,
Expand Down Expand Up @@ -63,6 +65,27 @@ def show_warning(msg, cat, fname, lno, file=None, line=None):
original_func = warnings.showwarning


class Iso8601TimezoneTests(unittest.TestCase):
def test_explicit_utc_ignores_default_timezone(self):
for default in (FixedOffset(5, 30, "+05:30"), FixedOffset(-4, 0, "-04:00"), None):
with self.subTest(default=default):
self.assertIs(parse_timezone("Z", default_timezone=default), UTC)
timestamp = parse_date("2026-12-01T12:34:56Z", default_timezone=default)
self.assertEqual(timestamp.utcoffset(), timedelta(0))

def test_missing_timezone_uses_default(self):
for default in (FixedOffset(5, 30, "+05:30"), None):
with self.subTest(default=default):
timestamp = parse_date("2026-12-01T12:34:56", default_timezone=default)
self.assertIs(timestamp.tzinfo, default)

def test_explicit_offset_ignores_default_timezone(self):
timestamp = parse_date(
"2026-12-01T12:34:56-03:30", default_timezone=FixedOffset(5, 30, "+05:30")
)
self.assertEqual(timestamp.utcoffset(), -timedelta(hours=3, minutes=30))


class TestUtils(unittest.TestCase):
def setUp(self):
global WARNINGS_BUFFER
Expand Down
2 changes: 1 addition & 1 deletion libcloud/utils/iso8601.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def __repr__(self):
def parse_timezone(tzstring, default_timezone=UTC):
"""Parses ISO 8601 time zone specs into tzinfo offsets"""
if tzstring == "Z":
return default_timezone
return UTC
# This isn't strictly correct, but it's common to encounter dates without
# timezones so I'll assume the default (which defaults to UTC).
# Addresses issue 4.
Expand Down