Why is Duration defined as a separate type in schema.org? - schema.org

According to http://schema.org/Recipe I can define a cookTime value as a Duration type.
Now Duration is defined as its own type but the Recipe specifies it should be an ISO 8601 format string.
Why have the Duration type if it should be text? I couldn't find any good explanations for this. Is the schema.org type hierarchy broken?

Duration, like the other quantities, are just strings. You don't use itemscope itemtype="…" with them, you just put a string in that format. The ‘type’ is used to indicate the required string format. There are no properties of Duration itself.
For example, a cookTime of 1h using the Duration type is:
<meta itemprop="cookTime" content="PT1H">
Notice the lack of itemscope and no declaration of the Duration type. This meets the Duration type though, because the string is of the correct format.
Another example would be Distance.
Properties that take Distances as values are of the form ' '. E.g., '7 ft'.
This isn't a type like you'd usually think of a type, with properties and such. This is just a string, with a format required to meet the type.

Related

How do I supply a validated Cocoa input for NSTimeInterval type values?

I am in need of a Cocoa control, either Objective C or Swift (not SwiftUI, I still support as low as 10.13.x), that accepts text in the format of:
minutes:seconds.fraction
And returns it in either milliseconds, or NSTimeInterval. The former is preferred, the latter is acceptable, I can convert it to milliseconds if necessary.
I need the control to be able to validate the inverse transformation of the value, and only store the value in my NSUserDefaults storage if the value is non-zero, and a valid timestamp.
I see a question here about validating inputs, unanswered: How do I validate value of a reverse transform input field in Cocoa?
Can a string simply be fed to an NSTimeInterval for processing? And what about converting NSTimeInterval to a string again? Validation is important, as I don't want the user inputting invalid values and just having them clobber their settings.

Is empty string value generally allowed by the FIX protocol?

When I look at the definition of a String type in the FIX protocol (e.g. here or here), I don't see a minimum length specified. Is it allowed to use empty strings? One online decoder seems to accept an empty string value (see tag 320), an other complains that it's invalid.
The FIX 4.4 specification states the following (emphasis in the original text):
Each message is constructed of a stream of <tag>=<value> fields with a
field delimiter between fields in the stream. Tags are of data type
TagNum. All tags must have a value specified. Optional fields without
values should simply not be specified in the FIX message. A Reject
message is the appropriate response to a tag with no value.
That strongly suggests (but does not unambiguously state) to me that the use of an empty value for a string is invalid. It is unsurprising to me that different FIX implementations might treat this edge case in different ways. So, I think the best approach is to avoid using empty values for strings.
+1 for Ciaran's and Grant's answer/comments. Just want to add something.
I generally suggest to look up things like this in the most current specification since they usually have been refined/reworded/clarified to eliminate unclear or ambiguous statements from older specs.
The answer is on the very page you link to in your question (emphasis mine, search for "Well-formed field"): https://www.fixtrading.org/standards/tagvalue-online/#field-syntax
A well-formed field has the form:
tag=value<SOH>
A field shall be considered malformed if any of the following occurs as a result of encoding:
the tag is empty
the tag delimiter is missing
the value is empty
the value contains an <SOH> character and the datatype of the field is not data or XMLdata
the datatype of the field is data and the field is not immediately preceded by its associated Length field.

How are values compared in NatTable with GlazedLists?

I do use NatTables with GlazedLists. I can not find in documentation, how default comparator compares values. According ASCII code values?
If you have not configured any other Comparator for a column, NatTable will use its DefaultComparator. The DefaultComparator checks if both objects are of type Comparable, if so it will use the compareTo(String) method of that type. If not it will try to get the String representation of the object and perform a comparison based on that. String itself is also a Comparable so you find the detailed information how Strings are compared in the Javadoc.

In PostgreSQL, which types can be cast with the type name first?

Reading the PostgreSQL docs, I see that you can cast a longish bit of text to xml like this:
SELECT xml '<long>long text, may span many lines</long>'
SELECT xml '...'
Curious, I found that I could do the same with JSON:
SELECT json '{"arg1":"val1", <more args spanning many lines>}'
(I couldn't find an official reference for this one. It just works!)
By contrast, this does not work:
SELECT float8 3.14159
I like this alternate syntax from a readability perspective. Now I'm looking for a reference listing which types may be specified up front like this. but I haven't found it yet.
Any pointers?
The documentation says:
A constant of an arbitrary type can be entered using any one of the following notations:
type 'string'
'string'::type
CAST ( 'string' AS type )
The string constant's text is passed to the input conversion routine for the type called type. The result is a constant of the indicated type. The explicit type cast can be omitted if there is no ambiguity as to the type the constant must be (for example, when it is assigned directly to a table column), in which case it is automatically coerced.
The form you are asking about is the first one.
So this can be used for all PostgreSQL types.
Note that the data must be specified as a string literal (in single or dollar quotes) when you use that syntax.

Difference between Formatter and Factory Function

​Hello,
Please explain what is the difference between Factory and Formatter function. Because as I see both can be used to format or manipulate the output results. How to choose between both of them ?
Regards,
Mayank
Factory functions allows you to create different types of controls in runtime. Let's assume that you have a list and you want to display different type of list items according to your list index for instance, or maybe to some value that you have in your model. Factory functions allows you to do it in the binding way.
Formatters are some kind of an helper functions which receive and input and return an output. The most popular examples are date and time that you receive date in form A and return date in form B. formatter functions are defined on a property level so if you have a field in your list item which display a date you can use formatter in order to do a very simple manipulation to this date