strptime for windows

by Joe Brewer on August 22, 2010

I was searching for a windows implementation for the php function strptime, however the best help/advice that I could find was read the source code and write it yourself. Here is my implentation that I knocked up with date_parse_from_format so you can use it on version of php less than 5.3.0

if (!function_exists('date_parse_from_format')) {
	function date_parse_from_format($format, $date) {
		$returnArray = array('hour' => 0, 'minute' => 0, 'second' => 0,
							'month' => 0, 'day' => 0, 'year' => 0);

		$dateArray = array();

		// array of valid date codes with keys for the return array as the values
		$validDateTimeCode = array('Y' => 'year', 'y' => 'year',
									'm' => 'month', 'n' => 'month',
									'd' => 'day', 'j' => 'day',
									'H' => 'hour', 'G' => 'hour',
									'i' => 'minute', 's' => 'second');

		/* create an array of valid keys for the return array
		 * in the order that they appear in $format
		 */
		for ($i = 0 ; $i <= strlen($format) - 1 ; $i++) {
			$char = substr($format, $i, 1);

			if (array_key_exists($char, $validDateTimeCode)) {
				$dateArray[$validDateTimeCode[$char]] = '';
			}
		}

		// create array of reg ex things for each date part
		$regExArray = array('.' => '\.', // escape the period

							// parse d first so we dont mangle the reg ex
							// day
							'd' => '(\d{2})',

							// year
							'Y' => '(\d{4})',
							'y' => '(\d{2})',

							// month
							'm' => '(\d{2})',
							'n' => '(\d{1,2})',

							// day
							'j' => '(\d{1,2})',

							// hour
							'H' => '(\d{2})',
							'G' => '(\d{1,2})',

							// minutes
							'i' => '(\d{2})',

							// seconds
							's' => '(\d{2})');

		// create a full reg ex string to parse the date with
		$regEx = str_replace(array_keys($regExArray),
								array_values($regExArray),
								$format);

		// Parse the date
		preg_match("#$regEx#", $date, $matches);

		// some checks...
		if (!is_array($matches) ||
			$matches[0] != $date ||
			sizeof($dateArray) != (sizeof($matches) - 1)) {
			return $returnArray;
		}

		// an iterator for the $matches array
		$i = 1;

		foreach ($dateArray AS $key => $value) {
			$dateArray[$key] = $matches[$i++];

			if (array_key_exists($key, $returnArray)) {
				$returnArray[$key] = $dateArray[$key];
			}
		}

		return $returnArray;
	}
}

if (!function_exists('strptime')) {
	function strptime($format, $date) {
		$dateArray = array();

		$dateArray = date_parse_from_format($format, $date);

		if (is_array($dateArray)) {
			return mktime($dateArray['hour'],
							$dateArray['minute'],
							$dateArray['second'],
							$dateArray['month'],
							$dateArray['day'],
							$dateArray['year']);
		} else {
			return 0;
		}
	}
}

{ 0 comments }

Updates for Caffinated Content

by Joe Brewer on August 12, 2010

For those of you that use Caffinated Content you may be interested to heat that kansieo has decided to sell 19 copies of the source code to Caffinated Content - it was 20, but I've bought one.  Full details can be found here - In a nutshell kansieo is allowing 20 developers to take the source code, improve it, and update it.

What would you like to see in future releases ?  Here's a list of mine:

  • Cron jobs for adding posts - a set number per day.
  • Cron jobs setup to add posts to different categories from specific sources.
  • Support for more sites to collect content from - maybe use a plugin architechture to add new sites.
  • The ability to poll for content to be posted from a specific folder.  A file in xml format could allow for wordpress post fields such as post date, title, content etc could be used appropriately in each post.

{ 0 comments }

Domain Renewal Group

May 8, 2010

I keep on getting letters from the domain renewal group asking if I want to transfer domains to them, only for them to change more than twice as much as my current registrar. My latest letter is asking me to transfer one of my .net domains to them for the bargin price of £20 (yes, [...]

Read the full article →

Tracker progress – part 1

February 6, 2010

So now I can create campaigns for offers, landing pages, offer rotations and landing page rotations.  I’ve only really tested sending traffic directly to offers, but I’ve only got one real report (and that is still not 100% finished). Here is the report for anyone that is interested.

Read the full article →

Tracking cost data

January 17, 2010

Although the major three search engines have apis for their PPC engines, PPV engines do not.  This brings up the question of how to track the cost of each impression. To get accurate stats I could scrape the reports that are available in each of the engines, and I guess this would be the best [...]

Read the full article →