src/Common/Controller/Base.php
protected function instantiateDateTime()
    {
        $oDateTimeService = Factory::service('DateTime');

        //  Define default date format
        $oDefaultDateFormat = $oDateTimeService->getDateFormatDefault();

        if (empty($oDefaultDateFormat)) {
            throw new NailsException(
                'No default date format has been set, or it\'s been set incorrectly.',
                1
            );
        }

        Functions::define('APP_DEFAULT_DATETIME_FORMAT_DATE_SLUG', $oDefaultDateFormat->slug);
        Functions::define('APP_DEFAULT_DATETIME_FORMAT_DATE_LABEL', $oDefaultDateFormat->label);
        Functions::define('APP_DEFAULT_DATETIME_FORMAT_DATE_FORMAT', $oDefaultDateFormat->format);

        //  Define default time format
        $oDefaultTimeFormat = $oDateTimeService->getTimeFormatDefault();

        if (empty($oDefaultTimeFormat)) {
            throw new NailsException(
                'No default time format has been set, or it\'s been set incorrectly.',
                1
            );
        }

        Functions::define('APP_DEFAULT_DATETIME_FORMAT_TIME_SLUG', $oDefaultTimeFormat->slug);
        Functions::define('APP_DEFAULT_DATETIME_FORMAT_TIME_LABEL', $oDefaultTimeFormat->label);
        Functions::define('APP_DEFAULT_DATETIME_FORMAT_TIME_FORMAT', $oDefaultTimeFormat->format);

        // --------------------------------------------------------------------------

        /**
         * Set the timezones.
         * Choose the user's timezone - starting with their preference, followed by
         * the app's default.
         */

        if (activeUser('timezone')) {
            $sTimezoneUser = activeUser('timezone');
        } else {
            $sTimezoneUser = $oDateTimeService->getTimezoneDefault();
        }

        $oDateTimeService->setTimezones('UTC', $sTimezoneUser);

        // --------------------------------------------------------------------------

        //  Set the user date/time formats
        $sFormatDate = activeUser('datetime_format_date');
        $sFormatDate = $sFormatDate ? $sFormatDate : APP_DEFAULT_DATETIME_FORMAT_DATE_SLUG;

        $sFormatTime = activeUser('datetime_format_time');
        $sFormatTime = $sFormatTime ? $sFormatTime : APP_DEFAULT_DATETIME_FORMAT_TIME_SLUG;

        $oDateTimeService->setFormats($sFormatDate, $sFormatTime);

        // --------------------------------------------------------------------------

        //  Make sure the database is running on UTC
        $oDb = Factory::service('Database');
        $oDb->query('SET time_zone = \'+0:00\'');
    }
protected function instantiateDateTime()
    {
        $oDateTimeService = Factory::service('DateTime');

        //  Define default date format
        $oDefaultDateFormat = $oDateTimeService->getDateFormatDefault();

        if (empty($oDefaultDateFormat)) {
            throw new NailsException(
                'No default date format has been set, or it\'s been set incorrectly.',
                1
            );
        }

        Functions::define('APP_DEFAULT_DATETIME_FORMAT_DATE_SLUG', $oDefaultDateFormat->slug);
        Functions::define('APP_DEFAULT_DATETIME_FORMAT_DATE_LABEL', $oDefaultDateFormat->label);
        Functions::define('APP_DEFAULT_DATETIME_FORMAT_DATE_FORMAT', $oDefaultDateFormat->format);

        //  Define default time format
        $oDefaultTimeFormat = $oDateTimeService->getTimeFormatDefault();

        if (empty($oDefaultTimeFormat)) {
            throw new NailsException(
                'No default time format has been set, or it\'s been set incorrectly.',
                1
            );
        }

        Functions::define('APP_DEFAULT_DATETIME_FORMAT_TIME_SLUG', $oDefaultTimeFormat->slug);
        Functions::define('APP_DEFAULT_DATETIME_FORMAT_TIME_LABEL', $oDefaultTimeFormat->label);
        Functions::define('APP_DEFAULT_DATETIME_FORMAT_TIME_FORMAT', $oDefaultTimeFormat->format);

        // --------------------------------------------------------------------------

        /**
         * Set the timezones.
         * Choose the user's timezone - starting with their preference, followed by
         * the app's default.
         */

        if (activeUser('timezone')) {
            $sTimezoneUser = activeUser('timezone');
        } else {
            $sTimezoneUser = $oDateTimeService->getTimezoneDefault();
        }

        $oDateTimeService->setTimezones('UTC', $sTimezoneUser);

        // --------------------------------------------------------------------------

        //  Set the user date/time formats
        $sFormatDate = activeUser('datetime_format_date');
        $sFormatDate = $sFormatDate ? $sFormatDate : APP_DEFAULT_DATETIME_FORMAT_DATE_SLUG;

        $sFormatTime = activeUser('datetime_format_time');
        $sFormatTime = $sFormatTime ? $sFormatTime : APP_DEFAULT_DATETIME_FORMAT_TIME_SLUG;

        $oDateTimeService->setFormats($sFormatDate, $sFormatTime);

        // --------------------------------------------------------------------------

        //  Make sure the database is running on UTC
        $oDb = Factory::service('Database');
        $oDb->query('SET time_zone = \'+0:00\'');
    }
protected function instantiateDateTime ( ) { $ oDateTimeService = Factory :: service ( 'DateTime' ) ; //  Define default date format $ oDefaultDateFormat = $ oDateTimeService -> getDateFormatDefault ( ) ; if ( empty ( $ oDefaultDateFormat ) ) { throw new NailsException ( 'No default date format has been set, or it\'s been set incorrectly.' , 1 ) ; } Functions :: define ( 'APP_DEFAULT_DATETIME_FORMAT_DATE_SLUG' , $ oDefaultDateFormat -> slug ) ; Functions :: define ( 'APP_DEFAULT_DATETIME_FORMAT_DATE_LABEL' , $ oDefaultDateFormat -> label ) ; Functions :: define ( 'APP_DEFAULT_DATETIME_FORMAT_DATE_FORMAT' , $ oDefaultDateFormat -> format ) ; //  Define default time format $ oDefaultTimeFormat = $ oDateTimeService -> getTimeFormatDefault ( ) ; if ( empty ( $ oDefaultTimeFormat ) ) { throw new NailsException ( 'No default time format has been set, or it\'s been set incorrectly.' , 1 ) ; } Functions :: define ( 'APP_DEFAULT_DATETIME_FORMAT_TIME_SLUG' , $ oDefaultTimeFormat -> slug ) ; Functions :: define ( 'APP_DEFAULT_DATETIME_FORMAT_TIME_LABEL' , $ oDefaultTimeFormat -> label ) ; Functions :: define ( 'APP_DEFAULT_DATETIME_FORMAT_TIME_FORMAT' , $ oDefaultTimeFormat -> format ) ; // -------------------------------------------------------------------------- /**
         * Set the timezones.
         * Choose the user's timezone - starting with their preference, followed by
         * the app's default.
         */ if ( activeUser ( 'timezone' ) ) { $ sTimezoneUser = activeUser ( 'timezone' ) ; } else { $ sTimezoneUser = $ oDateTimeService -> getTimezoneDefault ( ) ; } $ oDateTimeService -> setTimezones ( 'UTC' , $ sTimezoneUser ) ; // -------------------------------------------------------------------------- //  Set the user date/time formats $ sFormatDate = activeUser ( 'datetime_format_date' ) ; $ sFormatDate = $ sFormatDate ? $ sFormatDate : APP_DEFAULT_DATETIME_FORMAT_DATE_SLUG ; $ sFormatTime = activeUser ( 'datetime_format_time' ) ; $ sFormatTime = $ sFormatTime ? $ sFormatTime : APP_DEFAULT_DATETIME_FORMAT_TIME_SLUG ; $ oDateTimeService -> setFormats ( $ sFormatDate , $ sFormatTime ) ; // -------------------------------------------------------------------------- //  Make sure the database is running on UTC $ oDb = Factory :: service ( 'Database' ) ; $ oDb -> query ( 'SET time_zone = \'+0:00\'' ) ; }
Sets up date & time handling

@throws NailsException
Sets up date & time handling