Created
October 28, 2011 19:13
-
-
Save robcowie/1323194 to your computer and use it in GitHub Desktop.
Insert date and time stamps in Sublime Text 2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
from datetime import datetime | |
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 = datetime.now().strftime('%H:%M:%S') | |
else: | |
val = None | |
return [(prefix, prefix, val)] if val else [] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Works out of the box with Sublime Text 3.