| @@ 131-148 (lines=18) @@ | ||
| 128 | /** |
|
| 129 | * Set start time (millisecond). |
|
| 130 | */ |
|
| 131 | public function setStartTimeStamp(int $startTime) |
|
| 132 | { |
|
| 133 | $missTime = $this->getCurrentMicrotime() - $startTime; |
|
| 134 | ||
| 135 | if ($missTime < 0) { |
|
| 136 | throw new \Exception('The start time cannot be greater than the current time'); |
|
| 137 | } |
|
| 138 | ||
| 139 | $maxTimeDiff = -1 ^ (-1 << self::MAX_TIMESTAMP_LENGTH); |
|
| 140 | ||
| 141 | if ($missTime > $maxTimeDiff) { |
|
| 142 | throw new \Exception(sprintf('The current microtime - starttime is not allowed to exceed -1 ^ (-1 << %d), You can reset the start time to fix this', self::MAX_TIMESTAMP_LENGTH)); |
|
| 143 | } |
|
| 144 | ||
| 145 | $this->startTime = $startTime; |
|
| 146 | ||
| 147 | return $this; |
|
| 148 | } |
|
| 149 | ||
| 150 | /** |
|
| 151 | * Get start timestamp (millisecond), If not set default to 2019-08-08 08:08:08. |
|
| @@ 78-93 (lines=16) @@ | ||
| 75 | /** |
|
| 76 | * Set start time (millisecond). |
|
| 77 | */ |
|
| 78 | public function setStartTimeStamp(int $startTime) |
|
| 79 | { |
|
| 80 | $elapsedTime = floor(($this->getCurrentMicrotime() - $startTime) / 10) | 0; |
|
| 81 | if ($elapsedTime < 0) { |
|
| 82 | throw new \Exception('The start time cannot be greater than the current time'); |
|
| 83 | } |
|
| 84 | ||
| 85 | $maxTimeDiff = -1 ^ (-1 << self::MAX_TIMESTAMP_LENGTH); |
|
| 86 | if ($elapsedTime > $maxTimeDiff) { |
|
| 87 | throw new \Exception('Exceeding the maximum life cycle of the algorithm'); |
|
| 88 | } |
|
| 89 | ||
| 90 | $this->startTime = $startTime; |
|
| 91 | ||
| 92 | return $this; |
|
| 93 | } |
|
| 94 | ||
| 95 | /** |
|
| 96 | * Parse snowflake id. |
|