code: def _sorted_ranges(
      exp_ranges: Iterable["ExpRange"],
  ) -> List["ExpRange"]:
      """Return list of ExpRange sorted by (timestamp, rev)."""
  
      def _head_timestamp(
          exp_range: "ExpRange",
      ) -> Tuple[datetime, str]:
          head_exp = first(exp_range.revs)
          if head_exp and head_exp.data and head_exp.data.timestamp:
              return head_exp.data.timestamp, head_exp.rev
  
          return datetime.fromtimestamp(0), ""
  
      return sorted(exp_ranges, key=_head_timestamp, reverse=True)
  
imports: import itertools
  import os
  from dataclasses import fields
  from datetime import datetime
  from typing import TYPE_CHECKING, Collection, Dict, Iterable, Iterator, List, Optional, Tuple, Union
  from funcy import first
  from scmrepo.exceptions import SCMError
  from dvc.log import logger
  from dvc.scm import Git, SCMError, iter_revs
  from .exceptions import InvalidExpRefError
  from .refs import EXEC_BRANCH, ExpRefInfo
  from .serialize import ExpRange, ExpState, SerializableError, SerializableExp
  from .utils import describe
label_desc: Use image node_id 11 for calling a global function with example usage: _sorted_ranges(exp_ranges) and returns: sorted, datetime,  str, head_exp,  head_exp