It would be great if this module were to support schema.org formatting: https://schema.org/openingHours , providing this data in the Formatter output.

(This schema.org link discusses the problems with both implementations: https://github.com/schemaorg/schemaorg/issues/245)

The end result of OfficeHoursFormatter.php should look something like this:

<span class="office-hours-display-times office-hours-display-hours">
  <time itemprop="openingHours" datetime="Mo 09:00-17:00">"09:00-17:00"<br /></time>
</span>

or

<meta itemprop="openingHours" content="Mo-Fr 09:00-17:30">Mon-Fri 9am - 5:30pm
<meta itemprop="openingHours" content="Sa 09:00-12:00">Sat 9am - 12pm

The result can be tested on the Structured Data Testing Tools from Build, Test, and Release Your Structured Data

The current D8-version contains already:
- FieldFormatter setting 'Enable Schema.org openingHours support';
- class OfficeHoursFormatterSchema with preset format;

It could be nice to align/integrate it with the following Drupal modules:

  • Schema.org;
  • Schema.org configuration tool (RDF UI), which provides Field support for schema.org formatting, although the formatting of the Office Hours field doesn't match proper schema formatting when "openingHours" is enabled for it. OfficeHours is declared as an Integer, whereas normale Times have DateTimeIso8601

Not sure if this integration needs to be done here or within RDFUI, but it seems like a logical extension of functionality. With RFDUI you can set both the Content type and the Field type.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

jk.badsberg’s picture

Issue summary: View changes

displaying meta code

johnv’s picture

There are more vocabularies around. See https://drupal.org/project/dkan, which points to DCAT, which uses other vocabularies.
Each vocabulary has its own namespace.

So, we can do two things:
- add more settings to the current formatter settings, so we can create the requested format.
- add a list/catalogue of formats, like Schema.org, Google Places, Good Relations

johnv’s picture

Issue summary: View changes

Some more research:
Schema.org gives 2 pages: http://schema.org/OpeningHoursSpecification and http://schema.org/openingHours.
It also says:

This class is derived from the GoodRelations Vocabulary for E-Commerce, created by Martin Hepp. GoodRelations is a data model for sharing e-commerce data on the Web that can be expressed in a variety of syntaxes, including RDFa and HTML5 Microdata. More information about GoodRelations can be found at http://purl.org/goodrelations/.
johnv’s picture

VladSavitsky’s picture

Please take a look at my patch: https://drupal.org/node/2155585

jasonawant’s picture

Hi,

I'd like to help out and provide some patches to push this forward. Can we continue this discussion to map out a path forward?

I understand that you may want to provide a solution that works with multiple microdata formats. How would you like to provide that functionality, as a select (options: Schema.org, in the field settings? Then use this setting to fire off different theme functions or some other processing?

I don't follow you when you said the following in comment #1, What do you mean?

So, we can do two things:
- add more settings to the current formatter settings, so we can create the requested format.
- add a list/catalogue of formats, like Schema.org, Google Places, Good Relations

I'd like to help with the schema.org microdata integration, so that office hours associated with a node return markup like the following. I've done this already by stepping in with hook_theme_registry_alter() to provide my own theme function, but I'd like to work with you all to get this contributed.

Let me know what you think and want to do. Jason.

You can test this out here: http://www.google.com/webmasters/tools/richsnippets.

<div id="node-1" class="node node-location node-promoted node-full clearfix" itemscope="" itemtype="http://schema.org/LocalBusiness">
  <div class="field field-name-field-location-hours field-type-office-hours field-label-above">
    <div class="field-label">Hours: </div>
      <div class="field-items">
        <div class="field-item even">
          <span class="oh-wrapper">
            <span class="oh-display">
              
              <span class="oh-display-label" itemprop="openingHours" content="Mo 9:00-17:00" style="width: 6.6em; ">Monday: </span><span class="oh-display-times oh-display-hours">9:00 am-5:00 pm<br></span></span>
              
              <span class="oh-display"><span class="oh-display-label" itemprop="openingHours" content="Tu 9:00-17:00" style="width: 6.6em; ">Tuesday: </span><span class="oh-display-times oh-display-hours">9:00 am-5:00 pm<br></span></span>
              
              <span class="oh-display"><span class="oh-display-label" itemprop="openingHours" content="We 9:00-17:00" style="width: 6.6em; ">Wednesday: </span>
              
              <span class="oh-display-times oh-display-hours">9:00 am-5:00 pm<br></span></span><span class="oh-display"><span class="oh-display-label" itemprop="openingHours" content="Th 9:00-17:00" style="width: 6.6em; ">Thursday: </span>
              
              <span class="oh-display-times oh-display-hours oh-display-current">9:00 am-5:00 pm<br></span></span>
              
              <span class="oh-display"><span class="oh-display-label" itemprop="openingHours" content="Fr 9:00-17:00" style="width: 6.6em; ">Friday: </span><span class="oh-display-times oh-display-hours">9:00 am-5:00 pm<br></span>
            </span>
          </span>
        </div>
      </div>
    </div>
  </div>
</div>
johnv’s picture

@jwant, I'm happy to implement this, but I'm totally new to this matter.

Regarding #1: perhaps I didn't understand correctly at the time. As i now understand, the Rich snippets are used on a 'normal'node/entity display. Correct?
But I also have xml-feeds, like the one below. i want to send data, and use a convention for it. My need is something like this, where openingHours should use some convention (But perhaps these are two different things):

<store>
<ID>2971</ID>
<address>
  <Street>Rokin 8</Street>
  <City>Amsterdam</City>
  <Country>NL</Country>
</address>
<geo>
  <Latitude>51.1234</Latitude>
  <Longitude>4.1234</Longitude>
</geo>
<openingHours>
2=12:00-18:00;3=9:30-18:00;4=9:30-18:00;5=9:30-21:00;6=9:30-18:00;7=10:00-18:00;1=12:00-17:30;
</openingHours>
</store>

I also do not understand why both OpeningHours and OpeningHoursSpecifications (see http://schema.org/LocalBusiness ) exist next to eachother.

The current formatter only supports 3-letter Weeknames (Thu instead of Th).
I've added a related issue.

jasonawant’s picture

Hi Jonhv,

Sorry so much time has passed.

Regarding #1: perhaps I didn't understand correctly at the time. As i now understand, the Rich snippets are used on a 'normal'node/entity display. Correct?

Yes, that's correct. However, the rich snippets, which ever format, are added to all view modes: full content, teasers, and rss. Although the rich snippets are used with the different view modes, I don't think using a contributed module such as Schema.org or Microdata will offer you the flexibility to have different syntax for different view modes. I think you'll need to use a theme function or template to create your desired xml syntax.

Now that I'm returning to this project, I've discovered another issue. I'm using the Schema.org project for all that is has to offer. It adds RDFa syntax provided by Drupal 7 (see this issue #1606872 for more info), which when combined with the syntax I'm using (itemprop="openingHours") with the Office Hours, Google's Structured Data Testing Tool does not parse the opening hours. The testing tool is expecting itemtype="http://schema.org/LocalBusiness" to parse the opening hours.

I'm going to test the Mircodata contrib module to see how that works out instead.

I've attached a patch file representing the changes I made to office_hours.theme.inc to add the schema.org attributes to the opening hours. Note, this does not work as is. Also note, this approach does not provide the flexibility to choose which format, or offer a configuration option, which i think issue #2155585 attempts.

We may want to mark this issue a duplicate of issue #2155585, and combine efforts.

I'll let you know what I learn from using the Mircodata contrib module.

Jason.

Here's a diff.

diff --git a/office_hours.theme.inc b/office_hours.theme.inc
index ca07afd..0ab331e 100644
--- a/office_hours.theme.inc
+++ b/office_hours.theme.inc
@@ -74,15 +74,31 @@ function theme_office_hours_field_formatter_default($vars) {
         break;
     }
 
+    // Create array to later use to map day of week to schema.org day abbreviations
+    $day_map = array(
+      'Su' => 0,
+      'Mo' => 1,
+      'Tu' => 2,
+      'We' => 3,
+      'Th' => 4,
+      'Fr' => 5,
+      'Sa' => 6
+    );
+
+    // Set schema.org day and times
+    $da = array_search($day, $day_map);
+    $start_time = date("G:i", strtotime($info['times'][0]['start']));
+    $end_time = date("G:i", strtotime($info['times'][0]['end']));
+
     // Generate HTML for Hours.
     $HTML_hours .= '<span class="oh-display">'
-//             . '<span class="oh-display-label">'
-               . '<span class="oh-display-label" style="width: ' . ($max_label_length * 0.60) . 'em; ">'
+               . '<span class="oh-display-label"'
+               . 'style="width: ' . ($max_label_length * 0.60) . 'em;">'
                . $info['output_label']
                . '</span>'
                . '<span class="oh-display-times oh-display-' . (!$info['times'] ? 'closed' : 'hours')
-               . ($info['current'] ? ' oh-display-current' : '')
-               . '">'
+               . ($info['current'] ? ' oh-display-current"' : '"')
+               . ($info['times'] ? ' itemprop="openingHours" content="' . $da . ' ' . $start_time . '-' . $end_time . '">' : '>')
                . $info['output_times'] . $settings['separator_days']
                . '</span>'
                . '</span>';
jasonawant’s picture

Hi,

Well, using Mircodata would get us there I suppose, but there are a lot of other obstacles dissuading me from using it.

There are many patches that need application to work with addressfield, panels, etc. And, the project is minimally maintained without a commit by the maintainer since 7 months ago.

I'm going to revisit the schema.org contrib path I was on earlier. Jason.

jasonawant’s picture

Status: Active » Needs review
FileSize
2.38 KB

Hi,

So, I was originally mixing the formats, using RDFa that Drupal 7 provides to the contributed schema.org module and format specified by the schema.org example.

The GoodRelations specifications provide examples of both Mircodata and RDFa.

I've refactored the code to use the RDFa format. However, I think this is quite messy. And, as I've previously noted, forces one format over the another.

Please let me know what you think.

jasonawant’s picture

Version: 7.x-1.3 » 7.x-1.x-dev

The patches above are against 7.x-1.x.

jasonawant’s picture

Did I say it was messy? I removed the dsm() call.

scor’s picture

Status: Needs review » Needs work

The RDFa output looks and up to standard with http://www.heppnetz.de/ontologies/goodrelations/v1.html#OpeningHoursSpec... - that's also aligned with for example this Best Buy opening hours: http://stores.bestbuy.com/1088/

Feedback on the patch:

  1. +++ b/office_hours.theme.inc
    @@ -74,16 +74,40 @@ function theme_office_hours_field_formatter_default($vars) {
    +    // Create array to later use to map day of week to schema.org day abbreviations
    +    $day_map = array(
    +      'Sunday' => 0,
    +      'Monday' => 1,
    +      'Tuesday' => 2,
    +      'Wednesday' => 3,
    +      'Thursday' => 4,
    +      'Friday' => 5,
    +      'Saturday' => 6
    +    );
    +
    +    // Set schema.org day and times
    +    $da = array_search($day, $day_map);
    

    If you reverse the $day_map array, you don't need the $da variable at all, just call $day_map[$day] further down in $HTML_hours = ...

  2. +++ b/office_hours.theme.inc
    @@ -74,16 +74,40 @@ function theme_office_hours_field_formatter_default($vars) {
    +               . '<span class="oh-display-label" rel="gr:hasOpeningHoursDayOfWeek"
    +          resource="http://purl.org/goodrelations/v1#' . $da . '"'
    

    These two line should probably stay on the same line, even if it's a bit long, the code will be more readable IMO.

jasonawant’s picture

Status: Needs work » Needs review
FileSize
2.46 KB

Thanks for the feedback. I've attached an updated patch. Jason.

scor’s picture

So I tested the patch again, and it assumes the first day is Sunday, so the map would need to be adjusted somehow. The first day of the week to be displayed is stored in the settings as 'date_first_day'. Also, multiple blocks are not displayed with the patch (for example if you have Monday 9am-1pm and 2pm-5pm the same day). In this case, the gr:OpeningHoursSpecification for the same day has to be repeated for each time slot (for example if there is a lunch break). You might have to move the GR markup generation further up where $info['output_times'] is set...

Keep up the good work, @jwant, we're almost there!

jasonawant’s picture

Ok, well I have figured out how to account for the different first day of week setting by using $day_map[$info['startday']].

- . '<span class="oh-display-label" rel="gr:hasOpeningHoursDayOfWeek" resource="http://purl.org/goodrelations/v1#' . $day_map[$day] . '"
+ . '<span class="oh-display-label" rel="gr:hasOpeningHoursDayOfWeek" resource="http://purl.org/goodrelations/v1#' . $day_map[$info['startday']] . '"'

Yeah, there is lots of flexibility with the display formatter. In addition to the displaying multiple hour blocks, there's also these settings, "Group consecutive days with same hours into one set" and "Compress all hours of a day into one set". I'm digging in.

johnv’s picture

Gentlemen,
for your information: I've committed a fix and some code style issue. It included the file at hand. Please update to latest dev.

If you get this RTBC, I'll commit it by the end of this month.

jasonawant’s picture

Hi,

Here's another try at it. I patched office_hours.module as well to set 'endday', so I could use this info in logic later on the down the road. As a result, I updated the logic to set the $label variable.

Let me know if you don't like this approach or if I've missed something that this change impacts.

Please let me know if there's a better way of doing any of this that you see. Thanks, Jason.

johnv’s picture

Some additions:
- #2155585: Add schema.org/hoursAvailable microdata for office_hours hints to the fact that we not only have openingHours (for locations) , but also hoursAvailable (for persons, things)
- The patch doesn't supply the (apparently optional) link to the schema.org item type:

<div itemscope itemtype="http://schema.org/LocalBusiness">

 <div itemprop="openingHoursSpecification" itemscope itemtype="http://schema.org/OpeningHoursSpecification">
   Open Monday through Saturday from 8 am to 6:30 pm
   <meta itemprop="dayOfWeek" content="Monday Tuesday Wednesday Thursday Friday  Saturday"/>
   <meta itemprop="opens" content="08:00"/>
   <meta itemprop="closes" content="18:30"/>
 </div>
SeeWatson’s picture

I'll be creating a patch to add this functionality in to D7 & D8 if the move to template files in the other issue is approved. It will be much easier at that point.

johnv’s picture

Title: Semantic web application - Schema.org » Support 'openingHours' microdata for office_hours (D7)
johnv’s picture

Title: Support 'openingHours' microdata for office_hours (D7) » Add schema.org 'openingHours' microdata for office_hours (D7)
johnv’s picture

Title: Add schema.org 'openingHours' microdata for office_hours (D7) » Add schema.org/openingHours microdata for office_hours (D7)
Component: Code » Code - formatter
johnv’s picture

Title: Add schema.org/openingHours microdata for office_hours (D7) » Add schema.org/openingHours microdata for office_hours [META][D7]
Issue summary: View changes
johnv’s picture

johnv’s picture

Issue summary: View changes
johnv’s picture

Issue summary: View changes
johnv’s picture

Issue summary: View changes
johnv’s picture

Issue summary: View changes
johnv’s picture

Title: Add schema.org/openingHours microdata for office_hours [META][D7] » Add schema.org/openingHours microdata for office_hours [META] (+D7 patch)
Issue summary: View changes
johnv’s picture

Issue summary: View changes
johnv’s picture

Title: Add schema.org/openingHours microdata for office_hours [META] (+D7 patch) » Add schema.org/openingHours(Specification) microdata for office_hours [META] (+D7 patch)
Status: Needs review » Fixed

Closing all D7 requests, since I cannot maintain this anymore.

Closing this META ticket, since openingHours is now implemented in version 8.x-1.6.
As it occurs to me now, the patch #17 is implementing openingHoursSpecifications, not openingHours.

Please open a new ticket if we want to continue this D8.

Thanks.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.