# File lib/uuidtools.rb, line 226
  def self.timestamp_create(timestamp=nil)
    # We need a lock here to prevent two threads from ever
    # getting the same timestamp.
    @@mutex.synchronize do
      # Always use GMT to generate UUIDs.
      if timestamp.nil?
        gmt_timestamp = Time.now.gmtime
      else
        gmt_timestamp = timestamp.gmtime
      end
      # Convert to 100 nanosecond blocks
      gmt_timestamp_100_nanoseconds = (gmt_timestamp.tv_sec * 10000000) +
        (gmt_timestamp.tv_usec * 10) + 0x01B21DD213814000
      mac_address = self.get_mac_address
      if mac_address == nil || mac_address == ""
        raise StandardError,
          "MAC address could not be autodetected.  " +
          "Set the MAC address manually."
      end
      nodes = mac_address.split(":").collect do |octet|
        octet.to_i(16)
      end
      node_id = 0
      for i in 0..5
        node_id += (nodes[i] << (40 - (i * 8)))
      end
      clock_sequence = @@last_clock_sequence
      if clock_sequence.nil?
        clock_sequence = self.convert_byte_string_to_int(self.random_128)
      end
      if @@last_node_id != nil && @@last_node_id != node_id
        # The node id has changed.  Change the clock id.
        clock_sequence = self.convert_byte_string_to_int(self.random_128)
      elsif @@last_timestamp != nil &&
          gmt_timestamp_100_nanoseconds <= @@last_timestamp
        clock_sequence = clock_sequence + 1
      end
      @@last_timestamp = gmt_timestamp_100_nanoseconds
      @@last_node_id = node_id
      @@last_clock_sequence = clock_sequence

      time_low = gmt_timestamp_100_nanoseconds & 0xFFFFFFFF
      time_mid = ((gmt_timestamp_100_nanoseconds >> 32) & 0xFFFF)
      time_hi_and_version = ((gmt_timestamp_100_nanoseconds >> 48) & 0x0FFF)
      time_hi_and_version |= (1 << 12)
      clock_seq_low = clock_sequence & 0xFF;
      clock_seq_hi_and_reserved = (clock_sequence & 0x3F00) >> 8
      clock_seq_hi_and_reserved |= 0x80
      
      return self.new(time_low, time_mid, time_hi_and_version,
        clock_seq_hi_and_reserved, clock_seq_low, nodes)
    end
  end