Eric Barnes avatar Eric Barnes committed 46baa1a

Added unit tests for date helper.

Comments (0)

Files changed (3)

system/helpers/date_helper.php

 	function standard_date($fmt = 'DATE_RFC822', $time = '')
 	{
 		$formats = array(
-						'DATE_ATOM'		=>	'%Y-%m-%dT%H:%i:%s%Q',
+						'DATE_ATOM'		=>	'%Y-%m-%dT%H:%i:%s%O',
 						'DATE_COOKIE'	=>	'%l, %d-%M-%y %H:%i:%s UTC',
-						'DATE_ISO8601'	=>	'%Y-%m-%dT%H:%i:%s%Q',
+						'DATE_ISO8601'	=>	'%Y-%m-%dT%H:%i:%s%O',
 						'DATE_RFC822'	=>	'%D, %d %M %y %H:%i:%s %O',
-						'DATE_RFC850'	=>	'%l, %d-%M-%y %H:%m:%i UTC',
+						'DATE_RFC850'	=>	'%l, %d-%M-%y %H:%i:%s UTC',
 						'DATE_RFC1036'	=>	'%D, %d %M %y %H:%i:%s %O',
 						'DATE_RFC1123'	=>	'%D, %d %M %Y %H:%i:%s %O',
+						'DATE_RFC2822'	=>	'%D, %d %M %Y %H:%i:%s %O',
 						'DATE_RSS'		=>	'%D, %d %M %Y %H:%i:%s %O',
-						'DATE_W3C'		=>	'%Y-%m-%dT%H:%i:%s%Q'
+						'DATE_W3C'		=>	'%Y-%m-%dT%H:%i:%s%O'
 						);
 
 		if ( ! isset($formats[$fmt]))

tests/codeigniter/helpers/date_helper_test.php

+<?php
+require_once BASEPATH.'helpers/date_helper.php';
+
+class Date_helper_test extends CI_TestCase
+{
+	// ------------------------------------------------------------------------
+
+	public function test_now()
+	{
+		$this->markTestIncomplete('not implemented yet');
+	}
+
+	// ------------------------------------------------------------------------
+
+	public function test_mdate()
+	{
+		$time = time();
+		$expected = date("Y-m-d - h:i a", $time);
+		$test = mdate("%Y-%m-%d - %h:%i %a", $time);
+		$this->assertEquals($expected, $test);
+	}
+
+	// ------------------------------------------------------------------------
+
+	public function test_standard_date_rfc822()
+	{
+		$time = time();
+		$format = 'DATE_RFC822';
+		$expected = date("D, d F y G:i:s O", $time);
+		$this->assertEquals($expected, standard_date($format, $time));
+	}
+
+	// ------------------------------------------------------------------------
+
+	public function test_standard_date_atom()
+	{
+		$time = time();
+		$format = 'DATE_ATOM';
+		$expected = date("Y-m-d\TH:i:sO", $time);
+		$this->assertEquals($expected, standard_date($format, $time));
+	}
+
+	// ------------------------------------------------------------------------
+
+	public function test_standard_date_cookie()
+	{
+		$time = time();
+		$format = 'DATE_COOKIE';
+		$expected = date("l, d-M-y H:i:s \U\T\C", $time);
+		$this->assertEquals($expected, standard_date($format, $time));
+	}
+
+	// ------------------------------------------------------------------------
+
+	public function test_standard_date_iso8601()
+	{
+		$time = time();
+		$format = 'DATE_ISO8601';
+		$expected = date("Y-m-d\TH:i:sO", $time);
+		$this->assertEquals($expected, standard_date($format, $time));
+	}
+
+	// ------------------------------------------------------------------------
+
+	public function test_standard_date_rfc850()
+	{
+		$time = time();
+		$format = 'DATE_RFC850';
+		$expected = date("l, d-M-y H:i:s \U\T\C", $time);
+		$this->assertEquals($expected, standard_date($format, $time));
+	}
+
+	// ------------------------------------------------------------------------
+
+	public function test_standard_date_rfc1036()
+	{
+		$time = time();
+		$format = 'DATE_RFC1036';
+		$expected = date("D, d M y H:i:s O", $time);
+		$this->assertEquals($expected, standard_date($format, $time));
+	}
+
+	// ------------------------------------------------------------------------
+
+	public function test_standard_date_rfc1123()
+	{
+		$time = time();
+		$format = 'DATE_RFC1123';
+		$expected = date("D, d M Y H:i:s O", $time);
+		$this->assertEquals($expected, standard_date($format, $time));
+	}
+
+	// ------------------------------------------------------------------------
+
+	public function test_standard_date_rfc2822()
+	{
+		$time = time();
+		$format = 'DATE_RFC2822';
+		$expected = date("D, d M Y H:i:s O", $time);
+		$this->assertEquals($expected, standard_date($format, $time));
+	}
+
+	// ------------------------------------------------------------------------
+
+	public function test_standard_date_rss()
+	{
+		$time = time();
+		$format = 'DATE_RSS';
+		$expected = date("D, d M Y H:i:s O", $time);
+		$this->assertEquals($expected, standard_date($format, $time));
+	}
+
+	// ------------------------------------------------------------------------
+
+	public function test_standard_date_w3c()
+	{
+		$time = time();
+		$format = 'DATE_W3C';
+		$expected = date("Y-m-d\TH:i:sO", $time);
+		$this->assertEquals($expected, standard_date($format, $time));
+	}
+
+	// ------------------------------------------------------------------------
+
+	public function test_timespan()
+	{
+		$this->markTestIncomplete('not implemented yet');
+	}
+
+	// ------------------------------------------------------------------------
+
+	public function test_days_in_month()
+	{
+		$this->assertEquals(30, days_in_month(06, 2005));
+		$this->assertEquals(28, days_in_month(02, 2011));
+		$this->assertEquals(29, days_in_month(02, 2012));
+	}
+
+	// ------------------------------------------------------------------------
+
+	public function test_local_to_gmt()
+	{
+		$this->markTestIncomplete('not implemented yet');
+	}
+
+	// ------------------------------------------------------------------------
+
+	public function test_gmt_to_local()
+	{
+		$timestamp = '1140153693';
+		$timezone = 'UM8';
+		$daylight_saving = TRUE;
+
+		$this->assertEquals(1140128493, gmt_to_local($timestamp, $timezone, $daylight_saving));
+	}
+
+	// ------------------------------------------------------------------------
+
+	public function test_mysql_to_unix()
+	{
+		$this->assertEquals(1164378225, mysql_to_unix(20061124092345));
+	}
+
+	// ------------------------------------------------------------------------
+
+	public function test_unix_to_human()
+	{
+		$time = time();
+		$this->assertEquals(date("Y-m-d h:i A"), unix_to_human($time));
+		$this->assertEquals(date("Y-m-d h:i:s A"), unix_to_human($time, TRUE, 'us'));
+		$this->assertEquals(date("Y-m-d H:i:s"), unix_to_human($time, TRUE, 'eu'));
+	}
+
+	// ------------------------------------------------------------------------
+
+	public function test_human_to_unix()
+	{
+		$time = time();
+		$this->markTestIncomplete('Failed Test');
+		// $this->assertEquals($time, human_to_unix(unix_to_human($time)));
+	}
+
+	// ------------------------------------------------------------------------
+
+	public function test_timezones()
+	{
+		$zones = array(
+			'UM12'		=> -12,
+			'UM11'		=> -11,
+			'UM10'		=> -10,
+			'UM95'		=> -9.5,
+			'UM9'		=> -9,
+			'UM8'		=> -8,
+			'UM7'		=> -7,
+			'UM6'		=> -6,
+			'UM5'		=> -5,
+			'UM45'		=> -4.5,
+			'UM4'		=> -4,
+			'UM35'		=> -3.5,
+			'UM3'		=> -3,
+			'UM2'		=> -2,
+			'UM1'		=> -1,
+			'UTC'		=> 0,
+			'UP1'		=> +1,
+			'UP2'		=> +2,
+			'UP3'		=> +3,
+			'UP35'		=> +3.5,
+			'UP4'		=> +4,
+			'UP45'		=> +4.5,
+			'UP5'		=> +5,
+			'UP55'		=> +5.5,
+			'UP575'		=> +5.75,
+			'UP6'		=> +6,
+			'UP65'		=> +6.5,
+			'UP7'		=> +7,
+			'UP8'		=> +8,
+			'UP875'		=> +8.75,
+			'UP9'		=> +9,
+			'UP95'		=> +9.5,
+			'UP10'		=> +10,
+			'UP105'		=> +10.5,
+			'UP11'		=> +11,
+			'UP115'		=> +11.5,
+			'UP12'		=> +12,
+			'UP1275'	=> +12.75,
+			'UP13'		=> +13,
+			'UP14'		=> +14
+		);
+
+		foreach ($zones AS $test => $expected)
+		{
+			$this->assertEquals($expected, timezones($test));
+		}
+
+		$this->assertArrayHasKey('UP3', timezones());
+		$this->assertEquals(0, timezones('non_existant'));
+	}
+}
+
+/* End of file date_helper_test.php */

user_guide/helpers/number_helper.html

 echo byte_format(456); // Returns 456 Bytes<br />
 echo byte_format(4567); // Returns 4.5 KB<br />
 echo byte_format(45678); // Returns 44.6 KB<br />
-echo byte_format(456789); // Returns 447.8 KB<br />
+echo byte_format(456789); // Returns 446.1 KB<br />
 echo byte_format(3456789); // Returns 3.3 MB<br />
-echo byte_format(12345678912345); // Returns 1.8 GB<br />
-echo byte_format(123456789123456789); // Returns 11,228.3 TB
+echo byte_format(1932735283.2); // Returns 1.8 GB<br />
+echo byte_format(123456789123456789); // Returns 112,283.3 TB
 </code>
 
 <p>An optional second parameter allows you to set the precision of the result.</p>
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.