Optimize function get_last_weekday