schema.org: Multiple opening hours on same day - microdata

I'm building a website for a small store and want to implement schema.org-microdata-markup. The "problem": The store is opened from Tuesday till Friday – from 10:00 till 14:00 AND from 16:30 till 23:00 on these days. So I implemented the opening hours like this…
<time itemprop="openingHours" datetime="Tu-Fr 10:00-14:00, 16:00-23:00">XYZ</time>
But this way, the HTML-validator says…
Bad value Tu-Fr 10:00-14:00, 16:00-23:00 for attribute datetime on element time: The literal did not satisfy the time-datetime format.
How can I implement these multiple opening hours a day? Or is it impossible to do this with the <time>-tag and I have to change it to <meta>-tags? Thanks for your help! :-)

What if you used 2 entries for openingHours?
<time itemprop="openingHours" datetime="Tu-Fr 10:00-14:00">XYZ</time>
<time itemprop="openingHours" datetime="Tu-Fr 16:00-23:00">XYZ</time>

The LocalBusiness example has been updated to use <meta> elements:
<div itemscope itemtype="http://schema.org/Restaurant">
<span itemprop="name">GreatFood</span>
...
Hours:
<meta itemprop="openingHours" content="Mo-Sa 11:00-14:30">Mon-Sat 11am - 2:30pm
<meta itemprop="openingHours" content="Mo-Th 17:00-21:30">Mon-Thu 5pm - 9:30pm
<meta itemprop="openingHours" content="Fr-Sa 17:00-22:00">Fri-Sat 5pm - 10:00pm
</div>

The problem is the notations schema.org uses for openingHours are just not (yet) valid by the HTML5 spec for the time element.
You can copy all the examples from LocalBusiness in the Validator and they will all fail validation.
Until the spec contains a definition to write openingHours in a time element you will have to ignore the HTML validators I'm afraid.
BTW. The text on the schema.org site implies you could defines multiple times in one value:
The opening hours for a business. Opening hours can be specified as a weekly time range, starting with days, then times per day.

I recently ran in to the same issue and found that the second string of hours needs to be on another line like this:
<p><time itemprop="openingHours" datetime="Mo,Tu,We,Th, 08:30-13:30">M-Th 8:30am-12:30pm & 1:30pm-6:00pm</time>
<time itemprop="openingHours" datetime="Mo,Tu,We,Th, 14:30-18:00"></time></p>
It's also important to keep this code inside the closing tag, otherwise it will not register as being formatted correctly.

Related

Displaying time in minutes/hours/days using Carbon or any other tools

I want to convert date to make it like, if i posted comment 2 minutes ago it will show 2 minutes ago, if 2 hours ago, like that, week ago, and so on
<div class="col-md-2">
<p class="text-secondary text-center">{{ $comment->created_at }}</p>
</div>
You need to use diffForHumans()
$comment->created_at->diffForHumans();
https://carbon.nesbot.com/docs/#api-humandiff
You're looking for diffForHumans(), which is a Carbon method for returning a date relative to now. On Model instances, like your Comment class, the attribute created_at should already be converted to a Carbon instance, so you can simply call:
{{ $comment->created_at->diffForHumans() }}
This should return something similar to 1 hour ago, 5 months ago, etc. See https://carbon.nesbot.com/docs/#api-humandiff for full details.

Avoid parentheses in path using XPath 1.0

The following XML structure represents a website with many articles. Every article contains, among many other things, date of its creation and possibly arbitrarily many dates of its modification. I want to get the date of the last access (either creation or last modification) to every article using XPath 1.0.
<website>
<article>
<date><strong>22.11.2017</strong></date>
<edits>
<edit><strong>17.12.2017</strong></edit>
</edits>
</article>
<article>
<date><strong>17.4.2016</strong></date>
<edits></edits>
</article>
<article>
<date><strong>3.5.2011</strong></date>
<edits>
<edit><strong>4.5.2011</strong></edit>
<edit><strong>12.8.2012</strong></edit>
</edits>
</article>
<article>
<date><strong>12.2.2009</strong></date>
<edits></edits>
</article>
<article>
<date><strong>23.11.1987</strong></date>
<edits>
<edit><strong>3.4.2001</strong></edit>
<edit><strong>11.5.2006</strong></edit>
<edit><strong>13.9.2012</strong></edit>
</edits>
</article>
</website>
In other words, the expected output is:
<strong>17.12.2017</strong>
<strong>17.4.2016</strong>
<strong>12.8.2012</strong>
<strong>12.2.2009</strong>
<strong>13.9.2012</strong>
So far I've only created this path:
//article/*[self::date or self::edits/edit][last()]
that looks for date and nonempty edits nodes in every article and selects the latter one. But I don't know how to access the latest strong of every such selection and the naive //strong[last()] appended to the end of the path doesn't work.
I found a solution in XPath 2.0. Either of these paths should work, if I'm not mistaken:
//article/(*[self::date or self::edits/edit][last()]//strong)[last()]
//article/(*//strong)[last()]
Such use of parentheses within path is invalid in XPath 1.0 though.
This XPath 1.0 expression
/website/article/descendant::strong[parent::date|parent::edit][last()]
Selects the nodes:
<strong>17.12.2017</strong>
<strong>17.4.2016</strong>
<strong>12.8.2012</strong>
<strong>12.2.2009</strong>
<strong>13.9.2012</strong>
Tested in http://www.xpathtester.com/xpath/56d8f7bc4b9c8c064fdad16f22469026
Do note: position predicates acts over the context list.
Here is the simple xpath to get your output.
//article/descendant-or-self::strong[last()]

Xpath - how to differentiate nodes without attributes?

I want to extract a value from xml via xpath and I'm struggling a bit. This is the example of xml I have to work with
<data>
<menu>
<date>2017-10-30</date>
<type>S</type>
<name>onion soup</name>
</menu>
<menu>
<date>2017-10-30</date>
<type>L</type>
<name>ham sandwich</name>
</menu>
<menu>
<date>2017-10-31</date>
<type>S</type>
<name>pumpkin soup</name>
</menu>
<menu>
<date>2017-10-31</date>
<type>L</type>
<name>cheese sandwich</name>
</menu>
<menu>
<date>2017-11-1</date>
<type>S</type>
<name>sweet potato soup</name>
</menu>
<menu>
<date>2017-11-1</date>
<type>L</type>
<name>chicken sandwich</name>
</menu>
</data>
The dates and meal names are dynamically changing.
Now I have 2 columns, for Today's soup and Tomorrow's. I know how to link to xml via xpath for today's soup:
/data/menu/name[../type/text() = "S"] or /data/menu[type[text()='S']]/name
But I struggle with tomorrow's as my xml feed doesn't have any attributes to differentiate, types are the same for both dates and date is constantly changing.
Thanks for any help.
Edit:
Thank you for anwering.
I think I described my problem wrong.
I should probably point out that I'm using Xpath build-in feature in one of the local software.
You're right, these lines
/data/menu[type='S' and date='2017-10-31']]/name
are for all the soups, I just wrongly described it by how it behaves on my end, where it gives me just the value of the first one.
/data/menu[type='S' and date='2017-11-01']]/name
will give me Tommorow's soup, but if I want to use output for this value in static column "Tommorow's soup" next to which I want my xpath output it will only be true for one day. What I need is for it to be true also for next days.
I need a line that will give me "tommorow's soup" which is suppose to be Pumpkin soup today, tommorow when the xml updates it would be Sweet Potato soup and day after that it will be some new soup which is going to be updated later with the whole xml.
If I use
/data/menu[type='S' and date='2017-10-30']]/name
it will not show anything tommorow since there won't be a 2017-10-30 because the xml will update and will start with 2017-10-31.
I hope it's clearer now what I'm asking. I know it's still confusing it's kinda hard for me to describe it in English especially since I'm beginner when it comes to Xpath.
How to differentiate elements without attributes? Use other elements...
But first to clear up a wrong assumption:
Now I have 2 columns, for Today's soup and Tomorrow's. I know how to
link to xml via xpath for today's soup:
/data/menu/name[../type/text() = "S"] or
/data/menu[type[text()='S']]/name
Actually, the XPaths that you say will give you today's soups will actually give you all soups regardless of date.
XPath 1.0
XPath 1.0 has no date functions1, so you'll have to pass the current date and tomorrow's date into your XPAth, and you're on your own to test the date element's value as a string:
If today is 2017-10-31, then this XPath will give you the names of today's soups,
/data/menu[type='S' and date='2017-10-31']]/name
and this XPath will give you the names of tomorrow's soups:
/data/menu[type='S' and date='2017-11-1']]/name
1
XPath 2.0 and 3.0's dynamic context includes a current-dateTime() function, but its format is implementation-dependent, which limits its usefulness. You might be able to use date calculations to determine tomorrow's date, but unless you want to be dependent upon an implementation-defined format for current-dateTime(), you'll have to pass today into your XPath at least.

Why does Jquery FullCalendar Not specify an end date as a title when it is 12:00:00AM?

I am getting this data back in a valid json feed.
"start":"10/16/2011 11:00:00 PM","end":"10/16/2011 12:00:00 AM"
My event on the calendar will have
11:00am in the title part but nothing else
(source: gyazo.com)
I am not sure why it is ignoring it.
If I do say 11:59 am it works
(source: gyazo.com)
Any ideas?
The end time 12:00 AM is less than the start time 11:00 PM. So you are having the problem.
12:00 AM would mean the start of the day :)

How can I normalize dates stores using different timezones in XPath?

I have the following times stored in an XML document, which correspond to the time when the document was created and then updated:
<create-time>2010-11-04T03:13:35.212Z</create-time>
<update-time>2010-11-03T20:18:26.331-07:00</update-time>
The document was created at 8:13 pm, and then updated 5 minutes later, at 8:18 pm, but when I show the creation dates with format-dateTime(xs:dateTime(.), '[M]/[D]/[Y]'), I get 11/4/2010 and 11/3/2010, as if the document was updated one day before it was had been created, which is obviously not the case. How can I fix this?
The create-time and update-time in your XML document are correct, but they use different timezones:
create-time is in UTC (also called Zulu time, hence the Z).
update-time is in Pacific time.
This can happen if different pieces of code set this the time, or even from the same code using different libraries or functions. For instance, if you are using XPath from XForms:
Using current-dateTime() uses a timezone from the dynamic context, which is often the current timezone for the machine on which the code is running.
Using now() always returns a UTC time.
The solution in XPath is to use the adjust-dateTime-to-timezone() function. This will normalize your dateTimes so they are in the same timezones. As an example, in an XForms output, to show just the date part of create-time you would use:
<xforms:output value="format-dateTime(adjust-dateTime-to-timezone(xs:dateTime(create-time)), '[M]/[D]/[Y]')">
<xforms:label>Creation date</xforms:label>
</xforms:output>

Resources