Call time.strftime for years before 1900 by rolling forward a multiple of 28 years. *fmt* is a :func:`strftime` format string. Dalke: I hope I did this math right. Every 28 years the calendar repeats, except through century leap years excepting the 400 year
(self, dt, fmt=None)
| 640 | |
| 641 | @cbook.deprecated("3.0") |
| 642 | def strftime_pre_1900(self, dt, fmt=None): |
| 643 | """Call time.strftime for years before 1900 by rolling |
| 644 | forward a multiple of 28 years. |
| 645 | |
| 646 | *fmt* is a :func:`strftime` format string. |
| 647 | |
| 648 | Dalke: I hope I did this math right. Every 28 years the |
| 649 | calendar repeats, except through century leap years excepting |
| 650 | the 400 year leap years. But only if you're using the Gregorian |
| 651 | calendar. |
| 652 | """ |
| 653 | if fmt is None: |
| 654 | fmt = self.fmt |
| 655 | |
| 656 | # Since python's time module's strftime implementation does not |
| 657 | # support %f microsecond (but the datetime module does), use a |
| 658 | # regular expression substitution to replace instances of %f. |
| 659 | # Note that this can be useful since python's floating-point |
| 660 | # precision representation for datetime causes precision to be |
| 661 | # more accurate closer to year 0 (around the year 2000, precision |
| 662 | # can be at 10s of microseconds). |
| 663 | fmt = re.sub(r'((^|[^%])(%%)*)%f', |
| 664 | r'\g<1>{0:06d}'.format(dt.microsecond), fmt) |
| 665 | |
| 666 | year = dt.year |
| 667 | # For every non-leap year century, advance by |
| 668 | # 6 years to get into the 28-year repeat cycle |
| 669 | delta = 2000 - year |
| 670 | off = 6 * (delta // 100 + delta // 400) |
| 671 | year = year + off |
| 672 | |
| 673 | # Move to between the years 1973 and 2000 |
| 674 | year1 = year + ((2000 - year) // 28) * 28 |
| 675 | year2 = year1 + 28 |
| 676 | timetuple = dt.timetuple() |
| 677 | # Generate timestamp string for year and year+28 |
| 678 | s1 = time.strftime(fmt, (year1,) + timetuple[1:]) |
| 679 | s2 = time.strftime(fmt, (year2,) + timetuple[1:]) |
| 680 | |
| 681 | # Replace instances of respective years (both 2-digit and 4-digit) |
| 682 | # that are located at the same indexes of s1, s2 with dt's year. |
| 683 | # Note that C++'s strftime implementation does not use padded |
| 684 | # zeros or padded whitespace for %y or %Y for years before 100, but |
| 685 | # uses padded zeros for %x. (For example, try the runnable examples |
| 686 | # with .tm_year in the interval [-1900, -1800] on |
| 687 | # http://en.cppreference.com/w/c/chrono/strftime.) For ease of |
| 688 | # implementation, we always use padded zeros for %y, %Y, and %x. |
| 689 | s1, s2 = self._replace_common_substr(s1, s2, |
| 690 | "{0:04d}".format(year1), |
| 691 | "{0:04d}".format(year2), |
| 692 | "{0:04d}".format(dt.year)) |
| 693 | s1, s2 = self._replace_common_substr(s1, s2, |
| 694 | "{0:02d}".format(year1 % 100), |
| 695 | "{0:02d}".format(year2 % 100), |
| 696 | "{0:02d}".format(dt.year % 100)) |
| 697 | return cbook.unicode_safe(s1) |
| 698 | |
| 699 | @cbook.deprecated("3.0") |
no test coverage detected