Skip to content

Instantly share code, notes, and snippets.

@Garren
Forked from robcowie/timestamp.py
Created October 31, 2012 17:35
Show Gist options
  • Save Garren/3988539 to your computer and use it in GitHub Desktop.
Save Garren/3988539 to your computer and use it in GitHub Desktop.
Insert date and time stamps in Sublime Text 2
# -*- coding: utf-8 -*-
from datetime import datetime
import sublime_plugin
import getpass
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 = "[" + getpass.getuser() + "] " + datetime.now().strftime('%Y-%m-%dT%H:%M:%S')
elif prefix in ('utcnow', 'utcdatetime'):
val = "[" + getpass.getuser() + "] " +datetime.utcnow().strftime('%Y-%m-%dT%H:%M:%S')
elif prefix == 'date':
val = "[" + getpass.getuser() + "] " +datetime.now().strftime('%Y-%M-%d')
elif prefix == 'time':
val = "[" + getpass.getuser() + "] " +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