Active
Project:
Date
Version:
7.x-2.x-dev
Component:
Date API
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
1 Feb 2013 at 17:54 UTC
Updated:
1 Feb 2013 at 17:54 UTC
I am trying to work with date fields in PHP and it's quite difficult to do as AFAIK there aren't any functions in the Date API that allow a user to easily convert the field value arrays into DateObjects.
I see in date_formatter_process() there's a hefty chunk of code that parses out field data to get a DateObject
If I'd want to to something similar, I'd have to write at least this much code:
$field = field_info_field("FIELD_DATE_NAME");
foreach ($entity->FIELD_DATE_NAME[LANGUAGE_NONE] as $date) {
$timezone = isset($date['timezone']) ? $date['timezone'] : '';
$timezone = date_get_timezone($field['settings']['tz_handling'], $timezone);
$timezone_db = date_get_timezone_db($field['settings']['tz_handling']);
$db_format = date_type_format($field['type']);
$thisValObj = new DateObject($date['value'], $timezone_db, $db_format);
}
If the API provided field-related functions that gave us DateObjectsfrom entity fields, a lot of copy/pasting could be saved.
Is there already something like this in the API somewhere that I'm just not seeing?