Skip to content

Instantly share code, notes, and snippets.

@palaniraja
Created October 25, 2024 23:34
Show Gist options
  • Save palaniraja/301c962679892de3d9f7be8686d4aa7c to your computer and use it in GitHub Desktop.
Save palaniraja/301c962679892de3d9f7be8686d4aa7c to your computer and use it in GitHub Desktop.
sublime shortcut for converting epoch seconds ~/Library/Application Support/Sublime Text/Packages/User/
[
{
"caption": "Epoch Converter",
"command": "epoch_converter"
}
]
[
{ "keys": ["ctrl+u"], "command": "epoch_converter" }
]
import sublime
import sublime_plugin
from datetime import datetime
class epoch_converter(sublime_plugin.TextCommand):
def run(self, edit):
for region in self.view.sel():
if not region.empty():
selected_text = self.view.substr(region)
if selected_text.isdigit():
try:
timestamp = int(selected_text)
date_str = datetime.utcfromtimestamp(timestamp).strftime('%Y-%m-%d %H:%M:%S')
new_text = f"{selected_text} ({date_str}) "
self.view.replace(edit, region, new_text)
except ValueError:
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment