1. Create a custom timezone detector

You can create and add your own timezone detector.

1.1. Create the detector class

Todo:
  • add example class called MyCustomTimezoneDetector

1.2. Add the Service

Create a service with the sonata_intl.timezone_detector tag with a custom alias.

# config/services.yaml

services:
    app.my_custom_timezone_detector:
        class: App\TimezoneDetector\MyCustomTimezoneDetector
        tags:
            - { name: sonata_intl.timezone_detector }

1.3. Add the detector to the Configuration

You can now use this class by configuring the detector section:

# config/packages/sonata_intl.yaml

sonata_intl:
    timezone:
        detectors:
            - app.my_custom_timezone_detector
            - sonata.intl.timezone_detector.user
            - sonata.intl.timezone_detector.locale_aware

Important

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