Skip to content

Instantly share code, notes, and snippets.

@josh7weaver
Created December 23, 2014 22:19
Show Gist options
  • Save josh7weaver/d69db8d52b0f72de445d to your computer and use it in GitHub Desktop.
Save josh7weaver/d69db8d52b0f72de445d to your computer and use it in GitHub Desktop.
Date Wrapper
class Date{
public $date;
public $timestamp;
private $format = "Y-m-d";
public function __construct($dateString)
{
$this->_setAttrForTimestamp( strtotime($dateString) );
}
public function add($amount, $increment)
{
$timestamp = strtotime("+$amount $increment", $this->timestamp);
$this->_setAttrForTimestamp( $timestamp );
}
public function subtract($amount, $increment)
{
$timestamp = strtotime("-$amount $increment", $this->timestamp);
$this->_setAttrForTimestamp( $timestamp );
}
// PRIVATE FUNCTIONS
private function _setAttrForTimestamp($timestamp)
{
$this->timestamp = $timestamp;
$this->date = date( $this->format , $timestamp);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment