forked from mirror/pixelfed
Add snowflake id service
This commit is contained in:
parent
a443694dc0
commit
c0076ab035
1 changed files with 18 additions and 0 deletions
18
app/Services/SnowflakeService.php
Normal file
18
app/Services/SnowflakeService.php
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Services;
|
||||||
|
|
||||||
|
use Illuminate\Support\Carbon;
|
||||||
|
|
||||||
|
class SnowflakeService {
|
||||||
|
|
||||||
|
public static function byDate(Carbon $ts = null)
|
||||||
|
{
|
||||||
|
$ts = $ts ? now()->parse($ts)->timestamp : microtime(true);
|
||||||
|
return ((round($ts * 1000) - 1549756800000) << 22)
|
||||||
|
| (1 << 17)
|
||||||
|
| (1 << 12)
|
||||||
|
| 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in a new issue