2. Configuration

To display dates, this bundle uses timezone detectors to get the current timezone.

2.1. Timezone detectors

2.1.1. User timezone detector

New in version 2.7: If the model class for the authenticated user implements Sonata\IntlBundle\Timezone\TimezoneAwareInterface, it returns the timezone from its getTimezone() method. For convenience, the Sonata\IntlBundle\Timezone\TimezoneAwareTrait is available, which provides a basic implementation.

DEPRECATED Relying on Sonata\UserBundle\Model\User is deprecated since 2.x in favor of explicit implementation of Sonata\IntlBundle\Timezone\TimezoneAwareInterface.

If the SonataUserBundle is enabled, it returns the timezone from the Sonata\UserBundle\Model\User::getTimezone() method.

2.1.2. Locale timezone detector

The timezone is guessed from the current request locale. You can configure the locale / timezone mapping in the configuration:

  • YAML
    1
    2
    3
    4
    5
    6
    7
    # config/packages/sonata_intl.yaml
    
    sonata_intl:
        timezone:
            locales:
                fr:    Europe/Paris
                en_UK: Europe/London
    

2.1.3. Configure timezone detectors

By default, user then locale timezone detectors are used. You can change the order in the configuration:

  • YAML
    1
    2
    3
    4
    5
    6
    7
    # config/packages/sonata_intl.yaml
    
    sonata_intl:
        timezone:
            detectors:
                - sonata.intl.timezone_detector.user
                - sonata.intl.timezone_detector.locale
    

IMPORTANT In order to guess the timezone, the detectors will be called in the order they are declared.

2.1.4. Default timezone

If no timezone was returned by any detector, a default one will be returned (from the date_default_timezone_get() method, configurable in the php.ini file).

You can override this default timezone in the configuration:

  • YAML
    1
    2
    3
    4
    5
    # config/packages/sonata_intl.yaml
    
    sonata_intl:
        timezone:
            default: Europe/Paris