Get a datetime.date object given a format string and a year, month, and day (only year is mandatory). Raise a 404 for an invalid date.
(
year, year_format, month="", month_format="", day="", day_format="", delim="__"
)
| 705 | |
| 706 | |
| 707 | def _date_from_string( |
| 708 | year, year_format, month="", month_format="", day="", day_format="", delim="__" |
| 709 | ): |
| 710 | """ |
| 711 | Get a datetime.date object given a format string and a year, month, and day |
| 712 | (only year is mandatory). Raise a 404 for an invalid date. |
| 713 | """ |
| 714 | format = year_format + delim + month_format + delim + day_format |
| 715 | datestr = str(year) + delim + str(month) + delim + str(day) |
| 716 | try: |
| 717 | return datetime.datetime.strptime(datestr, format).date() |
| 718 | except ValueError: |
| 719 | raise Http404( |
| 720 | _("Invalid date string “%(datestr)s” given format “%(format)s”") |
| 721 | % { |
| 722 | "datestr": datestr, |
| 723 | "format": format, |
| 724 | } |
| 725 | ) |
| 726 | |
| 727 | |
| 728 | def _get_next_prev(generic_view, date, is_previous, period): |
no test coverage detected