from datetime import datetime
import time


def timestamp(dt=None):
  """
  Return a timestamp in the format of hex(megasecconds)-hex(seconds)-hex(microseconds)

  The timestamp should be monotonically increasing and hence usable as a uuid
  """
  if dt is None:
    dt = datetime.utcnow()
  mega, seconds = map(int, divmod(time.mktime(dt.timetuple()), 10**6))
  return "{:x}-{:x}-{:x}".format(mega, seconds, dt.microsecond)