symfony_persia/symfonyjdate
SymfonyJDate adds Persian (Jalali) date support to Symfony apps, with easy Gregorian-to-Jalali conversion and localized date formatting helpers for PHP and Twig. Integrate Persian dates quickly and consistently.
composer require symfony_persia/symfonyjdate in a Symfony 2.x project, but commit the exact version and check composer.lock. The last release is March 2015 — treat it as a fixed dependency, not something you'll get patches for.app/AppKernel.php, add the bundle to $bundles (the class name follows the SymfonyJDate naming — confirm against SymfonyJDateBundle.php at the repo root). There is no Flex recipe, no autowiring, and no services.yaml; this is the old Resources/config/services.yml style.README.md, *Bundle.php, Resources/config/services.yml (gives you the service id), DependencyInjection/, and any Twig/ or Form/ directory. Those three files tell you whether you get a Twig filter, a form type, a service, or just a static utility class. Don't guess the API from the README alone — 2015-era READMEs are usually out of sync with the code.DateTime stored in Gregorian (which you should keep doing) and you want to render it as Shamsi. Wire it up once in a controller or a Twig template and verify the output against a known pair, e.g. 2015-03-21 → 1394/01/01. If that one conversion is correct, the rest of the library is usually fine.DateTime/DateTimeImmutable. Run php -r 'echo PHP_INT_SIZE;' — if it prints 4, the whole reason to pick this package evaporates.DATETIME/TIMESTAMP (or UTC ISO strings) as usual and only convert for display and form input. This keeps your queries, sorting, and comparisons sane and makes it trivial to swap the library out later.AppBundle\Dates\JalaliConverter that injects the bundle service (or calls the static helper) and exposes exactly two methods: toJalali(DateTimeInterface $dt, string $format): string and fromJalali(string $s): DateTime. Every call site goes through this class. Given the package is unmaintained, this is the single most valuable thing you can do — it makes replacement a one-file change.{{ invoice.createdAt|jdate('Y/m/d H:i') }}. If it doesn't, add your own extension that delegates to the adapter — 15 lines and you control the filter name and defaults.1394/12/29; the entity expects a DateTime. Implement a DataTransformerInterface on top of fromJalali() / toJalali() and attach it to a normal DateType with a 'widget' => 'single_text' and a dd/MM/yyyy-style format. This is cleaner than trying to bend the bundle's own form type, which is likely tied to Symfony 2 form internals.fromJalali() and reject anything that doesn't round-trip: convert back and compare strings. Cheap validation that catches malformed input and off-by-one leap-year bugs in one shot.1394/12/29, 1395/12/30, and a far-future date like 1450/01/01 — and assert both directions in a unit test. This is your regression net against PHP version changes and accidental library swaps.DateTime rather than falling back to date()/mktime() internally. Grep the source for mktime, date(, and strtotime before trusting it with post-2038 dates.1394, 1395, and 1399 and the first day of Farvardin on both sides.23:30 UTC becomes the next day in Asia/Tehran, and a conversion done in the wrong order will silently show the wrong day.JDate::...), you cannot inject or mock it. That's another reason to keep the adapter wrapper — it's the only seam you'll have.jdate or jalali. Check getFilters() and rename yours if needed.composer.json constraints to lean on. Old bundles often declare symfony/symfony: ~2.x loosely or not at all, so Composer may happily install it alongside incompatible packages. Add an explicit conflict or platform constraint in your root composer.json.intl extension supports the Persian calendar natively via IntlDateFormatter with locale fa_IR@calendar=persian, and it handles far-future years on 64-bit builds. For parsing/arithmetic, a maintained Jalali date library is the safer long-term bet. Either way, the adapter wrapper from the patterns section makes that migration a same-day change rather than a refactor.How can I help you explore Laravel packages today?