Created
October 25, 2024 23:34
-
-
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/
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
Show hidden characters
[ | |
{ | |
"caption": "Epoch Converter", | |
"command": "epoch_converter" | |
} | |
] |
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
[ | |
{ "keys": ["ctrl+u"], "command": "epoch_converter" } | |
] |
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
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