History Stats: ValueError: day is out of range for month

Hello Friends, I am new here, and I could not find the answer elsewhere.
So basically, i have a bunch of HIstory Stats sensors to track the “on” state of an entity.
It has worked wonderfully for 2 months, no errors. No I am getting an error that I cant seem to find what the issue is. The sensor in question:

- platform: history_stats
  name: Thermoflux Total Time On February
  entity_id: switch.thermoflux
  state: "on"
  type: time
  start: "{{ now().replace(year=(now().year)).replace(month=2).replace(day=1).replace(hour=0).replace(minute=0).replace(second=0) }}"
  end: "{{ now().replace(year=(now().year)).replace(month=2).replace(day=28).replace(hour=23).replace(minute=59).replace(second=59) }}"
  scan_interval: 21600

This particular sensor gives me the following error:

Error parsing template for field start
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 398, in async_render
    render_result = _render_with_context(self.template, compiled, **kwargs)
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 1698, in _render_with_context
    return template.render(**kwargs)
  File "/usr/local/lib/python3.9/site-packages/jinja2/environment.py", line 1304, in render
  File "/usr/local/lib/python3.9/site-packages/jinja2/environment.py", line 925, in handle_exception
    raise rewrite_traceback_stack(source=source)
  File "<template>", line 1, in top-level template code
  File "/usr/local/lib/python3.9/site-packages/jinja2/sandbox.py", line 393, in call
    return __context.call(__obj, *args, **kwargs)
ValueError: day is out of range for month

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/history_stats/sensor.py", line 273, in update_period
    start_rendered = self._start.async_render()
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 400, in async_render
    raise TemplateError(err) from err
homeassistant.exceptions.TemplateError: ValueError: day is out of range for month

What is weird is, i have the SAME EXACT sensors for other months, and only February gives me this error?
What gives? Is this a leap year bug or something? Any help would be appreciated.
P.S. The sensor worked for 2 months before without issues or errors.

Replace the day first.
When you replace the month first, jinja tries to render 30th Feb (as of today) as an intermediary result, so that fails.

{{ now().replace(day=28).replace(month=2).replace(hour=23).replace(minute=59).replace(second=59) }}

.replace(year=(now().year)) is unnecessary, btw. It does nothing.

Thanks, that works!
But now I realise, that for example

  start: "{{ now().replace(year=(now().year)).replace(day=1).replace(month=12).replace(hour=0).replace(minute=0).replace(second=0) }}"
  end: "{{ now().replace(year=(now().year)).replace(day=31).replace(month=12).replace(hour=23).replace(minute=59).replace(second=59) }}"

Does not work, as like you said, it parses an intermediary result based on the current days in this month. Am i understanding it correctly? For example, from tommorow this template will give no errors.

How would you properly format these sensors going into 2022 even? Specifically Oct 2021 - May 2022.

Thanks you helping me

A generic way would be

{% set dt_start = now().replace(year=(now().year)).replace(day=1).replace(month=12).replace(hour=0).replace(minute=0).replace(second=0) %}
start: "{{ dt_start }}"
end: "{{ (dt_start + timedelta(days=32)).replace(day=1).replace(month=(dt_start.month % 12)+1) }}"

Which gives

start: "2021-12-01 00:00:00.009836+01:00"
end: "2022-01-01 00:00:00.009836+01:00"