msajadi824 / simple-date-bundle

A bundle for persian date in Symfony2
8 stars 2 forks source link
intl-format persian-date-picker persian-datepicker symfony

pouyasoft_ir/simple-date-bundle

A bundle for persian date in Symfony2

Install

$ php composer require pouyasoft_ir/simple-date-bundle

Service

Service Name: pouya_soft.j_sdate_service

Functions:

Sample:

$shamsiString = $this->get('pouya_soft.j_sdate_service')->georgianToPersian(new \DateTime(), 'yyyy-MM-dd E');
//result: ۱۳۹۴-۱۱-۲۲ دوشنبه
$shamsiString = $this->get('pouya_soft.j_sdate_service')->persianToGeorgian('1394-11-22 دوشنبه', 'yyyy-MM-dd E');
//result: An instance of DateTime

Twig

Functions:

Sample:

{{ date|gpDate }} <br>
{{ date|gpDate('yyyy-MM-dd E') }} <br>
{{ '1394/11/22'|gpDate }} <br>
{{ '1394-11-22 دوشنبه'|gpDate('yyyy-MM-dd E') }} <br>

Form

Type Name: PouyaSoftSDateType

Parameters:

note: Result of serverFormat and clientFormat, must be the same.

Sample:

$builder
    ->add('date', PouyaSoftSDateType::class, [
        'serverFormat' => 'yyyy/MM/dd',
        'pickerOptions' => [
            'Format' => 'yyyy/MM/dd',
            'EnableTimePicker' => true,
            'GroupId' => 'group1',
            'FromDate' => true,
            'DisableBeforeToday' => true,
        ]
    ])
    ->add('date2', PouyaSoftSDateType::class, [
        'serverFormat' => 'yyyy-MM-dd E',
        'pickerOptions' => [
            'Format' => 'yyyy/MM/dd',
            'EnableTimePicker' => true,
            'GroupId' => 'group1',
            'ToDate' => true,
        ]
    ])

Date Picker

Requirements:

Add this lines to head tag in base.html.twig file:

<head>
    ...

    <link rel="stylesheet" href="https://github.com/msajadi824/simple-date-bundle/blob/master/{{ asset('bundles/pouyasoftsdate/MdBootstrapPersianDateTimePicker/jquery.md.bootstrap.datetimepicker.style.css') }}" />
    ...
</head>

Add this lines to end of body tag in base.html.twig file:

<script type="text/javascript" src="https://github.com/msajadi824/simple-date-bundle/raw/master/{{ asset('bundles/pouyasoftsdate/MdBootstrapPersianDateTimePicker/jquery.md.bootstrap.datetimepicker.js') }}"></script>

Add this lines to config/packages/twig.yaml file:

twig:
    form_themes:
        - '@PouyaSoftSDate/form/form_s_date.html.twig'

References: