<?php
use DateTime;

function datetimeTimestampToString($timestamp) {
	$datetimeObject = new DateTime("@$timestamp"); // will supposedly have the timezone set to UTC.
	// The spec requires exactly 'GMT' without numeric offset, so we cannot use DateTime::RFC1123.
	$datetimeString = $datetimeObject->format("D, d M Y H:i:s") . " GMT";
	return $datetimeString;
}

function datetimeStringToTimestamp($datetimeString) {
	// Be tolerant and allow any RFC1123 formatted datetime string.
	$datetimeObject = DateTime::createFromFormat(DateTime::RFC1123, $datetimeString);
	$timestamp = $datetimeObject->getTimestamp();
	return $timestamp;
}