GithubHelp home page GithubHelp logo

mohebifar / php-jalali-extension Goto Github PK

View Code? Open in Web Editor NEW
20.0 2.0 0.0 1.91 MB

A php extension for Jalali dates

License: MIT License

PHP 7.03% Makefile 1.12% Awk 0.20% Shell 59.06% C 31.50% C++ 0.27% Zephir 0.82%

php-jalali-extension's Introduction

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.

$jDate = new \Jalali\Date();

You can format the date by calling $jDate::date. The function covers all of the native date() function literals.

$jDate->date("l jS F Y");
// Output: دوشنبه بیست و یکم مهر 1393

And Also You can get the timestamp of a date time.

$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 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.

$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

php-jalali-extension's People

Contributors

mohebifar avatar

Stargazers

Mojtabaa avatar Vahid Najafi avatar Ehsan Tork  avatar Amir Habibzadeh avatar Nima Heidari avatar Mohammad Shiran avatar Reza Khodadadi avatar Iman Ghasrfakhri avatar ReZa ZaRe avatar Ali Pandidan avatar Mohammad Sadegh Khoeini avatar Reza avatar Omid Pilevar avatar  avatar Reza Haghighi avatar Mahdi avatar Obaid Samadian avatar Mohamad Jahani avatar Mohammad Ali avatar Saleh Souzanchi avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.