EasyAdmin 3 datetime picker time format - symfony

How to change native easy admin 3 in symfony date/time picker time format? It now renders month, day, year. How do you set to 'Y-m-d H:i'?

If you look in the source code for the DateTimeField you will find a setFormat method that accepts a valid ICU Datetime Pattern (see http://userguide.icu-project.org/formatparse/datetime).
The format of a native date picker is determined by the browser's native code and locale settings, you cannot change it with out some complicated scripting (see here). This may possibly update the format of a choice or text type (not tested).
Try something like this:
use EasyCorp\Bundle\EasyAdminBundle\Field\DateTimeField;
public function configureFields(string $pageName): iterable
{
return [
// native date picker format cannot be changed
// Uses native HTML5 widgets when rendering this field in forms.
DateTimeField::new('beginsAt')->setFormat('Y-MM-dd HH:mm')->renderAsNativeWidget(),
// Uses <select> lists when rendering this field in forms.
DateTimeField::new('beginsAt')->setFormat('Y-MM-dd HH:mm')->renderAsChoice(),
// Uses <input type="text"> elements when rendering this field in forms.
DateTimeField::new('beginsAt')->setFormat('Y-MM-dd HH:mm')->renderAsText(),
];
}

Related

How can I translate input use ngx-translate?

<input type="text" name="title" [(ngModel)]="dataAdd.titleEN">
<input type="text" name="title" [(ngModel)]="dataAdd.titleFR">
I need to show two title but different language
If I click of button en show text in English or fr show text in French
and save in variable string
Note: I need unique variable for unique data insert in Firestore
dataAdd = {
titleEN: '',
titleFR: '',
}
this.translateList = this.afs.collection('translates');
this.translateList.doc('en').set({
TITLE_FOR_RENT: this.dataAdd.titleEN,
});
this.translateList = this.afs.collection('translates');
this.translateList.doc('fr').set({
TITLE_FOR_RENT: this.dataAdd.titleFR,
});
In my opinion you have assumed wrongly the usage of ngx-translate, this package is used in order to support multiple pre defined languages , for example if you want to support en and fr , beforehand you must have a .json file for each desired language, with the following KvP structure => where the key is a universal key (some string that is the same in each json file), which is used to map values to the translations from the .json files. You can check out the official StackBlitz Demo for detailed example of the usage.
In order to achieve the result that you described, I would suggest to use something like Cloud Translation API provided by Google, which is able to translate live user inputs (or whatever you pass to the API), after that depending on your strategy you might display the response from the API directly to the client, or load it first in the ngx-translate and then display it to the client.
Note:
I would go for the first option, because I assume in your case filling the browser memory is unnecessary (because when loading the translation trough in ngx-translate you are just feeling one big js object behind the scenes)

Vaadin Datefield doesn't recognize weeks in SimpleDateTime formats

My core problem is that I want to show the year's week number and the year itself in a Vaadin date-field. For example the user picks the 6th February 2018. The date-field should format its value like "06 2018".
As I understood the documentation of Vaadin 7.7.13, this should easily possible with:
public class CalendarWeekField extends DateField {
public CalendarWeekField() {
super();
this.setLocale(UI.getCurrent().getLocale());
this.setDateFormat("ww yyyy");
this.setShowISOWeekNumbers(true);
}
Please recognize the line this.setDateFormat("ww yyyy"); since it contains the actual "magic".
The date and time are normally displayed according to the default
format for the current locale (see Locale). You can specify a custom
format with setDateFormat(). It takes a format string that follows the
format of the SimpleDateFormat in Java.
However, following the above example, the output of the DateField is only " 2018".
What do I need to consider to get the year's week numbers displayed?
Consulted documentations:
Java SimpleDateFormat
Vaadin Date and Time Input with DateField - Date and Time Format
Vaadin 7.7.13 API Documentation DateField - setDateFormat(...)
I would call this a bug, your code is fine. You can even "fiddle around" with their live sampler (hit properties -> date format), the field excepts most date patterns but ww (and apparently some timezone-properties). File a bug report maybe?
Maybe you can walk around it by applying a change listener and using .setText() yourself? You would not need to extend the DateField in that case (actually there is no need to extend the field in the first place, simply create and set your properties).

What is the standard way to get/set datetime from fluid in typo3 flow?

What is the standard way to get/set datetimes to/from fluid in typo3 flow?
Is there editable html field which - like a basic f:form.textfield - will allow the datetime to be entered, edited and persisted?
I know I can display a datetime with eg
<f:format.date format="d.m.Y - H:i:s">{productArticle.classdate}</f:format.date>
but in that case the value is null nothing gets displayed and no entry is possible anyway. Does property work with f:format.date in some version? I get "property not registered" when I try it.
Or do I need to have two fields on my page, one for date and one for time, that I put together in the Action?
Thanks
I'm not sure if it's standard way, and personally I don't like it.. but it can be done like this:
In Fluid for new/edit actions:
<f:form action="create" objectName="girlfriend">
...
<f:form.textfield property="birthDate" placeholder="1991-12-30 - 18:25:58" value="{newGirlfriend.birthDate->f:format.date(format:'Y-m-d - H:i:s')}" />
...
</f:form>
In your controller you can add initialize*Action and update propertyMappingConfiguration for \DateTime if standard isn't good for you (it has to be done for both create and update action):
public function initializeCreateAction() {
$mappingConfig = $this->arguments['girlfriend']->getPropertyMappingConfiguration();
$mappingConfig->forProperty('birthDate')->setTypeConverterOption(
'TYPO3\Flow\Property\TypeConverter\DateTimeConverter',
\TYPO3\Flow\Property\TypeConverter\DateTimeConverter::CONFIGURATION_DATE_FORMAT,
'Y-m-d - H:i:s'
);
}
Sometimes it's easier to not pass object directly to controller but create it on service layer. You can also take a look at TypeConverters - they do not require initializeActions and you can easily override existing ones setting higher priority..

Date format upon retrieval

I am trying to retrieve dates from database in a recordset and print dates in mm/dd/yy mm:ss format in the view. Is it possible to intercept data in the model while retrieval and do formatting there instead of looping over recordset in the controller and reformatting dates in the controller before sending it to the view.
Is there a way in handlebars to format dates in the view without writing a helper function ?
Please help.
Thank you.
To format all my data, I created a service "utils" and pass it formatting libraries like moment.js. Your question asked if the handlebars could do this, and I don't know, but this method gives you the freedom to utilize any library. Reference http://sailsjs.org/#/documentation/concepts/Services
this "utilService" has a few libraries that help with formatting.
// utilService.js - in api/services
var changeCase = require("change-case"),
moment = require("moment"),
numeral = require("numeral");
module.exports = {
numeral : numeral,
moment : moment,
changeCase : changeCase
}
then I can use it in my view pages as utilService.moment(DATE).format('YYYY-MM-DD')

Custom date format (callback with php logic)

I want to create a dynamic php date format. Example: show the time of the node if it was published today and only the day/month when older then today. I want this format to be available throughout Drupal like the other predefined date formats in Drupal (not just on theme level).
I found the (D7 only) hook for hook_date_format_types but even that one doesn't seem to allow for a callback where I could define this PHP logic.
Does anyone know which hook would make this possible? Or a module which does this?
In Drupal6, format_date() has the dates and times hardcoded. Also, format_date() does not allow callbacks, but it does allow a custom string. That is where you can apply a trick: instead of hardcoding the string in there, you call a function that returns a string.
function mydate_format($timestamp) {
$now = time();
if (($now - $timestamp) < (60*60*24)) {
return "H:i";
}
else {
return "d:m:Y";
}
}
print format_date($timestamp, 'custom', mydate_format($timestamp));
The second option is to re-define a date-timestamp, but that is both hackish and limited. Date-formats are defined with variable_get(), but don't pass the timestamp along; so your example of switching formats based on the value of timestamp is not possible this way.
In settings.php:
$conf['date_format_long'] = $conf['debug'] ? 'r' : 'l, F j, Y - H:i';
This will switch from one value to another, based on whether your settings.php has a flag "debug" set to TRUE or not. As mentioned: the use for this is limited, since you cannot get any context.
The third alternative is to use Date API which offers onlinle configurable time-formats. But that is both clumsy and insecure (inputting executable PHP in your database). It also depends on a very large module-set. And has the same downside as the first solution: you cannot use format_date, but must use a modified function call, instead of format_date(). See all the options at The Drupal.org date themeing handbook.
GOTCHA In all cases Drupal will not call this function for cached content. If you want to have the dates really dynamic you either need to avoid caching alltogether, or implement the date-formatting in clientside javascript.
TL;DR: You cannot have dynamic date-formats without changing some of the code on theme-level. Using a callback-function to generate the "custom" dateformat is the simplest, working solution.
You can use Date API module to add your custom date formatting. Date API module is inside the Date module. After enabling the Date API module you can go the path "admin/settings/date-time/formats/add" to add your custom format.
"admin/settings/date-time/formats/configure" is the path to configure date formats.
Have a look at these. Happy coding.
Thanks
RT
You can go to node.tpl.php(possibly in sites/all/themes/theme_name/node.tpl.php). Here yo can find $created variable, to reformat date you can use your custom function and change the $created as you want.After this all nodes will use your formatted dates.
Regatds,
Chintan.
Use the features module. Create a feature.
In the resulting feature module, on the [feature].module file, create a hook_nodeapi function and format the field with a conditional statement that takes into account the current date() for how the date will be displayed and feed it into the $node->content var.
And that is the way rockstars would do it (-;

Resources