Calculate the Julian day based on the year, week of the year, and day of the week, with week_start_day representing whether the week of the year assumes the week starts on Sunday or Monday (6 or 0).
(year, week_of_year, day_of_week, week_starts_Mon)
| 493 | _regex_cache = {} |
| 494 | |
| 495 | def _calc_julian_from_U_or_W(year, week_of_year, day_of_week, week_starts_Mon): |
| 496 | """Calculate the Julian day based on the year, week of the year, and day of |
| 497 | the week, with week_start_day representing whether the week of the year |
| 498 | assumes the week starts on Sunday or Monday (6 or 0).""" |
| 499 | first_weekday = datetime_date(year, 1, 1).weekday() |
| 500 | # If we are dealing with the %U directive (week starts on Sunday), it's |
| 501 | # easier to just shift the view to Sunday being the first day of the |
| 502 | # week. |
| 503 | if not week_starts_Mon: |
| 504 | first_weekday = (first_weekday + 1) % 7 |
| 505 | day_of_week = (day_of_week + 1) % 7 |
| 506 | # Need to watch out for a week 0 (when the first day of the year is not |
| 507 | # the same as that specified by %U or %W). |
| 508 | week_0_length = (7 - first_weekday) % 7 |
| 509 | if week_of_year == 0: |
| 510 | return 1 + day_of_week - first_weekday |
| 511 | else: |
| 512 | days_to_week = week_0_length + (7 * (week_of_year - 1)) |
| 513 | return 1 + days_to_week + day_of_week |
| 514 | |
| 515 | |
| 516 | def _strptime(data_string, format="%a %b %d %H:%M:%S %Y"): |