Skip to content

Instantly share code, notes, and snippets.

@mlebkowski
Created September 17, 2014 14:26
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save mlebkowski/a67ba0a901a5fe919f4c to your computer and use it in GitHub Desktop.
combined ids
<?php
function compositeId($calendarId, \DateTime $start) {
static $startOfTime = 1410963347;
$time = ($start->getTimestamp() - $startOfTime) / 60 / 5;
if ($time & 0xFFFF0000) {
throw new RuntimeException(sprintf('We have ran out of time: %s!', $start->format('Y-m-d H:i:s')));
}
if ($calendarId & 0xFFFF0000) {
throw new RuntimeException(sprintf('We are too successful (calendarId: %d)', $calendarId));
}
return $time + ($calendar << 16);
}
function reverseCompositeId($compositeId) {
static $startOfTime = 1410963347;
return [
$compositeId >> 16,
DateTime::createFromFormat('U', ($compositeId & 0xFFFF) * 60 * 5 + $startOfTime),
];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment