Skip to content

Instantly share code, notes, and snippets.

@rossriley
Created July 10, 2016 19:11
Show Gist options
  • Save rossriley/59d943fe9bd25ee57c8652dc58ba7232 to your computer and use it in GitHub Desktop.
Save rossriley/59d943fe9bd25ee57c8652dc58ba7232 to your computer and use it in GitHub Desktop.
<?php
// Assuming you have a repeater field named `performances` and within each set there's a field named performancetime which is a datetime.
// The example is in PHP code, if you want to use it in Twig then you'll need to put this code in a method and use a Twig Filter to point
// to the method
$iterator = $record['performances']->getIterator();
$iterator->uasort(function ($first, $second) {
if ($first === $second) {
return 0;
}
return (float) $first->get('performancetime')->format("U.u") < (float) $second->get('performancetime')->format("U.u") ? -1 : 1;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment