I'm trying to set up a past events archive. Followed the guide provided by PT: craft cms guide to set up an archive.
The only difference is that I use a custom date field (dateAndTime) and not postDate. The route leads to the correct template.
The issue
When it loads the archives/agenda/2018 template (f. ex.), it displays all 2018 events (grouped by month) but also all 2019 events that where entered in Craft in 2018. This under the correct month, but obviously the wrong year. When it load the 2019 template, only the 2019 events that where entered in 2019 show up. I can't figure out where the code is wrong.
Route
url: archives/agenda/year (token) template: _sections/archives/agenda/index
Nav
{% set firstEntryEver = craft.entries.section('agenda').orderBy('dateAndTime asc').one() %}
<ul>
{% for year in now|date('Y') .. firstEntryEver.dateAndTime|date('Y') %}
<li><a href="archives/agenda/{{ year }}">{{ year }}</a></li>
{% endfor %}
</ul>
Index
<h1>{{ year }}</h1>
{% set entriesInYear = craft.entries.section('agenda').limit(null).after(year).before(year+1).all() %}
{% for month, entries in entriesInYear | group("dateAndTime|date('F')") %}
<h2>{{ month }}</h2>
<ul>
{% for entry in entries %}
<li>{{ entry.getLink() }}</li>
{% endfor %}
</ul>
{% endfor %}