Symfony change value of days in form - forms

I have a problem with the form in symfony.
I have English names of the days but I would like them to be in Polish. I changed the range of the years, but the names of the days I can't
-> add ('DateOfBirth', 'date', array (
'years' => range (date ('Y') - 100, date ('Y'))
))
Any clue?

You can pass option format to change the date format itself. In this way you can make that months would be integer numbers, not full names.
When formatting, the DateType takes locale as the default: \Locale::getDefault(). So you just need to change the default locale. It is set in the parameters.ini/parameters.yml file or set via the routing or in other ways if you support multiple languages.
I suggest to look for more details in the implementation class:
https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Form/Extension/Core/Type/DateType.php

Related

Change the date format for the showLastUpdateTime at the bottom of pages

I've added the
showLastUpdateTime: true,
line to my docusaurus.config.js, and the date is showing at the bottom of documents, but the format is US (which doesn't work for the majority of the world). I need it to be unambiguous, or not 'wrong' :D
Does anyone know how I can change this?
I don't believe you can explicitly set the format manually - it uses the default Intl.DateTimeFormat constructor under the hood - however you can manipulate it by setting the base locale of your site to something other than the default.
To do this, you need to leverage the i18n configuration - add this to your docusaurus.config.js:
i18n: {
defaultLocale: 'en-GB',
locales: ['en-GB']
}
Substitute en-GB for whatever your desired locale is, and you'll see the date show in that locale's format, so in the UK it's dd/MM/yyyy.

Date Format - Change format of Month from String to Numeric Value

I would think this is relatively straight forward but cant find documentation on how to do it(or the correct syntax to use) and my messing around hasn't worked so far.
For Dates we have a custom format called Month /Day /Year. This pulls back a the date(as a date type) in date format as such:
"14 April 2003"
The code behind this is:
(DATEPART('year', [Close Date])*10000 + DATEPART('month', [Close Date])*100 + DATEPART('day', [Close Date]))
What I want to get back is the month is numeric format like:
"14.04.2003"
Is it simply changing the "month" part in the code to a different type? Has any one come across this?
Cheers
lampbob, I'd just use date formatting which will mean you will still be able to use all the date-fields flexibility that Tableau provides.
Select Custom format with the following input:
dd.mm.yyyy
See the screen below for more details:
This can be easily achieved using the 'Format' option in Tableau. Here are the steps to follow to format the date field as you have specified.
Add Date field to your Rows/Columns field on a Tableau worksheet.
Set the format of the Date to be DAY(Date).
Click on options for 'DAY(Date)' and go to 'Format...'
On the Format DAY(Date) panel, go to Scale -> Dates.
Select 'Custom' option and type in 'mm.dd.yyyy'. Now the date will be in the string format you need.
Screenshots:
String format for date,
Changing to 'DAY' and 'Format...'
If you are only concerned about how the date is presented, then leave the datatype as a date, and use a custom format string via the format pane to display it as desired.
Followed your advice and just had to change the date pill, in the column field, to a continuous value. Then right clicked -> format -> Scale -> custom. Then used the above suggested format setting. Thanks Petr, woodhead92.

Use localized date format with date picker in cakephp 3

I'm building a cakephp 3 app (cakephp v3.3.2 that is) and I have a problem getting dates displayed in the chosen locale (de_DE).
The database field in my example is invoice_date, which is of type DATE (stored in a mysql DB).
I want to use a date picker in the web page ("zebra_datepicker"), so in the view I use a single text entry field for the date instead of the three drop-downs that are displayed by default:
echo $this->Form->input('invoice_date', [ 'type' => 'text' ]);
To get the date displayed in the German format dd.mm.YY I changed the global locale setting to
ini_set('intl.default_locale', 'de_DE');
in config/bootstrap.php.
For testing, I created a new record in the database and set the invoice_date to 2016-09-02 (Y-M-D).
If I call the edit action of my controller now, I get a default value of 02.09.16 in the form, which is correct. But if I submit the form back, the database value of the field is changed into 2002-09-16!
Do I need some extra code in the controller to change the date format back into its original form? Is this a bug in the localization code of cakephp or did I miss something? Note, that my controller just uses patchEntity to process the posted data.
I already tried adding date('invoice_date', 'dmy') in the validationDefault method of the table object, but this didn't change anything:
$validator
->date('invoice_date', 'dmy')
->requirePresence('invoice_date', 'create')
->notEmpty('invoice_date');
Thanks for your help!
I just found the solution to my problem: in bootstrap.php, I had to add:
Type::build('date')->useLocaleParser();
Type::build('datetime')->useLocaleParser();
With that, I can enter dates like 31.12.16 (d.m.y) and the date gets correctly saved in the database. This works with the simple validator:
$validator
->date('invoice_date')
->notEmpty('invoice_date');
To also support dates like 31.12.2016 (d.m.Y), I had to add an extra parameter to the date validator, like this:
$validator
->date('invoice_date', 'dmy')
->notEmpty('invoice_date');

ZendFramework 2: Locale Currency values in a form

Is there any way to convert how a text input displays a currency in its value in correct locale number format from within the Form construct method or ViewHelper?
e.g.
value from database is 10000.50
In US or UK, is viewed as 10,000.50
In EUR is viewed as 10.000,50
I have been able to do the conversions in controllers, models and views, but haven't come across how do do it here.
Thanks
Aborgrove
You have the Zend\I18n component which ships formatters to format numbers. You can both use the NumberFormat for numbers in general and the CurrencyFormat for specifically currencies.
These formatters are living in the Zend\I18n\View\Helper domain, but are not dependant on the view actually. Therefore, you can just use them anywhere you want:
use Zend\I18n\View\Helper\CurrencyFormat;
$formatter = new CurrencyFormat;
$formatter->setLocale('en-US');
$currency = $formatter(1234.56, 'EUR'); // "€1,234.56"
$currency = $formatter(1234.56, 'USD'); // "$1,234.56"
$formatter->setLocale('nl-NL');
$currency = $formatter(1234.56, 'EUR'); // "€ 1.234,56"
You have to be aware of two things:
The number formatting style is depending on the locale, so supply the correct locale (or set the default locale with Locale::setDefault()).
The "EUR" or "USD" is only for the signs, and together with the locale will be prepended or appended to the number formatted
You can simply use the Zend\I18n\View\Helper\NumberFormat if you only want to format the numbers without any currency code. More information about the formatting is available in the manual.

jquery datepicker date format with output of Zend_Locale

I'm trying to set the format for a jquery datepicker element with the date format returned by Zend_Locale::getTranslationList('date', $locale);
My problem is zend returns the string 'dd/MM/yyyy' for the date format but jquery expects only 2 characters for the year ie 'dd/mm/yy', so it enters the year twice 20112011
Is there some option that can be passed to either zend or jquery to make them work in the same manner? I've read through the docs and can't seem to find anything
Many thanks for your help in advance!
I have used jquery date picker in python-django framework when I give date format as dd/mm/yyyy format it returns 20112011 then i have corrected it to dd/mm/yy and it returned 2011 only. you can specify in your datepicker css class to specify the date format as dd/mm/yy.
Iam not sure if this is what you're looking for but:
// use german local, change it to our needs :-)
$locale = new Zend_Locale('de_DE');
$result = Zend_Locale::getTranslationList('date', $locale);
// returns dd.MM.yy (german!)
echo $result['short'];