return a fixed-offset timezone based off a number of minutes. >>> one = FixedOffset(-330) >>> one pytz.FixedOffset(-330) >>> str(one.utcoffset(datetime.datetime.now())) '-1 day, 18:30:00' >>> str(one.dst(datetime.datetime.now())) '0:00:00'
(offset, _tzinfos={})
| 436 | |
| 437 | |
| 438 | def FixedOffset(offset, _tzinfos={}): |
| 439 | """return a fixed-offset timezone based off a number of minutes. |
| 440 | |
| 441 | >>> one = FixedOffset(-330) |
| 442 | >>> one |
| 443 | pytz.FixedOffset(-330) |
| 444 | >>> str(one.utcoffset(datetime.datetime.now())) |
| 445 | '-1 day, 18:30:00' |
| 446 | >>> str(one.dst(datetime.datetime.now())) |
| 447 | '0:00:00' |
| 448 | |
| 449 | >>> two = FixedOffset(1380) |
| 450 | >>> two |
| 451 | pytz.FixedOffset(1380) |
| 452 | >>> str(two.utcoffset(datetime.datetime.now())) |
| 453 | '23:00:00' |
| 454 | >>> str(two.dst(datetime.datetime.now())) |
| 455 | '0:00:00' |
| 456 | |
| 457 | The datetime.timedelta must be between the range of -1 and 1 day, |
| 458 | non-inclusive. |
| 459 | |
| 460 | >>> FixedOffset(1440) |
| 461 | Traceback (most recent call last): |
| 462 | ... |
| 463 | ValueError: ('absolute offset is too large', 1440) |
| 464 | |
| 465 | >>> FixedOffset(-1440) |
| 466 | Traceback (most recent call last): |
| 467 | ... |
| 468 | ValueError: ('absolute offset is too large', -1440) |
| 469 | |
| 470 | An offset of 0 is special-cased to return UTC. |
| 471 | |
| 472 | >>> FixedOffset(0) is UTC |
| 473 | True |
| 474 | |
| 475 | There should always be only one instance of a FixedOffset per timedelta. |
| 476 | This should be true for multiple creation calls. |
| 477 | |
| 478 | >>> FixedOffset(-330) is one |
| 479 | True |
| 480 | >>> FixedOffset(1380) is two |
| 481 | True |
| 482 | |
| 483 | It should also be true for pickling. |
| 484 | |
| 485 | >>> import pickle |
| 486 | >>> pickle.loads(pickle.dumps(one)) is one |
| 487 | True |
| 488 | >>> pickle.loads(pickle.dumps(two)) is two |
| 489 | True |
| 490 | """ |
| 491 | if offset == 0: |
| 492 | return UTC |
| 493 | |
| 494 | info = _tzinfos.get(offset) |
| 495 | if info is None: |
nothing calls this directly
no test coverage detected