Reproduces on master.

```
SELECT toDateTime64('2021-03-22', 3, 'Asia/Tehran')

Query id: 26f7c373-f473-4209-8976-6ada79a8627f

┌─toDateTime64('2021-03-22', 3, 'Asia/Tehran')─┐
│                      2157-04-28 06:28:16.000 │
└──────────────────────────────────────────────┘
```
{
        UInt8 week_format = (mode & 7);
        if (!(week_format & static_cast<UInt8>(WeekModeFlag::MONDAY_FIRST)))
            week_format ^= static_cast<UInt8>(WeekModeFlag::FIRST_WEEKDAY);
        return week_format;
    }
    /** Calculate weekday from d.
      * Returns 0 for monday, 1 for tuesday...
      */
    template <typename DateOrTime>
    inline unsigned calc_weekday(DateOrTime v, bool sunday_first_day_of_week) const
    {
        const LUTIndex i = toLUTIndex(v);
        if (!sunday_first_day_of_week)
            return toDayOfWeek(i) - 1;
        else
            return toDayOfWeek(i + 1) - 1;
    }
    
    inline unsigned calc_days_in_year(Int32 year) const