| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 7b1f0f2 commit 307bcea
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -504,10 +504,16 @@ def test_time_struct(self): | |||
| 504 | 504 | self.assertEqual(str(t), time.strftime("%Y%m%dT%H:%M:%S", d)) | |
| 505 | 505 | ||
| 506 | 506 | def test_datetime_datetime(self): | |
| 507 | + # naive (no tzinfo) | ||
| 507 | 508 | d = datetime.datetime(2007,1,2,3,4,5) | |
| 508 | 509 | t = xmlrpclib.DateTime(d) | |
| 509 | 510 | self.assertEqual(str(t), '20070102T03:04:05') | |
| 510 | 511 | ||
| 512 | + # aware (with tzinfo): the timezone is ignored | ||
| 513 | + d = datetime.datetime(2023, 6, 12, 13, 30, tzinfo=datetime.UTC) | ||
| 514 | + t = xmlrpclib.DateTime(d) | ||
| 515 | + self.assertEqual(str(t), '20230612T13:30:00') | ||
| 516 | + | ||
| 511 | 517 | def test_repr(self): | |
| 512 | 518 | d = datetime.datetime(2007,1,2,3,4,5) | |
| 513 | 519 | t = xmlrpclib.DateTime(d) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -245,41 +245,15 @@ def __repr__(self): | |||
| 245 | 245 | ||
| 246 | 246 | ## | |
| 247 | 247 | # Backwards compatibility | |
| 248 | - | ||
| 249 | 248 | boolean = Boolean = bool | |
| 250 | 249 | ||
| 251 | - ## | ||
| 252 | - # Wrapper for XML-RPC DateTime values. This converts a time value to | ||
| 253 | - # the format used by XML-RPC. | ||
| 254 | - # <p> | ||
| 255 | - # The value can be given as a datetime object, as a string in the | ||
| 256 | - # format "yyyymmddThh:mm:ss", as a 9-item time tuple (as returned by | ||
| 257 | - # time.localtime()), or an integer value (as returned by time.time()). | ||
| 258 | - # The wrapper uses time.localtime() to convert an integer to a time | ||
| 259 | - # tuple. | ||
| 260 | - # | ||
| 261 | - # @param value The time, given as a datetime object, an ISO 8601 string, | ||
| 262 | - # a time tuple, or an integer time value. | ||
| 263 | - | ||
| 264 | 250 | ||
| 265 | - # Issue #13305: different format codes across platforms | ||
| 266 | - _day0 = datetime(1, 1, 1) | ||
| 267 | - def _try(fmt): | ||
| 268 | - try: | ||
| 269 | - return _day0.strftime(fmt) == '0001' | ||
| 270 | - except ValueError: | ||
| 271 | - return False | ||
| 272 | - if _try('%Y'): # Mac OS X | ||
| 273 | - def _iso8601_format(value): | ||
| 274 | - return value.strftime("%Y%m%dT%H:%M:%S") | ||
| 275 | - elif _try('%4Y'): # Linux | ||
| 276 | - def _iso8601_format(value): | ||
| 277 | - return value.strftime("%4Y%m%dT%H:%M:%S") | ||
| 278 | - else: | ||
| 279 | - def _iso8601_format(value): | ||
| 280 | - return value.strftime("%Y%m%dT%H:%M:%S").zfill(17) | ||
| 281 | - del _day0 | ||
| 282 | - del _try | ||
| 251 | + def _iso8601_format(value): | ||
| 252 | + if value.tzinfo is not None: | ||
| 253 | + # XML-RPC only uses the naive portion of the datetime | ||
| 254 | + value = value.replace(tzinfo=None) | ||
| 255 | + # XML-RPC doesn't use '-' separator in the date part | ||
| 256 | + return value.isoformat(timespec='seconds').replace('-', '') | ||
| 283 | 257 | ||
| 284 | 258 | ||
| 285 | 259 | def _strftime(value): | |
| Back | FazBrowse Home | New Git URL |
0 commit comments