= 6) { $stamp = sprintf( "%04d-%02d-%02d %02d:%02d:%02d", $parts[0], $parts[1], $parts[2], $parts[3], $parts[4], $parts[5] ); } else { // fallback: use filemtime $stamp = date("Y-m-d H:i:s", filemtime($full)); } $iCreated = strtotime($stamp); $age = $Now - $iCreated; $days = floor($age / 86400); // Human-readable age $when = humanReadableAge($age, $days); // --------------------------------------------------------- // Build time array (single date() calls) // --------------------------------------------------------- $aTime = [ "age" => $age, "weekday" => date("l", $iCreated), "wkday" => date("D", $iCreated), "mday" => date("j", $iCreated), "mdayth" => date("j", $iCreated) . "" . date("S", $iCreated) . "", "mday_0" => date("d", $iCreated), "month" => date("F", $iCreated), "mon" => date("M", $iCreated), "mnum" => date("n", $iCreated), "mnum_0" => date("m", $iCreated), "year" => date("Y", $iCreated), "yr" => date("y", $iCreated), "hour_12" => date("g", $iCreated), "hour_12_0" => date("h", $iCreated), "am_pm" => date("a", $iCreated), "AM_PM" => date("A", $iCreated), "hour_24" => date("G", $iCreated), "hour_24_0" => date("H", $iCreated), "min" => date("i", $iCreated), "sec" => date("s", $iCreated), "days" => $days, "when" => $when ]; // Time-of-day classification $hour = date("G", $iCreated); $aTime["timeofday"] = ($hour >= 17 ? "evening" : ($hour >= 12 ? "afternoon" : "morning")); $aTime["ampm"] = ($hour >= 12 ? "PM" : "AM"); // --------------------------------------------------------- // Final return row // --------------------------------------------------------- $aReturn[] = array_merge([ "base" => $base, "ext" => $ext, "size" => FormatSize(filesize($full)), "contents" => file_get_contents($full) ], $aTime); } return $aReturn; } function humanReadableAge($age, $days) { if ($days >= 3650) return "a decade or more"; if ($days >= 712) return floor($days / 365) . " years"; if ($days >= 365) return "a year"; $monthMap = [ 330 => "11 months", 300 => "10 months", 270 => "9 months", 240 => "8 months", 210 => "7 months", 180 => "6 months", 150 => "5 months", 120 => "4 months", 90 => "3 months", 60 => "2 months", 30 => "a month" ]; foreach ($monthMap as $limit => $label) { if ($days >= $limit) return $label; } if ($days >= 21) return "3 weeks"; if ($days >= 14) return "2 weeks"; if ($days >= 7) return "a week"; if ($days >= 2) return "$days days"; if ($days == 1) return "a day"; $hours = floor($age / 3600); if ($hours == 0) return round($age / 60) . " minute(s)"; if ($hours == 1) return "1 hour"; return "$hours hours"; } function FormatSize($bytes) { if ($bytes < 1024) return $bytes . "b"; if ($bytes < 1048576) return round($bytes / 1024, 1) . "kb"; return round($bytes / 1048576, 1) . "mb"; } ?>