Weird sorting bug

So, I have a list of events where some events are not sorted in ascending order depending on the date for some reason. Can anybody explain why?

This is the blueprint:

termine:
  type: pages
  create: termin
  empty: Eintrag hinzufügen
  layout: table
  image: false
  text: false
  columns:
    beginn_datum:
      label: Datum
      value: "{{ page.beginn_datum.toDate('d.m.Y') }}"
      mobile: true
    title:
      label: Veranstaltung
      type: html
      mobile: true
      value: '<span class="k-url-field-preview" data-link="{{ page.panel.url }}" style="padding: 0"><a class="k-link" href="{{ page.panel.url }}">{{ page.title }}</a><span>'
      width: 2/3
  sortBy: beginn_datum asc

this is the relevant template code:

<?php
	$termine = $page->children()->filter(function($item) {
		return $item->beginn_datum()->toDate() >= time();
	});
	if($termine):
?>
	<?php foreach($termine as $termin): ?>
		…
		…
	<?php endforeach; ?>
<?php endif; ?>

For some reason, events where no start time has been specified are printed before events with start time, even if the start date is after those. For example, an event beginning on 2024-05-15 at 16:00 hours is printed after an event beginning on 2024-06-01 without start time (or rather, the event without start time is printed before all events with start time).
They are in the right order in the panel. This seems to be an issue with the filter but I can’t figure out what. Please help! :frowning:

Oh, I figured it out. :man_facepalming: I’ve set the individual pages in the blueprint to prepend the start date and start time as number (num: '{{ page.beginn_datum.toDate("Ymd") }}{{ page.beginn_zeit.toDate("Hi") }}'), sorting them by date and start time. If the time isn’t entered, it will just not be prepended which results in a smaller number than pages with time, so they come first in the file system.

I now need to sort the pages explicitly only by the value of the start date field after filtering them in the template:

$termine = $page->children()->filter(function($item) {
	return $item->beginn_datum()->toDate() >= time();
})->sortBy('beginn_datum', 'asc');