Hi, would something like this be useful?
I'm not sure about the check in the validation part.
/**
* @file
* Convert string to timestamp.
*/
$plugin = array(
'form' => 'feeds_tamper_timetodate_form',
'callback' => 'feeds_tamper_timetodate_callback',
'validate' => 'feeds_tamper_timetodate_validate',
'name' => 'PHP Date Format',
'multi' => 'loop',
'category' => 'Text',
);
function feeds_tamper_timetodate_form($importer, $element_key, $settings) {
$form = array();
$form['date_format'] = array(
'#type' => 'textfield',
'#title' => t('PHP Date Format'),
'#default_value' => isset($settings['date_format']) ? $settings['date_format'] : '',
'#description' => t('Format ( eg. d/m/Y )'),
);
return $form;
}
function feeds_tamper_timetodate_callback($result, $item_key, $element_key, &$field, $settings) {
$field = date($settings['date_format'], $field);
}
function feeds_tamper_timetodate_validate(&$settings) {
if (!date($settings['date_format'])) { // Not sure about this...
form_set_error('settings][date_format', t('Format must be in correct php date format.'));
} else {
$settings['date_format'] = (string) $settings['date_format'];
}
}
Comments
Comment #1
twistor commentedLooks good!
A few things:
The name should just be "Date format".
Add a link to http://php.net/manual/en/function.date.php somewhere on the plugin form.
Validation won't do anything, just checking that it's not empty would be enough.
Somewhere on the form it should also mention that it's converting a UNIX timestamp to the date format.
Comment #2
gionnibgud commentedHere you go.
The name now is "Unix timestamp to Date"
Added a better help text with a link to the manual.
Validation now works for empty input and valid date string by doing
cheers
Comment #3
gionnibgud commentedComment #4
twistor commentedFeel free to tell me I'm wrong, but I think date() can output many things that strtotime() can't parse. For example, date() could spit out "It's 10 o'clock Jim." That's why it only ever returns an error when the timestamp is incorrect. There's essentially no input that date() won't accept.
Comment #5
gionnibgud commentedHa! Guess you are right about the date function. You could enter something like this:
date('l jS \of F Y h:i:s A');Ok
Comment #6
gionnibgud commentedComment #7
twistor commentedShebang!
http://drupalcode.org/project/feeds_tamper.git/commit/19515e4
Comment #8
twistor commentedComment #9
twistor commentedComment #10
irgnet commentedThis works perfect when input data is unix timespamp.
But i aggregate several feeds, some feeds using unixtimestamp, other using Date format.
And when i import these feeds with date format, i got errors.
So can you make a validation , which to work only with unix timestamp and skip when input is date format.