homieiot / convention

🏡 The Homie Convention: a lightweight MQTT convention for the IoT
https://homieiot.github.io/
Other
705 stars 59 forks source link

Add time datatype, and maybe date too #214

Open bggardner opened 4 years ago

bggardner commented 4 years ago

There are use cases where only the time portion of a datetime property is relevant, such as in a daily schedule. Using the datetime datatype is possible, but would result in an infinite number of values that would represent the same time (with different dates). The reverse could also be said about only needing the date portion, but that can more easily be resolved by setting the time portion to zero. In either case, ISO 8601 formats are established.

On the implementation side, JavaScript does not have a time class (though the HTML input type=time exists), but Python does (datetime.time). In lieu of researching other languages, would this cause heartburn with any other implementations?

piegamesde commented 4 years ago

Instead of adding yet another data type, what about using the $format attribute for this?

bggardner commented 4 years ago

Possibly, but that may be confusing, since the "format" needs to be according to ISO 8601. Values of $format could be:

No to open a can of worms, but $format is really a misnomer for all the data types, as it's really just extended data type information. I would expect "format" to be used for displaying information, not describing it. Just another thing to consider.

bggardner commented 4 years ago

An alternative approach (just brainstorming here) is to make $datatype simply iso8601, and use $format to express one of datetime (default, maybe), date, time, duration, or interval. However, I think the reverse would be more appropriate: having a separate $datatype for each one, and making $format (if defined at all) always be ISO 8601.

mjcumming commented 3 years ago

From the Convention description, it seems that $format is being used to further describe the datatype.

"$format | Specifies restrictions or options for the given data type"

I agree, we should probably add datatypes for date, time and interval. We already have datetime and duration. Correct me if I am wrong, but would the datatime datatype already hand just date or just time?

joelightshoe commented 3 years ago

An additional consideration is that datetime in ISO-8601 can be formatted as

The Java 8 Time API is a good reference.

time is generally either local or offset and not zoned, since date information is required for time-zone to be meaningful, and date is generally only local. Perhaps $format could be leveraged somehow to convey that. For example,