Returns the most recent date, no later than orig_date, which is on week_day week_day: 0==Sunday, 1==Monday, ...
| 79 | // Returns the most recent date, no later than orig_date, which is on week_day |
| 80 | // week_day: 0==Sunday, 1==Monday, ... |
| 81 | date GoBackToWeekday(const date& orig_date, int week_day) { |
| 82 | int current_week_day = orig_date.day_of_week(); |
| 83 | int diff = current_week_day - week_day; |
| 84 | if (diff == 0) return orig_date; |
| 85 | if (diff > 0) { |
| 86 | // ex. Weds(3) shifts to Tues(2), so we go back 1 day |
| 87 | return orig_date - date_duration(diff); |
| 88 | } |
| 89 | // ex. Tues(2) shifts to Weds(3), so we go back 6 days |
| 90 | DCHECK_LT(diff, 0); |
| 91 | return orig_date - date_duration(7 + diff); |
| 92 | } |
| 93 | |
| 94 | // Maps the user facing name of a unit to a TruncUnit used by DateTrunc function |
| 95 | // Returns the TruncUnit for the given string |