Created
February 12, 2024 02:24
-
-
Save rudiedirkx/7c14a7088819338172dca6644b7811dc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$json1 = <<<JSON | |
... | |
JSON; | |
var_dump(strlen($json1)); | |
$data1 = json_decode($json1, true); | |
// print_r($data1); | |
$data2 = [ | |
'start' => date2int(key($data1)), | |
'days' => [], | |
]; | |
foreach ($data1 as $date => $info) { | |
$data2['days'][] = $info; | |
} | |
var_dump(strlen(json_encode($data2))); | |
echo "first day = " . int2date($data2['start']) . "\n"; | |
echo "last day = " . int2date($data2['start'] + count($data2['days']) - 1) . "\n"; | |
print_r($data2); | |
// ==== // | |
function date2int(string $date) : int { | |
$components = array_map(intval(...), explode('-', $date)); | |
return juliantojd($components[1], $components[2], $components[0]); | |
} | |
function int2date(int $date) : string { | |
return date('Y-m-d', strtotime(jdtojulian($date))); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment