Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Packaged for laravel 5.* #5

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Changelog

All Notable changes to `laravel-jdate` will be documented in this file.

### Added
- packaged for laravel 5.*
- falaki month names
- config file (jdate.php) for month names (jalali\falaki)

### Deprecated
- Nothing

### Fixed
- README updated for installing package on laravel 5.*

### Removed
- Nothing

### Security
- Nothing
21 changes: 21 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# The MIT License (MIT)

Copyright (c) 2016 :author_name <:author_email>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you change this to correct information?


> Permission is hereby granted, free of charge, to any person obtaining a copy
> of this software and associated documentation files (the "Software"), to deal
> in the Software without restriction, including without limitation the rights
> to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
> copies of the Software, and to permit persons to whom the Software is
> furnished to do so, subject to the following conditions:
>
> The above copyright notice and this permission notice shall be included in
> all copies or substantial portions of the Software.
>
> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
> AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
> LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
> OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
> THE SOFTWARE.
23 changes: 17 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# jDate Bundle for Laravel #
# jDate Package for Laravel 5.*#

This bundle helps developers to easily work with Jalali (Shamsi or Iranian) dates in Laravel applications, based on [Jalali (Shamsi) DateTime](https://github.com/sallar/jDateTime) class.

Expand All @@ -9,16 +9,27 @@ This bundle helps developers to easily work with Jalali (Shamsi or Iranian) date

## Install ##

To install using artisan run the following CLI command:
In order to install Laravel 5 jDate, just add
```
php artisan bundle:install jdate
"sallar/laravel-jdate" : "*"
```
Or just copy the downloaded package to ``app/bundles``
to your composer.json. Then run composer install or composer update.

Then in ``application/bundles.php`` add:
Then run
```
php artisan vendor:publish
```

Then in your config/app.php add
```php
'jDate' => Sallar\jDate\jDate::class
```

## Config ##

in the config/jdate.php you can set jalali or falaki for month names.
```php
'jdate' => array('auto' => true),
'type' => 'jalali' //default is jalali
```

## Examples ##
Expand Down
37 changes: 37 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"name": "sallar/laravel-jdate",
"type": "library",
"description": "This package helps developers to easily work with Jalali (Shamsi or Iranian) dates in Laravel applications",
"keywords": [
"sallar",
"laravel-jdate"
],
"homepage": "https://github.com/sallar/laravel-jdate",
"license": "MIT",
"authors": [
{
"name": "sallar",
"email": "[email protected]",
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my correct email is [email protected] and maybe add yourself also as a contributor.

"homepage": "https://sallar.me",
"role": "Developer"
}
],
"require": {
"illuminate/support": "~5.1",
"php" : "~5.5|~7.0"
},
"require-dev": {
"phpunit/phpunit" : "4.*",
"scrutinizer/ocular": "~1.1",
"squizlabs/php_codesniffer": "~2.3"
},
"autoload": {
"psr-4": {
"Sallar\\jDate\\": "src"
}
},
"scripts": {
"test": "phpunit"
},
"minimum-stability": "dev"
}
6 changes: 6 additions & 0 deletions src/config/config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?php

return [
// jalali of falaki
'type' => 'jalali' //default is jalali
];
2 changes: 2 additions & 0 deletions libraries/jdate.php → src/jDate.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php
namespace Sallar\jDate;
use Sallar\jDate\jDateTime;

/**
* A LaravelPHP helper class for working w/ jalali dates.
Expand Down
30 changes: 30 additions & 0 deletions src/jDateServiceProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace Sallar\jDate;

use Illuminate\Support\ServiceProvider;

class jDateServiceProvider extends ServiceProvider
{
/**
* Perform post-registration booting of services.
*
* @return void
*/
public function boot()
{
$this->publishes([
__DIR__.'/config/config.php' => config_path('jdate.php'),
]);
}

/**
* Register any package services.
*
* @return void
*/
public function register()
{
//
}
}
61 changes: 58 additions & 3 deletions libraries/jdatetime.php → src/jDatetime.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<?php
namespace Sallar\jDate;
use \DateTime;
use \DateTimeZone;
/**
* Jalali DateTime Class, supports years higher than 2038
* by: Sallar Kaboli
Expand Down Expand Up @@ -437,8 +440,8 @@ private static function getDayNames($day, $shorten = false, $len = 1, $numeric =

private static function getMonthNames($month, $shorten = false, $len = 3)
{
$ret = '';
switch ( $month ) {
$ret = self::getMonth($month,'falaki');
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To make changes to this file, please send a pull request to the original project here: https://github.com/sallar/jDateTime
Direct changes should be reverted.

/*switch ( $month ) {
case '1': $ret = 'فروردین'; break;
case '2': $ret = 'اردیبهشت'; break;
case '3': $ret = 'خرداد'; break;
Expand All @@ -451,7 +454,9 @@ private static function getMonthNames($month, $shorten = false, $len = 3)
case '10': $ret = 'دی'; break;
case '11': $ret = 'بهمن'; break;
case '12': $ret = 'اسفند'; break;
}
}*/


return ($shorten) ? mb_substr($ret, 0, $len, 'UTF-8') : $ret;
}

Expand Down Expand Up @@ -571,4 +576,54 @@ public static function toGregorian($j_y, $j_m, $j_d)

}

/**
* @author Morteza Rjabi
*
* get the specifid moonth
* @param int $num month number 1-12
* @param string $type jalali or falaki
* @return string month name
*/
private static function getMonth($num ,$type= 'jalali')
{

$jalali = [ '1'=> 'فروردین',
'2'=> 'اردیبهشت',
'3'=> 'خرداد',
'4'=> 'تیر',
'5'=> 'امرداد',
'6'=> 'شهریور',
'7'=> 'مهر',
'8'=> 'آبان',
'9'=> 'آذر',
'10'=> 'دی',
'11'=> 'بهمن',
'12'=> 'اسفند'];

$falaki = [ '1'=> 'حمل',
'2'=> 'ثور',
'3'=> 'جوزا',
'4'=> 'سرطان',
'5'=> 'اسد',
'6'=> 'سنبله',
'7'=> 'میزان',
'8'=> 'عقرب',
'9'=> 'قوس',
'10'=> 'جدی',
'11'=> 'دلو',
'12'=> 'حوت'];

if($num < 1 or $num > 12)
return '';


if(config('jdate.type', $type) == 'jalali') //use $type if config does not exists.
return $jalali[$num];

if(config('jdate.type', $type) == 'falaki') //use $type if config does not exists.
return $falaki[$num];

return '';//if $type not mach jalali or falaki
}

}
6 changes: 0 additions & 6 deletions start.php

This file was deleted.