Skip to content

Commit

Permalink
Add new voice commands for inserting datestamps/timestamps (talonhub#444
Browse files Browse the repository at this point in the history
)

* Add new voice commands for inserting datestamps (e.g. 2021-05-30) or timestamps (e.g. 2021-05-30 16:31:39)

* Use 'insert' instead of 'fill'; rename files and update spoken words.

Have the functions in the .py file return a string instead of
performing the actual insertion, which allows users to customize the
formatting as they see fit.

* Make more flexible by calling through strftime()

* Enhance function docstrings as per @linuxbochs suggestion

* remove unneeded line

* remove another unneeded line
  • Loading branch information
same-moon authored Jun 6, 2021
1 parent 83cec98 commit 03a7013
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
22 changes: 22 additions & 0 deletions misc/datetimeinsert.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import datetime
from talon import Context, actions, Module

mod = Module()

@mod.action_class
class Actions:
def time_format(fmt: str=None) -> str:
"""Return the current time, formatted.
fmt: strftime()-style format string, defaults to ISO format."""
now = datetime.datetime.now()
if fmt is None:
return now.isoformat()
return now.strftime(fmt)

def time_format_utc(fmt: str=None) -> str:
"""Return the current UTC time, formatted.
fmt: strftime()-style format string, defaults to ISO format."""
now = datetime.datetime.utcnow()
if fmt is None:
return now.isoformat()
return now.strftime(fmt)
12 changes: 12 additions & 0 deletions misc/datetimeinsert.talon
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
date insert:
insert(user.time_format("%Y-%m-%d"))
date insert UTC:
insert(user.time_format_utc("%Y-%m-%d"))
timestamp insert:
insert(user.time_format("%Y-%m-%d %H:%M:%S"))
timestamp insert high resolution:
insert(user.time_format("%Y-%m-%d %H:%M:%S.%f"))
timestamp insert UTC:
insert(user.time_format_utc("%Y-%m-%d %H:%M:%S"))
timestamp insert UTC high resolution:
insert(user.time_format_utc("%Y-%m-%d %H:%M:%S.%f"))

0 comments on commit 03a7013

Please sign in to comment.