| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154 |
- <?php
- /** @package verysimple::Util */
- /**
- * Static utility class for working with Dates
- *
- * @package verysimple::Util
- * @author Jason Hinkle
- * @copyright 1997-2011 VerySimple, Inc.
- * @license LGPL http://www.gnu.org/licenses/lgpl.html
- * @version 1.0
- */
- class VsDateUtil
- {
- /** @var int one day in milliseconds */
- static $ONE_DAY = 86400000;
-
- /** @var int one hour in milliseconds */
- static $ONE_HOUR = 3600000;
-
- /** @var int one minute in milliseconds */
- static $ONE_MINUTE = 6000;
-
- /** @var int one second in milliseconds */
- static $ONE_SECOND = 1000;
-
- /**
- * Return current date as string in the specified format
- * @param string $format
- */
- static function Today($format = "Y-m-d")
- {
- return self::Now($format);
- }
-
- /**
- * Returns the timestamp for the beginning of DST for specified year
- * @param int the 4-digit year (if not provide then the current year is used)
- */
- static function DstStartNorthAmerica($year = null)
- {
- if (!$year) $year = date('Y');
- return strtotime('03/01/' . $year . ' second sunday');
- }
-
- /**
- * Returns the timestamp for the end of DST for the specified year
- * @param int the 4-digit year (if not provide then the current year is used)
- */
- static function DstEndNorthAmerica($year = null)
- {
- if (!$year) $year = date('Y');
- return strtotime('11/01/' . $year . ' first sunday');
- }
-
- /**
- * Return true if the date is within the DST observation range for North America
- * @param int $timestamp (if not provided then the current server time will be used)
- */
- static function IsDstNorthAmerica($timestamp = null)
- {
- if (!$timestamp) $timestamp = time();
- return $timestamp > self::DstStartNorthAmerica() && $timestamp < self::DstEndNorthAmerica();
- }
-
- /**
- * Return current date/time as string in the specified format
- * @param string $format
- */
- static function Now($format = "Y-m-d H:i:s")
- {
- return date($format);
- }
-
- /**
- * Return yesterday's date as string in the specified format
- * @param string $format
- */
- static function Yesterday($format = "Y-m-d")
- {
- return self::DaysAgo(1,$format);
- }
- /**
- * Return tomorrow's date as string in the specified format
- * @param string $format
- */
- static function Tomorrow($format = "Y-m-d")
- {
- return self::DaysFromNow(1,$format);
- }
-
- /**
- * Return the date/time 24 hours ago as string in the specified format
- * @param string $format
- */
- static function TwentyFourHoursAgo($format = "Y-m-d H:i:s")
- {
- return self::HoursAgo(24,$format);
- }
- /**
- * Return the date/time 24 hours from now as string in the specified format
- * @param string $format
- */
- static function TwentyFourHoursFromNow($format = "Y-m-d H:i:s")
- {
- return self::HoursFromNow(24,$format);
- }
-
- /**
- * Return date as a string the specified number of days ago
- * @param int $days
- * @param string $format
- */
- static function DaysAgo($days, $format = "Y-m-d")
- {
- return date($format,strtotime(self::Now() . " - $days days"));
- }
-
- /**
- * Return date as a string the specified number of days from now
- * @param int $days
- * @param string $format
- */
- static function DaysFromNow($days, $format = "Y-m-d")
- {
- return date($format,strtotime(self::Now() . " + $days days"));
- }
- /**
- * Return date/time as a string the specified number of hours ago
- * @param int $hours
- * @param string $format
- */
- static function HoursAgo($hours, $format = "Y-m-d H:i:s")
- {
- return date($format,strtotime(self::Now() . " - $hours hours"));
- }
-
- /**
- * Return date/time as a string the specified number of hours from now
- * @param int $hours
- * @param string $format
- */
- static function HoursFromNow($hours, $format = "Y-m-d H:i:s")
- {
- return date($format,strtotime(self::Now() . " - $hours hours"));
- }
-
-
- }
- ?>
|