def to_timestamp(dt, timestamp):
  """Convert datetime to google.protobuf.Timestamp.

  Args:
    dt: a timezone naive datetime.
    timestamp: a google.protobuf.Timestamp to populate.

  Raises:
    TypeError: if a timezone aware datetime was provided.
  """
  if dt.tzinfo:
    # this is an "aware" datetime with an explicit timezone. Throw an error.
    raise TypeError('Cannot store a timezone aware datetime. '
                    'Convert to UTC and store the naive datetime.')
  timestamp.seconds = calendar.timegm(dt.timetuple())
  timestamp.nanos = dt.microsecond * _NANOS_PER_MICRO
Convert datetime to google.protobuf.Timestamp.

  Args:
    dt: a timezone naive datetime.
    timestamp: a google.protobuf.Timestamp to populate.

  Raises:
    TypeError: if a timezone aware datetime was provided.