Where do I find documentation on the Date HTML5 Widget programming from module?

I've cobbled together this sort of thing from D7 sources, but the timezone stuff is consistently wrong:
 

$node->field_status_changed[LANGUAGE_NONE][0] = array(

'value' => format_date(strtotime('now'), 'custom', 'Y-m-d H:i:s', '+1300'),

'timezone' => '+1300',

'timezone_db' => '+1300',

);

Accepted answer

One more thing:

In order to correctly set the time in the field structure, you MUST use UTC time. So your date_format call should look like:

format_date(strtotime('now'), 'custom', 'Y-m-d H:i:s', 'UTC');

Notice the UTC.

Most helpful answers

Yes, what you posted above is a datetime field type. It says so under "date_type". You can use the structure you posted to set the value of the field in the node object.

Hi onyx.

I believe you are misunderstanding what a widget is, and confusing that with what a date field is.

There is a difference between a "date field" and a "date field widget". The widget is just the form portion that is used to collect a date from the user. A "date field" can use different types of widgets: date_html5, date_select, date_text and date_popup (all of them defined in date_field_widget_info()).

So, after entering the date through a form widget, the processors transform that information into a standard structure that gets stored in the date field table.

When you load a node, the date field structure is "attached" to the node object.

From what you posted, I gather you want to programmatically set a value for a date field attached to a node. To do that, you only need to know the field structure for the date fields (there is no reason to know anything about the HTML5 widget to do that).

Now, there are three types of date field types:

  •  datetime
  • date (ISO format)

  • datestamp (Unix timestamp)

All three of them use slightly different structures when attached to a node object. See image:

 

So, you see, if you want to programmatically set the date field for the node, first you need to now what type of date field you have in that node, then use any of the structures above. The timezone identifiers are all listed here.

Now, perhaps I'm misunderstanding what you want to do...

BTW, this is how I obtained what you see above in the picture:

1. I attached 3 date fields to the Page content type

2. I created a node and enter values in the fields

3. In the Devel PHP page I did dpm(node_load(NID));

Comments

Hi onyx.

I believe you are misunderstanding what a widget is, and confusing that with what a date field is.

There is a difference between a "date field" and a "date field widget". The widget is just the form portion that is used to collect a date from the user. A "date field" can use different types of widgets: date_html5, date_select, date_text and date_popup (all of them defined in date_field_widget_info()).

So, after entering the date through a form widget, the processors transform that information into a standard structure that gets stored in the date field table.

When you load a node, the date field structure is "attached" to the node object.

From what you posted, I gather you want to programmatically set a value for a date field attached to a node. To do that, you only need to know the field structure for the date fields (there is no reason to know anything about the HTML5 widget to do that).

Now, there are three types of date field types:

  •  datetime
  • date (ISO format)

  • datestamp (Unix timestamp)

All three of them use slightly different structures when attached to a node object. See image:

 

So, you see, if you want to programmatically set the date field for the node, first you need to now what type of date field you have in that node, then use any of the structures above. The timezone identifiers are all listed here.

Now, perhaps I'm misunderstanding what you want to do...

BTW, this is how I obtained what you see above in the picture:

1. I attached 3 date fields to the Page content type

2. I created a node and enter values in the fields

3. In the Devel PHP page I did dpm(node_load(NID));

Lovely detailed answer, thank you!

is my field, which I suspect is the Datetime? How do you tell??
 

The aim is merely to have the status update I am triggering change the date of this field according to where the update is happening within the code execution. That part was working, but I was getting weird times appearing for when it was updated; in the future. So I knew it had to be something to do with the timezone handling, which is why I wanted to find out whether and where the D7 posts on this still stood.

Yes, what you posted above is a datetime field type. It says so under "date_type". You can use the structure you posted to set the value of the field in the node object.

As for the "timezone" and "timezone_db" elements: the dates are stored in the database using UTC (timezone_db). So, if you inspect the DB directly, you'll see a date and time that typically doesn't match yours (unless you live in the UK). The "timezone" element is the timezone where that date will be converted to. 

On Backdrop, sites can use the site's timezone, or you can configure it to allow users to set their own timezones. So, the "timezone" element will match either the site's TZ, or the user's TZ.

One more thing:

In order to correctly set the time in the field structure, you MUST use UTC time. So your date_format call should look like:

format_date(strtotime('now'), 'custom', 'Y-m-d H:i:s', 'UTC');

Notice the UTC.

Thanks, that's something that surely must be documented ??

And that, my friend is the answer! xoxoxox ;-)