Location: PHPKode > projects > v-creator > v-creator_1.3-pre3/modules/date.php
<?php
	/*
	 * Copyright (c) 2003 gencon Ltd, all rights reserved.
	 *
	 * This file is part of v-creator.
	 *
   * v-creator is free software; you can redistribute it and/or modify
   * it under the terms of the GNU General Public License as published by
   * the Free Software Foundation; either version 2 of the License, or
   * (at your option) any later version.
	 *
   * v-creator is distributed in the hope that it will be useful,
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   * GNU General Public License for more details.
	 *
   * You should have received a copy of the GNU General Public License
   * along with this program; if not, write to the Free Software
   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
	 */

	require_once(VC_ROOT.'/classes/VCPage.php');

	/**
	 * @ingroup VCmodules
	 * @brief Class for processing dates and times.
	 *
	 * $Revision: 1.5 $  $Date: 2005-09-26 13:00:33 $
	 *
	 * @author Andrew 'Diddymus' Rolfe
	 *
	 * This module provides functionality for processing dates and times.
	 */
	class date {

		/**
		 * @brief Function to split a date into it's component parts.
		 *
		 * This function takes a timestamp and splits it into it's component parts.
		 * The parts can then be combined to represent any date or time format
		 * required. To make handling of multiple dates easier the VC_data values
		 * used can have an alternative prefix to 'date_' using the
		 * date_field_prefix. For example if it is specified as 'activate_date_'
		 * then 'activeate_date_date' will be split into 'activate_date_day',
		 * 'activate_date_month etc. The values returned in VC_data are:
		 *
		 * <dl>
		 *	<dt>date_day</dt>
		 *	<dd>The day of the month (1-31)</dd>
		 *	<dt>date_dayZero</dt>
		 *	<dd>The day of the month (01-31) with leading zeros</dd>
		 *	<dt>date_dayShort</dt>
		 *	<dd>The short name of the day. For example: Mon</dd>
		 *	<dt>date_dayLong</dt>
		 *	<dd>The long name of the day. For example: Monday</dd>
		 *	<dt>date_daySuffix</dt>
		 *	<dd>The numeric day suffix. For example: st, nd, th</dd>
		 *	<dt>date_dayOfWeek</dt>
		 *	<dd>The day in the week with Sunday being 0 upto 6 for Saturday</dd>
		 *	<dt>date_month</dt>
		 *	<dd>The month of the year (1-12)</dd>
		 *	<dt>date_monthZero</dt>
		 *	<dd>The month of the year (01-12) with leading zeros</dd>
		 *	<dt>date_monthShort</dt>
		 *	<dd>The short name of the month. For example: Jan</dd>
		 *	<dt>date_monthLong</dt>
		 *	<dd>The long name of the month. For example: January</dd>
		 *	<dt>date_year</dt>
		 *	<dd>The 4 digit year. For example: 2004</dd>
		 *	<dt>date_yearShort</dt>
		 *	<dd>The last 2 digits of the year. For example: 04</dd>
		 *	<dt>date_hours</dt>
		 *	<dd>The hour in 24 hour format</dd>
		 *	<dt>date_hoursZero</dt>
		 *	<dd>The hour in 24 hour format with leading zeros</dd>
		 *	<dt>date_hours12</dt>
		 *	<dd>The hour in 12 hour format</dd>
		 *	<dt>date_hours12Zero</dt>
		 *	<dd>The hour in 12 hour format with leading zeros</dd>
		 *	<dt>date_ampm</dt>
		 *	<dd>Ante meridiem and Post meridiem (am/pm) of the hour</dd>
		 *	<dt>date_minutes</dt>
		 *	<dd>The minutes</dd>
		 *	<dt>date_minutesZero</dt>
		 *	<dd>The minutes with leading zeros</dd>
		 *	<dt>date_seconds</dt>
		 *	<dd>The seconds</dd>
		 *	<dt>date_secondsZero</dt>
		 *	<dd>The seconds with leading zeros</dd>
		 *	<dt>date_timestamp</dt>
		 *	<dd>The number of seconds since January 1 1970 00:00:00 GMT</dd>
		 *	<dt>date_timezone</dt>
		 *	<dd>The timezone of the local machine (GMT, BST, EST, MDT...) </dd>
		 * </dl>
		 *
		 * The following values from VC_data will be used if available:
		 *
		 * <dl>
		 *	<dt>date_date</dt>
		 *	<dd>The timestamp to be formatted</dd>
		 *	<dt>date_field_prefix</dt>
		 *	<dd>The prefix to use instead of 'date_' for VC_data value names being
		 *			this name may be overridden using date_field_prefix.</dd>
		 * </dl>
		 *
		 * @static
		 */
		function split() {
			global $VC_data;

			$fieldPrefix = VCPage::getVC_data('date_field_prefix');
			if (!$fieldPrefix) $fieldPrefix = 'date_';

			$date = VCPage::getVC_data($fieldPrefix.'date');
			if (!$date) $date=time();

			$dateInfo = date('j d D l S n m M F Y y G H g h a i s U w T', $date);
			$dateInfo = explode(' ', $dateInfo);

			$VC_data[$fieldPrefix.'day'] 					= $dateInfo[0];
			$VC_data[$fieldPrefix.'dayZero'] 			= $dateInfo[1];
			$VC_data[$fieldPrefix.'dayShort'] 		= $dateInfo[2];
			$VC_data[$fieldPrefix.'dayLong'] 			= $dateInfo[3];
			$VC_data[$fieldPrefix.'daySuffix'] 		= $dateInfo[4];
			$VC_data[$fieldPrefix.'dayOfWeek'] 		= $dateInfo[19];
			$VC_data[$fieldPrefix.'month'] 				= $dateInfo[5];
			$VC_data[$fieldPrefix.'monthZero'] 		= $dateInfo[6];
			$VC_data[$fieldPrefix.'monthShort'] 	= $dateInfo[7];
			$VC_data[$fieldPrefix.'monthLong'] 		= $dateInfo[8];
			$VC_data[$fieldPrefix.'year'] 				= $dateInfo[9];
			$VC_data[$fieldPrefix.'yearShort'] 		= $dateInfo[10];
			$VC_data[$fieldPrefix.'hours'] 				= $dateInfo[11];
			$VC_data[$fieldPrefix.'hoursZero'] 		= $dateInfo[12];
			$VC_data[$fieldPrefix.'hours12'] 			= $dateInfo[13];
			$VC_data[$fieldPrefix.'hours12Zero'] 	= $dateInfo[14];
			$VC_data[$fieldPrefix.'ampm'] 				= $dateInfo[15];
			$VC_data[$fieldPrefix.'minutesZero'] 	= $dateInfo[16];
			$VC_data[$fieldPrefix.'secondsZero'] 	= $dateInfo[17];
			$VC_data[$fieldPrefix.'timestamp'] 		= $dateInfo[18];
			$VC_data[$fieldPrefix.'timezone'] 		= $dateInfo[19];

			$minutes = ltrim($dateInfo[16], '0');
			if ($minutes == '') $minutes = '0';
			$VC_data[$fieldPrefix.'minutes'] = $minutes;

			$seconds = ltrim($dateInfo[17], '0');
			if ($seconds == '') $seconds = '0';
			$VC_data[$fieldPrefix.'seconds'] = $seconds;

		}

		/**
		 * @brief Function to combine a date components into a timestamp.
		 *
		 * This function takes the components of a date and creates a timestamp
		 * from them. To make handling of multiple dates easier the VC_data values
		 * used can have an alternative prefix to 'date_' using the
		 * date_field_prefix. For example if it is specified as 'activate_date_'
		 * then 'activate_date_day', 'activate_date_month etc will be used and
		 * 'activate_date_timestamp' will be returned. The values returned in
		 * VC_data are:
		 *
		 * <dl>
		 *	<dt>date_timestamp</dt>
		 *	<dd>The number of seconds since January 1 1970 00:00:00 GMT.  Note that
		 *			this name may be overridden using date_field_prefix.</dd>
		 * </dl>
		 *
		 * The following values from VC_data will be used if available:
		 *
		 * <dl>
		 *	<dt>date_field_prefix</dt>
		 *	<dd>The prefix to use instead of 'date_' for VC_data value names being
		 *	read or set.</dd>
		 *	<dt>date_day</dt>
		 *	<dd>The day of the month (1-31)</dd>
		 *	<dt>date_month</dt>
		 *	<dd>The month of the year (1-12)</dd>
		 *	<dt>date_year</dt>
		 *	<dd>The 4 digit year</dd>
		 *	<dt>date_hours</dt>
		 *	<dd>The hours in 24 hour format</dd>
		 *	<dt>date_minutes</dt>
		 *	<dd>The minutes of the hour</dd>
		 *	<dt>date_seconds</dt>
		 *	<dd>The seconds of the minute</dd>
		 * </dl>
		 *
		 * @static
		 */
		function combine() {
			global $VC_data;

			$fieldPrefix = VCPage::getVC_data('date_field_prefix');
			if (!$fieldPrefix) $fieldPrefix = 'date_';

			$day 			= VCPage::getVC_data($fieldPrefix.'day');
			$month 		= VCPage::getVC_data($fieldPrefix.'month');
			$year 		= VCPage::getVC_data($fieldPrefix.'year');
			$hours 		= VCPage::getVC_data($fieldPrefix.'hours');
			$minutes 	= VCPage::getVC_data($fieldPrefix.'minutes');
			$seconds 	= VCPage::getVC_data($fieldPrefix.'seconds');
		
			$VC_data[$fieldPrefix.'timestamp'] = mktime($hours, $minutes, $seconds,
																	 $month, $day, $year);
		}

	}
?>
Return current item: v-creator