Skip to content

Commit

Permalink
Added unit testing for jDateTime
Browse files Browse the repository at this point in the history
  • Loading branch information
sallar committed Jan 28, 2013
1 parent a33ac41 commit c969a89
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 11 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ jDateTime
Jalali (Shamsi) DadeTime class written in PHP, Supports year higher than 2038.
[![Build Status](https://travis-ci.org/sallar/jDateTime.png?branch=master)](https://travis-ci.org/sallar/jDateTime)

##About v2.0.0
##About v2.1.5

PHP's default `date` function does not support years higher than
2038, so the `DateTime` class was introduced in PHP5 to solve this problem and provide more sophisticated date methods. Iranian users have been using an old `jdate` function to convert Gregorian date to the Jalali equivalent, which is completely based on the old php `date` function so its pretty much out-dated.
Expand Down
18 changes: 14 additions & 4 deletions Tests/JDateTimeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,27 @@ class JDateTimeTest extends PHPUnit_Framework_TestCase
//Start test
public function setUp()
{
//nothing
$this->obj = new jDateTime(true, true, 'Asia/Tehran');
}
//EOF
public function tearDown()
{
//nothing
}

public function testFirstTest()
public function testMakeJalaliTime()
{
$time = $this->obj->mktime(0,0,0,10,02,1368);
$this->assertEquals($time, 630361800);
$this->assertEquals($this->obj->date("l Y/m/d", $time), "شنبه ۱۳۶۸/۱۰/۰۲");
$this->assertEquals($this->obj->date("c", $time, false), "1368-10-02T00:00:00+03:30");
}

public function testMakeGregorianTime()
{
//It works!
$this->assertEquals(1, 1);
$time = $this->obj->mktime(0,0,0,1,1,2010, false, 'America/New_York');
$this->assertEquals($time, 1262322000);
$this->assertEquals($this->obj->date("c", $time, false, false, 'America/New_York'), "2010-01-01T00:00:00-05:00");
$this->assertEquals($this->obj->date("c", $time, false, false, 'Europe/Berlin'), "2010-01-01T06:00:00+01:00");
}
}
4 changes: 2 additions & 2 deletions Tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

function loader($class)
{
$file = $class . '.php';
$file = dirname(dirname(__FILE__)) .'/'. strtolower($class) . '.class.php';
if (file_exists($file)) {
require $file;
}
}

spl_autoload_register('loader');
spl_autoload_register('loader');
4 changes: 2 additions & 2 deletions jdatetime.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
* @license http://opensource.org/licenses/mit-license.php The MIT License
* @link https://github.com/sallar/jDateTime
* @see DateTime
* @version 2.0.0
* @version 2.1.5
*/
class jDateTime
{
Expand Down Expand Up @@ -95,7 +95,7 @@ public static function date($format, $stamp = false, $convert = null, $jalali =
//Timestamp + Timezone
$stamp = ($stamp != false) ? $stamp : time();
$timezone = ($timezone != null) ? $timezone : ((self::$timezone != null) ? self::$timezone : date_default_timezone_get());
$obj = new DateTime('@' . $stamp);
$obj = new DateTime('@' . $stamp, new DateTimeZone($timezone));
$obj->setTimezone(new DateTimeZone($timezone));

if ( (self::$jalali === false && $jalali === null) || $jalali === false ) {
Expand Down
4 changes: 2 additions & 2 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit bootstrap="Tests/bootstrap.php" colors="true">
<phpunit bootstrap="./Tests/bootstrap.php" colors="true">
<testsuites>
<testsuite name="Project Test Suite">
<testsuite name="jDateTime_Test">
<directory>./Tests/</directory>
</testsuite>
</testsuites>
Expand Down

0 comments on commit c969a89

Please sign in to comment.