code: public function onBeforePublish() {
  		if ($this->dbObject('PublishDate')->InPast() && !$this->isPublished()) {
  			$this->setCastedField("PublishDate", time());
  			$this->write();
  		}
  	}
docs: Update the PublishDate to now, if being published for the first time, and the date hasn't been set to the future.