Skip to content

Instantly share code, notes, and snippets.

@tmacam
Forked from kmorey/timestamp.py
Created July 20, 2022 18:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tmacam/03e87714799618852766d1482ec21676 to your computer and use it in GitHub Desktop.
Save tmacam/03e87714799618852766d1482ec21676 to your computer and use it in GitHub Desktop.
# -*- coding: utf-8 -*-
from datetime import datetime
import time
import sublime_plugin
class TimestampCommand(sublime_plugin.EventListener):
"""Expand `isoD`, `now`, `datetime`, `utcnow`, `utcdatetime`,
`date` and `time`
"""
def on_query_completions(self, view, prefix, locations):
if prefix in ('isoD', 'now', 'datetime'):
val = datetime.now().strftime('%Y-%m-%dT%H:%M:%S')
elif prefix in ('utcnow', 'utcdatetime'):
val = datetime.utcnow().strftime('%Y-%m-%dT%H:%M:%S')
elif prefix == 'date':
val = datetime.now().strftime('%Y-%m-%d')
elif prefix == 'time':
val = str(int(time.time()))
else:
val = None
return [(prefix, prefix, val)] if val else []
@tmacam
Copy link
Author

tmacam commented Jul 20, 2022

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment