// Use SongKick's fucked up DateTime field, which is NOT GMT time but rather the local concert time followed by a UTC OFFSET value.
$datetime = $fullShowDetail->start["datetime"];
// Fail out if there isn't a show time at all.
if ("" == $datetime)
{
if ($debugprints==true) { echo("No datetime found in show information. Fill out your event times! Failing out of program.<br>"); }
die(" ");
}
// Obtain the timezone offset number out of the datetime string.
// Datetime string will resemble this, with the offset baked in at the end (always 4 digits, always with a + or -, even if the number is 0000):
// 2016-11-05T16:00:00-0400
// TODO: Find out if there is a PHP one-liner that does all this crap below without me having to do the bullshit parsing.
// I tried to find one but they all gave me the local server's timezone offset rather than the offset baked into the sting.
$timezoneOffsetString = substr($datetime, -5);
// (Last 5 characters of string are the sign and the time offset in HHMM format such as -0400 or +1200 or +0000)
// Make sure we actually got 5 characters
if ( 5 != strlen($timezoneOffsetString) )
{
if ($debugprints==true) { echo("Problem parsing timezone offset out of DateTime string. Length of string was not 5. Failing out of program.<br>"); }
die(" ");
}
// Get the sign character of the offset and validate it.
$timezoneOffsetSign = substr($timezoneOffsetString, 0, 1);
if ($timezoneOffsetSign != "-" and $timezoneOffsetSign != "+")
{
if ($debugprints==true) { echo("Problem parsing timezone offset out of DateTime string. Couldn't find plus or minus sign. Failing out of program.<br>"); }
die(" ");
}
//Validate each of the digits to make sure it's the kind of string we want (last 4 characters of the offset string must all be digits)
if (false==ctype_digit(substr($timezoneOffsetString, -4)))
{
if ($debugprints==true) { echo("Problem parsing timezone offset out of DateTime string. Offset string was not all digits. Failing out of program.<br>"); }
die(" ");
}
// Now we know for sure we have a string such as "-0400" or "+1200" or "-0130" or "+0000" and we need to convert it into SECONDS.
$timezoneOffsetSeconds = 0; // start with 0
$timezoneOffsetSeconds += (int)substr($timezoneOffsetString, 1, 2) * 60 * 60; // Hours is digit pos 1,2 times 60 minutes times 60 seconds.
$timezoneOffsetSeconds += (int)substr($timezoneOffsetString, 3, 2) * 60 ; // minutes is digit pos 3,4 times times 60 seconds.
// Now if the sign was positive then flip the seconds to negative.
// For instance an offset of -0400 means that we need to ADD 4 hours to our time to get back to a GMT number
// whereas with an offset of +0400 means that we need to SUBTRACT 4 hours to our time to get back to a GMT number
if ($timezoneOffsetSign == "+") { $timezoneOffsetSeconds = 0 - $timezoneOffsetSeconds; }