Repository navigation
Commit 63ac01f
authored
Python: fix: TimePlugin timeZoneOffset/timeZoneName return actual values (microsoft#14583) (microsoft#14604)
### Motivation and Context
`TimePlugin.timeZoneOffset()` and `TimePlugin.timeZoneName()` always
returned empty strings because they formatted a naive
`datetime.datetime.now()` (no tzinfo) with `strftime("%z")` /
`strftime("%Z")`, which produce empty output when the datetime is
timezone-naive.
### Fix
Both methods now use `datetime.datetime.now().astimezone()`, so they
report the local machine's time zone offset and name (e.g. `-0400` /
`EDT`) instead of empty strings.
### Tests
- Updated `test_time_zone_offset` and `test_time_zone_name` expectations
(the mocked UTC instant is now converted to local time before
formatting).
- Added regression tests `test_time_zone_offset_without_mock` and
`test_time_zone_name_without_mock` that verify non-empty local
offset/name values without mocking.
- All 24 unit tests in `test_time_plugin.py` pass.
Fixes microsoft#14583
---
AI assistance disclosure: AI assistance was used in preparing this
change (the fix implementation and test updates); the author reviewed
and committed the final code.1 parent fdbc2cc commit 63ac01f
2 files changed
Lines changed: 31 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
226 | 226 | | |
227 | 227 | | |
228 | 228 | | |
229 | | - | |
| 229 | + | |
230 | 230 | | |
231 | | - | |
| 231 | + | |
232 | 232 | | |
233 | 233 | | |
234 | 234 | | |
| |||
238 | 238 | | |
239 | 239 | | |
240 | 240 | | |
241 | | - | |
| 241 | + | |
242 | 242 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
175 | 175 | | |
176 | 176 | | |
177 | 177 | | |
178 | | - | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
179 | 181 | | |
180 | 182 | | |
181 | 183 | | |
182 | 184 | | |
183 | 185 | | |
184 | 186 | | |
185 | 187 | | |
186 | | - | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
0 commit comments