Skip to content

Instantly share code, notes, and snippets.

@eoghanobrien
Created August 3, 2013 10:09
Show Gist options
  • Select an option

  • Save eoghanobrien/6145964 to your computer and use it in GitHub Desktop.

Select an option

Save eoghanobrien/6145964 to your computer and use it in GitHub Desktop.
ExpressionEngine's Localize class currently lacks a method to modify a timestamp while keeping the member's localization settings in-tact. Adding this method around line 90 to to the file /system/expressionengine/libraries/Localize.php fixes that issue. Usage: $tomorrow = ee()->localize->modify_timestamp('+1 day');
/**
* Given a modification like +1 day or -2 weeks and a Unix timestamp,
* returns the modified timestamp in the specified timezone or member's
* current timezone.
*
* @param string Modificiation like +1 day
* @param int Unix timestamp
* @param bool Return date localized or not
* @return string Formatted date
*/
public function modify_timestamp($modify, $timestamp = NULL, $localize = TRUE)
{
if ( ! ($dt = $this->_datetime($timestamp, $localize)))
{
return FALSE;
}
return $dt->modify($modify)->format('U');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment