Hello.
Few time ago @WanWizzard stated that we need more flexible way to use formatted strings in skins.
So i thought about it and i think i found a solution. so i post this as a discussion here so to discuss what can be done and everybody to give suggestions before to post a PR for that.
So, finally i came up to this possible definition in the skin
<convert type="EventTime">F',{StartTime:%H:%M} - {EndTime:%H:%M} • {DurationSign}{Duration:d} min</convert>
Let me explain the parts of the convert text definition...
The text/type is a comma separated list with first element " F' ". That stands for to notify the convertor that we have a format string template as a second element.
So the second element is obviously the format string.
{StartTime:%H:%M} - {EndTime:%H:%M} • {DurationSign}{Duration:d} min
Here you can specify what you want to render and also you can specify the format of the elements in it. For example StartTime of the event:
{StartTime:%H:%M} - %H:%M formatted as 24h time
In this way you can construct whatever sequence you want with separators of your choice or without them.
So to work all this ofcource the convertor itself have to be adapted. For example above the code in the convertor can look like this:
begin = event.getBeginTime() end = begin + event.getDuration() now = int(time()) duration_sign = "" if begin <= now <= end: duration = end - now duration_sign = "+" else: duration = event.getDuration() d = {"StartTime":datetime.fromtimestamp(begin), "EndTime":datetime.fromtimestamp(end), "Duration": duration//60, "DurationSign": duration_sign} res_str = self.parts[1].format(**d)
The requirements is the values to be formattable and to provide in the dictionary all possible values that you may use in the format string.
So any thoughts?