|
1 | 1 | from datetime import datetime |
2 | 2 |
|
| 3 | +import pytest |
3 | 4 | from dateutil import tz |
4 | 5 |
|
5 | 6 | from elementary.utils.time import ( |
| 7 | + convert_partial_iso_format_to_full_iso_format, |
6 | 8 | convert_time_to_timezone, |
7 | 9 | datetime_strftime, |
8 | 10 | get_formatted_timedelta, |
@@ -67,3 +69,49 @@ def test_convert_time_to_timezone(): |
67 | 69 | assert date.hour == 1 |
68 | 70 | assert date_with_timezone.hour == 2 |
69 | 71 | assert (date - date_with_timezone).total_seconds() == 0 |
| 72 | + |
| 73 | + |
| 74 | +@pytest.mark.parametrize( |
| 75 | + "input_time, expected_output", |
| 76 | + [ |
| 77 | + pytest.param( |
| 78 | + "2024-01-01T12:00:00+00", |
| 79 | + "2024-01-01T12:00:00+00:00", |
| 80 | + id="abbreviated_utc_offset", |
| 81 | + ), |
| 82 | + pytest.param( |
| 83 | + "2024-01-01T12:00:00-05", |
| 84 | + "2024-01-01T12:00:00-05:00", |
| 85 | + id="abbreviated_negative_offset", |
| 86 | + ), |
| 87 | + pytest.param( |
| 88 | + "2024-01-01 12:00:00.123456+00", |
| 89 | + "2024-01-01T12:00:00+00:00", |
| 90 | + id="abbreviated_offset_with_fractional_seconds", |
| 91 | + ), |
| 92 | + pytest.param( |
| 93 | + "2024-01-01T12:00:00+00:00", |
| 94 | + "2024-01-01T12:00:00+00:00", |
| 95 | + id="full_utc_offset", |
| 96 | + ), |
| 97 | + pytest.param( |
| 98 | + "2024-01-01T12:00:00+05:30", |
| 99 | + "2024-01-01T12:00:00+05:30", |
| 100 | + id="full_non_utc_offset", |
| 101 | + ), |
| 102 | + pytest.param( |
| 103 | + "2024-01-01T12:00:00", |
| 104 | + "2024-01-01T12:00:00+00:00", |
| 105 | + id="no_offset_defaults_to_utc", |
| 106 | + ), |
| 107 | + pytest.param( |
| 108 | + "2024-01-15", |
| 109 | + "2024-01-15T00:00:00+00:00", |
| 110 | + id="date_only_not_corrupted", |
| 111 | + ), |
| 112 | + ], |
| 113 | +) |
| 114 | +def test_convert_partial_iso_format_to_full_iso_format( |
| 115 | + input_time: str, expected_output: str |
| 116 | +) -> None: |
| 117 | + assert convert_partial_iso_format_to_full_iso_format(input_time) == expected_output |
0 commit comments