WebThingsIO / schemas

A Web of Things schema repository
https://webthings.io/schemas/
5 stars 8 forks source link

TimeAgoProperty #75

Open benfrancis opened 3 years ago

benfrancis commented 3 years ago

In https://github.com/WebThingsIO/zigbee-adapter/pull/292 there's a request for a feature to show the user when a device was last seen, so that they know when a gateway exposing the Web Thing API for a web thing last had contact with the actual device.

I propose that new type of property schema be defined which provides a machine readable value like an ISO 8601 date stamp, an integer representing milliseconds past the epoch, or an integer representing a time period in milliseconds. This machine readable value can then be converted into a human-readable string like "3 hours ago" in a user interface.

I'm open to ideas on the naming. It would be nice if this could be more generic like "DateTimeProperty", but the request was specifically for a property to be displayed as a string like "3 hours ago", which wouldn't be obvious from such a generic type.

The more specific option LastSeenProperty would be a bit of a strange name to standardise because it wouldn't make sense for devices which host their own Thing Description.

kgiori commented 3 years ago

Event logs (such as for pushbutton events) show "[seconds|minutes|hours|days] ago" in the Events page UI for the device -- could we leverage a similar paradigm to how those values are calculated?

benfrancis commented 3 years ago

Event logs (such as for pushbutton events) show "[seconds|minutes|hours|days] ago" in the Events page UI for the device -- could we leverage a similar paradigm to how those values are calculated?

Event resources include an ISO 8601 timestamp at the API level, which is then converted into those user friendly strings on the client side.

chas-iot commented 3 years ago

The ISO data format is painful to handle in Javascript when converting to a user readable string, as the toISOString method in current default libraries always uses the UTC timezone.

This, of course, is an argument that the libraries have an issue rather than an argument that a data interchange format should not be used. However it is another datapoint to consider.

benfrancis commented 3 years ago

I think I'd probably need to see the code to understand the problem here, but if it helps this is how we handle timestamps in the events view on WebThings Gateway https://github.com/WebThingsIO/gateway/blob/master/static/js/views/event-list.js

The timezone doesn't matter so much when you're calculating a "3 hours ago" type human-readable string though, as you just need a relative time period.

jaller94 commented 2 years ago

To me this seems to be a formatting variation of a DateTimeProperty. It sounds similar to a request of making DateTimeProperty prefer displaying in the user's local timezone or the timestamp's timezone.

An issue I have with converting a timestamp to "3 hours ago" on the server is the translation into a specific language (English in this case). As far as I'm aware, all other property values of the schema try to be language-agnostic when it comes to values.