Giter Club home page Giter Club logo

Comments (3)

Slamdunk avatar Slamdunk commented on July 29, 2024

I didn't know about date formatting resulting in non-numbers 😮

I'd say you have more knowledge about this topic than me: may you open a PR with related new tests, and see if all other tests still pass?

from laminas-form.

pine3ree avatar pine3ree commented on July 29, 2024

@Slamdunk I didn't know, or suspected, either (been using php since 2001 😄 ). I always assumed that hours, minutes and seconds formatting options could only result in non-zerofilled and zerofilled int strings. At first I thought that the IntlDateFormatter was being used just for symmetry with the label (array value) formatter, to have a more elegant/consistent code. Curiosity made me try it with all avaiable locales... I haven't used selects for date/time inputs in years, but while creating a Plates extensions for laminas-form, I had to examine laminas-form-view-helpers related code more thoroughly. There is also another inconsistency. The year select element has both numeric keys (select-option-values) and values (select-option-labels). It should have intl-formatted values values.

There is only one test checking the formatted selects in es_CL. We would need tests checking that all the <option value=""> parts only contain 2 or 4 digits strings and no other chars, allowing the presented label to be locale-formatted

<?php

// INSTALL libs
// $ composer require laminas/laminas-form
// $ composer require laminas/laminas-i18n
// $ composer require laminas/laminas-view

use Laminas\Form\ConfigProvider;
use Laminas\Form\Element\DateTimeSelect;
use Laminas\Form\View\Helper\FormDateTimeSelect;
use Laminas\View\Renderer\PhpRenderer;

$locale = 'ar';

//Locale::setDefault($locale);
//setlocale(LC_ALL, $locale);

ini_set('display_errors', 'true');

$__dir = __DIR__;

require "{$__dir}/vendor/autoload.php";


$view                = new PhpRenderer();
$helperPluginManager = $view->getHelperPluginManager();
$viewHelperConfig    = (new ConfigProvider())->getViewHelperConfig();
$helperPluginManager->configure($viewHelperConfig);
$view->setHelperPluginManager($helperPluginManager);

$formDateTimeSelect = new FormDateTimeSelect();
$formDateTimeSelect->setView($view);


$datetimeField = new DateTimeSelect('createdAt');

$html = $formDateTimeSelect(
    $datetimeField,
    IntlDateFormatter::LONG,
    IntlDateFormatter::LONG,
    $locale
);

die("\n{$html}\n");

from laminas-form.

pine3ree avatar pine3ree commented on July 29, 2024

Hello @Slamdunk ,

should I prepare a pull-request for this?
kind regards

PS
We can use a simple sprintf or , since we already have a DateTimeInterface instance, just use the non-localized formatter:

Example for days select-option

    protected function getDaysOptions($pattern, string $locale, int $dateType): array
    {
        $dateFormatter = new IntlDateFormatter($locale, $dateType, IntlDateFormatter::NONE, null, null, $pattern);
        $date          = new DateTime('1970-01-01');

        $result = [];
        for ($day = 1; $day <= 31; $day++) {
            $key   = sprintf('%02d', $day); // 1
            $key   = $date->format('d'); // 2
            $value = $dateFormatter->format($date->getTimestamp());
            $result[$key] = $value;

            $date->modify('+1 day');
        }

        return $result;
    }

from laminas-form.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.