Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mohebifar/php-jalali-extension
A php extension for Jalali dates
https://github.com/mohebifar/php-jalali-extension
Last synced: 16 days ago
JSON representation
A php extension for Jalali dates
- Host: GitHub
- URL: https://github.com/mohebifar/php-jalali-extension
- Owner: mohebifar
- License: mit
- Created: 2014-10-12T22:30:52.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2015-02-14T14:00:49.000Z (over 9 years ago)
- Last Synced: 2024-10-10T22:15:21.951Z (about 1 month ago)
- Language: Shell
- Size: 1.86 MB
- Stars: 20
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-persian - php-jalali-extension - A php extension for Jalali dates. (Jalali Date)
README
PHP Jalali Extension
====================
Jalali extension is a php extension written in C which allows you to format a timestamp by *Hejri Date Format* or get the timestamp by giving *Hejri Dates*.This is simply **as fast as** `date()` and `mktime()` functions.
Installation
==========
Copy the `build/jalali.so` into the php extensions directory. Then add this line into the `php.ini` :extension=jalali.so
Done !
## PHP Version ##
If you are running php on a windows machine when developing or **you cannot install the extension for some reason**, You can include the **php version** which exists in `php` directory. **It uses the extension if it existed** otherwise It defines the same class in php context.How to use
=========
Create an object of `\Jalali\Date`.```php
$jDate = new \Jalali\Date();
```You can format the date by calling `$jDate::date`. The function covers all of the native `date()` function literals.
```php
$jDate->date("l jS F Y");
// Output: دوشنبه بیست و یکم مهر 1393
```And Also You can get the timestamp of a date time.
```php
$jDate->mktime(15, 45, 0, 7, 21, 1393);
```Benchmark
=========
As you know calculating Hejri Date from a timestamp includes of a lot of addition, subtraction, multiplication, and division, so it increases cpu cycles.This is the fastest class ever known in php to do that !
We compare the extension with [sallar/jDateTime](https://github.com/sallar/jDateTime) so that we do the same `date("Y m d l s f")` action with both classes 100,000 times.
I ran the script on an ubuntu 14.04 machine with php5.5 installed and enabled opcache.
```php
$phpJDate = new jDateTime();
$extJDate = new \Jalali\Date();$phpTime = 0;
$extTime = 0;$time = time();
for($i = 0; $i < 100000; $i++) {
$start = microtime(true);
$phpJDate->date("Y m d l s f");
$phpTime += microtime(true) - $start;$start = microtime(true);
$extJDate->date("Y m d l s f");
$extTime += microtime(true) - $start;
}var_dump($phpTime, $extTime);
```And the result is :
18.459370851517 seconds for sallar/jDateTime
5.1387049674988 seconds for mohebifar/php-jalali-extension