Skip to content

Commit

Permalink
Merge pull request #10 from xtcat/cleanup
Browse files Browse the repository at this point in the history
Added some docblocks and use phpunit
  • Loading branch information
camroncade committed Jun 2, 2016
2 parents a3e5b3c + 85dab01 commit e127e55
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 10 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
composer.phar
composer.lock
.DS_Store
.idea/
7 changes: 5 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "camroncade/timezone",
"description": "Helps manage timezones in Laravel. Includes <select> form builder for timezones.",
"homepage": "http://www.camroncade.com/managing-timezones-with-laravel/",
"keybords": ["timezone", "timezones"],
"keywords": ["timezone", "timezones"],
"license": "MIT",
"authors": [
{
Expand All @@ -22,5 +22,8 @@
"Camroncade\\Timezone\\": "src/"
}
},
"minimum-stability": "stable"
"minimum-stability": "stable",
"require-dev": {
"phpunit/phpunit": "^5.3"
}
}
33 changes: 29 additions & 4 deletions src/Camroncade/Timezone/Timezone.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,22 @@ class Timezone {
'(UTC+13:00) Nuku\'alofa' => 'Pacific/Tongatapu'
);

public function getTimezones()
/**
* @return array
*/
public function getTimezones()
{
return $this->timezoneList;
}


/**
* @param null $selected
* @param null $placeholder
* @param array $selectAttributes
* @param array $optionAttributes
*
* @return string
*/
public function selectForm($selected = null, $placeholder = null, array $selectAttributes = [], array $optionAttributes = [] )
{
$selectAttributesString = '';
Expand Down Expand Up @@ -196,16 +207,30 @@ public function selectForm($selected = null, $placeholder = null, array $selectA
return $string;
}

/**
* @param integer $timestamp
* @param string $timezone
* @param string $format
*
* @return string
*/
public function convertFromUTC($timestamp, $timezone, $format = 'Y-m-d H:i:s')
{
$date = new DateTime($timestamp, new DateTimeZone('UTC'));

$date->setTimezone(new DateTimeZone($timezone));

return $date->format($format);
}
}

public function convertToUTC($timestamp, $timezone, $format = 'Y-m-d H:i:s')
/**
* @param integer $timestamp
* @param string $timezone
* @param string $format
*
* @return string
*/
public function convertToUTC($timestamp, $timezone, $format = 'Y-m-d H:i:s')
{
$date = new DateTime($timestamp, new DateTimeZone($timezone));

Expand Down
8 changes: 4 additions & 4 deletions src/Camroncade/Timezone/TimezoneServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,21 @@ class TimezoneServiceProvider extends ServiceProvider {
/**
* Bootstrap the application events.
*
* @return void
* @return null
*/
public function boot()
{
AliasLoader::getInstance()->alias('Timezone', 'Camroncade\Timezone\Facades\Timezone');
AliasLoader::getInstance()->alias('Timezone', \Camroncade\Timezone\Facades\Timezone::class);
}

/**
* Register the service provider.
*
* @return void
* @return null
*/
public function register()
{
$this->app->bind('timezone', 'Camroncade\Timezone\Timezone');
$this->app->bind('timezone', Timezone::class);
}

/**
Expand Down
17 changes: 17 additions & 0 deletions tests/TimezoneTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

class TimezoneTest extends PHPUnit_Framework_TestCase{
public function testConvertFromUTC(){
$timezone = new \Camroncade\Timezone\Timezone();

$this->assertEquals('2016-01-01 18:00:00',$timezone->convertFromUTC('2016-01-01 18:00:00','UTC'));
$this->assertEquals('18:30:20',$timezone->convertFromUTC('2016-01-01 18:30:20','UTC','H:i:s'));
}

public function testConvertToUTC(){
$timezone = new \Camroncade\Timezone\Timezone();

$this->assertEquals('2016-01-01 18:00:00',$timezone->convertToUTC('2016-01-01 18:00:00','UTC'));
$this->assertEquals('18:30:20',$timezone->convertToUTC('2016-01-01 18:30:20','UTC','H:i:s'));
}
}

0 comments on commit e127e55

Please sign in to comment.