Giter Site home page Giter Site logo

morilog / jalali Goto Github PK

View Code? Open in Web Editor NEW

This project forked from miladr/jalali

851.0 16.0 107.0 142 KB

This Package helps developers to easily work with Jalali (Shamsi or Iranian) dates in php appliations, based on Jalali (Shamsi) DateTime class.

License: MIT License

PHP 100.00%
laravel jalali shamshi morilog laratalks persian-calendar composer

jalali's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

jalali's Issues

Wrong result in subMonths()

Hello dear,
Algorithm of the subMonths() function has a problem for subtracting months which results a date in previous year.
I propose you a simple implementation as follow:

    public function subMonths(int $months = 1): Jalalian
    {
        Assertion::greaterOrEqualThan($months, 1);

        $years = (int)($months / 12);
        $newDate = clone $this;
        if($years > 0)
            $newDate  = $this->subYears($years);

        $rem = $months % 12;
        $targetMonth = $newDate->getMonth() - $rem;
        if($targetMonth > 0) {
            $day = $newDate->getDay();
            $targetMonthDays = $newDate->getDaysOf($targetMonth);
            $targetDay = $day <= $targetMonthDays ? $day : $targetMonthDays;
            return new static(
                $newDate->getYear(),
                $targetMonth,
                $targetDay,
                $newDate->getHour(),
                $newDate->getMinute(),
                $newDate->getSecond(),
                $newDate->getTimezone()
            );
        } else {
            $targetMonth = 12 - abs($targetMonth);
            $day = $newDate->getDay();
            $targetMonthDays = $newDate->getDaysOf($targetMonth);
            $targetDay = $day <= $targetMonthDays ? $day : $targetMonthDays;
            return new static(
                $newDate->getYear() - 1,
                $targetMonth,
                $targetDay,
                $newDate->getHour(),
                $newDate->getMinute(),
                $newDate->getSecond(),
                $newDate->getTimezone()
            );
        }
   }

bug in call method

I get this Error When using methods
toArray()
getDayOfWeek()
isSunday()
and...
Call to undefined method Carbon\Carbon::isDayOfWeek()
at method isDayOfWeek() in Jalalian.php

Timestamp Not Working

Hi

Not working:
$date = Jalalian::forge(1333857600);

and "createFromTimestamp" is missing!

Fix Documentation

What is the difference?!!

// get relative 'ago' format
$date = Jalalian::forge('now - 10 minutes')->ago() // 10 دقیقه پیش
// OR
$date = Jalalian::forge('now - 10 minutes')->ago() // 10 دقیقه پیش

Get DayName

hi

i want to use getdayname like this :

$date = new jdate(true, true, 'Asia/Tehran');
$day = $date->mktime(0,0,0,10,10,1397);
echo $date->date("l", $day);

is there any easier than this way ?!!!
i want set time and get day name .....?!!!

some issue in length array periods

Hi , I think that the array define for 'قرن' is not correct . its 10 right now and its have to be 100 .
or maybe changing 'قرن' to 'دهه' can be a solution.
here

Or tell me if i'm wrong.

first day of last month

how can i have this result ?
$date = Jalalian::forge('first day of last month'); // present time for example : 1397-08-08 // output : 1397-07-01

checkdate always returns false

jDateTime.checkdate returns false (for any input parameters!)

I replaced function body with original jdf checkdate and it works good
public static function checkdate($jm, $jd, $jy) { $l_d=($jm==12)?(($jy%33%4-1==(int)($jy%33*.05))?30:29):31-(int)($jm/6.5); return($jm>0 and $jd>0 and $jy>0 and $jm<13 and $jd<=$l_d)?true:false; }

time is 00:00:00

why time is 00:00:00

$date = jDate::forge('last sunday')->format('datetime'); // 1391-10-02 00:00:00

?

تشخیص سال کبیسه

سلام
وقت بخیر

من می خواستم بدونم آیا متودی برای تشخیص سال کبیسه وجود دارد؟

Wrong value for day of the year

The day of the year (starting from 0): function.date.php

$j = jDate::forge(1458432001, 'UTC');
echo $j->format('Y-m-d H:i:s --z') . "\n";    // 1395-01-01 00:00:01 --1

$d = DateTime::createFromFormat('Y-m-d H:i:s', '2016-01-01 00:00:01', new DateTimeZone('UTC'));
echo $d->format('Y-m-d H:i:s --z') . "\n";    // 2016-01-01 00:00:01 --0

toGregorian return type

Is it possible to have another version of toGregorian which returns date instead of array? Currently I have to do the following to convert numbers to date:

$georgianDate = jDateTime::toGregorian(1370, 2, 20);
$year = $georgianDate[0];
$month = $georgianDate[1];
$day = $georgianDate[2];
$birthdate = date("Y-m-d",strtotime("$year-$month-$day"));

set jDate for timestamp field type in laravel

SQLSTATE[22007]: Invalid datetime format: 1292 Incorrect datetime value: '1397-06-23 11:45:30' for column 'updated_at' at row 1 (SQL: update products set updated_at = 1397-06-23 11:45:30 where id = 26)

and i don't wanna change the timestamp type to datetime in my table

Issue on Time output

Hi
Thanks for such a nice library.
I was previously using this library on L5.4 and everything was fine. Recently I switched to L5.5 and there is some weird thing happen.

When I insert my data in database I have the correct time(ex: 2017-10-25 10:35:34). I made a getAttributeStartDateTime($value) and getAttributeEndDateTime($value) and use below functions alternatively to get the date and time in jalali format:

return jDateTime::strftime('Y-m-d  H:m:s', strtotime($value), 'Asia/Tehran');
return jdate(strtotime($value))->format('Y-m-d H:m:s');

I changed all possible formats and the result is always the same. whatever I put in database the result of this function is XX:08:00.

By this I mean if I have 09:34:45 or 23:15:24 in database the result will be 09:08:00 and 23:08:00 accordingly.

I would appreciate if you help me on this matter

predefined format doesn't work

hi
these codes:
// get a predefined format
$date = Jalalian::forge('last sunday')->format('datetime'); // 1391-10-02 00:00:00
$date = Jalalian::forge('last sunday')->format('date'); // 1391-10-02
$date = Jalalian::forge('last sunday')->format('time'); // 00:00:00

doesn't work.
error:

(1/1) InvalidArgumentExceptionUnexpected data found.Unexpected data found.The separation symbol could not be foundA two digit second could not be found

The addMonths method in Jalalian class has bug !!!

`Assertion::greaterOrEqualThan($months, 1);

    $years = (int) ($months / 12);
    $date = $years > 0 ? $this->addYears($years) : clone $this;

    $months = ($months % 12) + $date->getMonth();
    $days = 0;

    for ($i = $date->getMonth() + 1; $i <= $months; $i++) {
        $days += $date->getDaysOf($i); **// Bug here**
        if ($i === 12) {
            $i = 1;
            $months = $months - 12;
        }
    }

    return $date->addDays($days);`

Sometimes maybe month is 12, so when month total with 1 digit, reporting exception:
Provided "13" is neither greater than or equal to "1" nor less than or equal to "12".

loop 5/month for two years

Hi ,

I want to make a loop for filth day in each month to 2 years

5/1/1395
5/2/1395
5/3/1395
5/4/1395
5/5/1395
5/6/1395
5/7/1395
5/8/1395
5/9/1395
5/10/1395
5/11/1395
5/12/1395
5/1/1396
...

How can I do it by your package?

I use mktime() php in Gregorian date

thanks

Missing "format characters"

Hi,

According to this page function.date.php, some other format characters like u and v exist that are not supported by Jalali .

$d1 =  DateTime::createFromFormat('Y-m-d H:i:s.u', '1966-02-31 22:32:11.254687'); //success
$d2 = jDateTime::createFromFormat('Y-m-d H:i:s.u', '1354-02-31 22:32:11.254687');; //error

I don't want to hard code Jalali. May you please consider adding missing format characters to Jalali ?

problem with leap years

$date = jDate::forge('2012-10-12')->reforge('next year')->format('Y-m-d');
reforge function works on Gregorian date and ignores Jalali leap years.

Specially, I want to add 1 year to a SQL date column without losing leap year computation.
(In my program SQL date columns are Gregorian, but users should work with Jalali date formats.)

thanks

Modify on dates

I saw on the codes that reforge is actually same as modify. So I tried this:

 $c = jDate::forge( Carbon::createFromDate(2016,12,1)->timestamp );
 $this->assertSame('1395-09-11', $c->format('Y-m-d'));

 $c->reforge('2 month');
 $this->assertSame('1395-11-11', $c->format('Y-m-d'));

and got this:

Failed asserting that two strings are identical.
--- Expected
+++ Actual
@@ @@
-1395-11-11
+1395-11-13

Are you planning to add this functionality to Jalali dates soon? I mean if you are already working on it I'll wait. Or if you're not, I figure it out somehow and make a PR for morilog/jalali.

5th month name

5th month name is مرداد in official jalali calendar but in this package sallar used امرداد (with better meaning). Is it possible to change it to official name?

Regex problem on parseFromFormat method from CalendarUtils class

The Exception is on line 735.

Exception Message:

preg_match(): Compilation failed: two named subpatterns have the same name at offset 50

Exception trace:

preg_match("#^(?P\d{4})/(?P[A-Z][a-z]{3})(?P[A-Z][a-z]{3})/(?P[A-Z][a-z]{2})(?P[A-Z][a-z]{2})$#", "1397/09/21", [])

Class 'Morilog\Jalali\jDatetime' not found

Hi , i am using your bundle in view or blade , I went through this error "Class 'Morilog\Jalali\jDatetime' not found".

.
.
.

تاریخ رزرو {{ \Morilog\Jalali\jDatetime::strftime('Y-m-d',$reservation->date_reserved) }} . . . please help me.

Error in PHP7.1

In PHP7.1 i get this error:

A non well formed numeric value encountered

More information:
I'm using Laravel 5.4 on PHP7.1. It works fine with Laravel 5.4 on PHP5.6

تاریخ شروع و پایان ماه

سلام
وقت بخیر

من از این پکیج برای لاراول استفاده می کنم و خود
timestamp
های لاراول را دارم یعنی میلادی هستند

حالا می خواهم تاریخ شروع و پایان ماه جاری شمسی را به سیستم بدهم و تراکنش های ماه شمسی را بگیرم.

ممنون می شوم توضیح بدهید روند کار چگونه است

Can not install

Why Version 3 is not installed in LARAVEL version 5.6 and 5.7?

Undefined index: year

ErrorException in jDateTime.php line 735: Undefined index: year

echo jDateTime::createDateTimeFromFormat('Y/m/d h:i:s', "1395/4/15 00:00:00"); //error
echo jDateTime::createDateTimeFromFormat('Y/m/d h:i:s', "1395/04/15 00:00:00"); //success

Error because length of month or day

مشکل تبدیل تاریخ شمسی به میلادی

برای تبدیل تاریخ شمسی به میلادی از متد
toGregorian
استفاده می کنم. منتهی ارور دریافت میکنم.

\Morilog\Jalali\CalendarUtils::toGregorian(1395,4,15)
اروری که دریافت می کنم:
htmlspecialchars() expects parameter ۱ to be string, array given
نسخه لاراولم ۵.۵ هست
نسخه پکیجی که نصب کردم :
3.*

mismatch datetime

ساعت نشان داده شده همواره 4:30 از ساعت ذخیره شده عقب است.
my server timezone is Asia/Tehran
my timezone in config/app.php is Asia/Tehran

code to save date:
jDateTime::createCarbonFromFormat('Y-n-j', $request->input('hire_date'))->toDateString()

code to show date:
jDate::forge($user->hire_date)->format('j F Y')

Bug in xxxx-01-02 Dates

I have found a bug here. Please check jDate22 out

<?php
use Morilog\Jalali\jDate;
class convertTest extends PHPUnit_Framework_TestCase
{
    public function testCreate()
    {
        $jDate20 = jdate('2017-03-20 00:00:00');
        $jDate21 = jdate('2017-03-21 00:00:00');
        $jDate22 = jdate('2017-03-22 00:00:00');
        $jDate23 = jdate('2017-03-23 00:00:00');

        $this->assertSame('1395-12-30 00:00:00', $jDate20->format('Y-m-d H:i:s'), 'jDate20');
        $this->assertSame('1396-01-01 00:00:00', $jDate21->format('Y-m-d H:i:s'), 'jDate21');
        $this->assertSame('1396-01-02 00:00:00', $jDate22->format('Y-m-d H:i:s'), 'jDate22');
        $this->assertSame('1396-01-03 00:00:00', $jDate23->format('Y-m-d H:i:s'), 'jDate23');
    }
}

Result:

There were 1 failures:

1) convertTest::testCreate
jDate22
Failed asserting that two strings are identical.
--- Expected
+++ Actual
@@ @@
-1396-01-02 00:00:00
+1396-01-02 01:00:00

The 0 hour could not be set.

Warning: date_default_timezone_get()

I use laravel5.4.I install jalali package.now when I run project, I see this message
Whoops, looks like something went wrong.
to understand the details entered this command in terminal
php artisan key generate
and I got this warning Warning:
date_default_timezone_get(): Invalid date.timezone value 'Asia/Iran', we selected the timezone 'UTC' for now. in C:\wamp\www\laravel\vendor\monolog\monolog\src\Monolog\Logger.php on line 311 Warning: date_default_timezone_get(): Invalid date.timezone value 'Asia/Iran', we selected the timezone 'UTC' for now. in C:\wamp\www\laravel\vendor\monolog\monolog\src\Monolog\Logger.php on line 311 [Symfony\Component\Debug\Exception\FatalThrowableError] Undefined constant 'Morilog\Jalali\JalaliServiceProvider' timezone of php.ini and app.php is UTC . what should I do to fix this bug?

wrong calculate of some date

this package convert 1397/02/30 to 2018-05-20 that it's correct but convert 2018-05-20 to 1397/03/02 that means wrong.
See my functions that do this:

function hijri2miladi($hijriDate) {
   $parseDate = date_parse($hijriDate);

   $miladi=jDateTime::toGregorian($parseDate['year'],$parseDate['month'],$parseDate['day']);

   $myDate = new DateTime();
   $myDate = $myDate->setDate($miladi[0], $miladi[1], $miladi[2])->format('Y-m-d');

   return $myDate;
}

And

function miladi2hijri($miladiDate) {
   $parseDate = date_parse($miladiDate);

   $shamsi = jDateTime::toJalali($parseDate['year'], $parseDate['month'], $parseDate['day']);
   $myDate = new DateTime();
   $myDate = $myDate->setDate($shamsi[0], $shamsi[1], $shamsi[2])->format('Y/m/d');

   return $myDate;
}

Problem with 'forge'

Hi,
On version 3, when i using Jalalian::forge(1538902714) i got below error:
DateTime::__construct(): Failed to parse time string (1538902714) at position 8 (1): Unexpected character

Can you help me?

detect localization

hi ,
how can I use jdate with detect localization , and i see shamsi in persian lang, and miladi for english ,and ...

update

Can update this packege from 5.6 to 5.7

مشکل در subMonths

بعد از به روز رسانی فقط به خاطر
subMonths
به مشکل برخوردم که درست کار نمیکنه !

مثلا مقدار 1 رو میدم که یک ماه گذشته رو بیاره که دو سه ماه آینده رو میاره.
وقت کردی فیکسش کن.

ممنون

Class JalaliServiceProvider not found

Hi
I'm using laravel 5.4 to develop an app, when i run:
php artisan optimize
i got this error:

In ProviderRepository.php line 208:
  Class 'Morilog\Jalali\JalaliServiceProvider' not found

just to mention that i cloned my project and run this that at the end when it want to optimize i got the above error
composer install --no-dev

Wrong Daylight saving time.

hello
how we can use daylight saving time?
there is an option to enable? or will it be calculated automatically?
thanks.

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.