Created
December 23, 2014 22:19
-
-
Save josh7weaver/d69db8d52b0f72de445d to your computer and use it in GitHub Desktop.
Date Wrapper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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