Hi

When I declare a 'date' field as follows, it is ignored when I am at Set import options (step 5 of 8) and I still shows the default date format 'Y-m-d H:i' instead of my custom date format 'n/j/Y':

    $fields['project_calendar_requested_end_date'] = array(
      'title' => t('Project Requested End Date'),
      'group' => t('Project information'),
      'default_value' => 0,
      'input_format' => 'date',
      'date_format' => 'custom',
      'date_custom' => 'n/j/Y',
      'weight' => $weight++,
    );

What gives?

Help would be much appreciated.

Thanks

Jeff in Seattle

Comments

Robrecht Jacques’s picture

Title: date_format & date_custom are ignored » custom date_format & date_custom in field definition
Category: bug » feature

Right. It makes sense to have this 'date_format' and 'date_custom' to correctly set the default value on the options page. Currently this is not implemented, but it seems logical compared to being able to specify a different default multiple_separator or hierarchy_separator in the field definition.

So, currently this is ignored. Setting it as feature.

jeff00seattle’s picture

Issue tags: +custom input_format

So, even though it is not being set within the Options page, then if I skipped over the Options page and onto the Validation page, then could the 'date_format' and 'date_custom' settings still be used to data validation.

The reason I ask is that my data has a large number (20) of custom dates 'n/j/Y', and enter them in every time I do an import (or explaining it to customers that will be using this site that they will have to enter) will be a pain.

HOWEVER, just at this moment I had an idea!!!
IS IT POSSIBLE...That I should create a custom 'date' input_format, called 'date_n_j_Y', that SKIPS the Options Page and only validates dates that are in the 'n/j/Y' date format???

Just a thought

Jeff in Seattle

Robrecht Jacques’s picture

With hook_node_import_fields_alter() you could set input_format to "my_own_date" and then the options would disappear. Because the "process" function node_import_check_date() is still attached, it would still check the dates. The way to set what format to use would then be to implement a hook_node_import_options() and act on "my_own_date" to set hidden form elements "date_format" and "date_custom". This way, you don't get the options while the conversion is still run.

Another way is with hook_node_import_options_alter() and set a different #default_value ('n/j/Y') for the "date_format" and "date_custom" form elements. Maybe this would be best.

The code in node_import_fields()/_options() is hardcoded at the moment for the builtin input_formats. It would be better if this is moved somewhere else and be better configurable, eg:
- there should be an easier way to set a default custom date format that one would want to use for each import. Maybe remember the last inputted one or have some setting.
- same with multiple/hierarchical separators,