Skip to content

Instantly share code, notes, and snippets.

@fwolf
Created March 5, 2015 16:14
Show Gist options
  • Save fwolf/94c10f9659c568eb4d64 to your computer and use it in GitHub Desktop.
Save fwolf/94c10f9659c568eb4d64 to your computer and use it in GitHub Desktop.
Compute if trim timestamp to start from not 1970, the max year same length base 36 zzz... can present to.
<?php
// Compute if trim timestamp to start from not 1970, the max year same length
// base 36 zzz... can present to.
$startYear = 2000;
$currentYear = date('Y');
$currentTimestamp = time();
for ($year = $startYear; $year <= $currentYear; $year ++) {
$startDate = "$year-01-01";
echo "Start date: " . $startDate;
// Compute relative timestamp
$startDateTimestamp = strtotime($startDate);
$timestamp = $currentTimestamp - $startDateTimestamp;
$encoded = base_convert($timestamp, 10, 36);
$length = strlen($encoded);
echo ", encoded: $encoded, $length bytes";
// Compute max relative date by this length
$maxTimestamp = $startDateTimestamp +
base_convert(str_repeat('z', $length), 36, 10);
$maxDate = date('Y-m-d H:i:s', $maxTimestamp);
echo ", max to $maxDate";
echo PHP_EOL;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment