InsertDate
InsertDate copied to clipboard
New Feature: parse and reformat date in view
It would be nice to have a command to parse the selection in a view assuming it's a date, then present the user with a panel with the output formats to which the date can be transformed.
That's a good idea. I will couple that with #15 when I work on it.
How would you suggest to determine the format of the timestamp parsed?
Yeah, I could just use the same panel as in InsertDatePanelCommand
. I could also attempt to parse the string(s) with all format strings from the prompt_config
setting (minus tz_in and tz_out variants) and take whatever matches - and only ask for an explicit format if none matches.
If the above works like I think it could, i'll most likely implement it like that.
If I were to do it, I would try to see if the dateutil
module works with ST's python (it is not bundled with ST3 as far as I can see).
It contains a parse
function that tries to guess the format (see here).
As an ugly fallback, if nothing else works, you could try parsing the date using each template with datetime.strptime
.
Also, I would probably not write new command but exploit the current ones adding a, say, date
optional argument (default to None
): when None
do as now (backward compat), when now
or tomorrow
or few other keywords compute the corresponding date, when selection
or a generic string try to parse.
Thanks for the hint. dateutil
looks like it could easily be made compatible with ST and I can just bundle it as a dependency, like I did with pytz
.
I think that would be enough info to start working on this. Don't expect it too soon though, I have many things with higher priority currently, so for the moment you'll either have to stick to regular expressions or implement it on your on and file a pull request.