-
-
Notifications
You must be signed in to change notification settings - Fork 335
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How about support time expression? #4760
Comments
I write a python script to do this, with some help of GPT-4, it does work, but not as easy use as in notepad3, I need switch to cmd window type some cmd line and copy result and switch back to notepad3. tc.py import sys
import re
from datetime import datetime, timedelta
def main():
if len(sys.argv) != 2:
print(
'''Usage: python tc.py "01:23:15.211 01:24:10.323"
python tc.py "01:24:10.323-01:23:15.211"
python tc.py "01:24:10.323+11.211"
''')
return
time_str = sys.argv[1]
pattern = re.compile(r'^((\d{1,2}:)?(\d{1,2}:)?(\d{1,2}(\.\d{1,3})?))([+ \- ])((\d{1,2}:)?(\d{1,2}:)?(\d{1,2}(\.\d{1,3})?))$')
m = pattern.match(time_str)
if not m:
print('Invalid time expression format')
return
#for i in range(11):
# print(m[i+1], i+1)
op = m.group(6)
fstr1 = '%S' #'%H:%M:%S.%f'
if m.group(2):
fstr1 = '%M:' + fstr1
if m.group(3):
fstr1 = '%H:' + fstr1
if m.group(5):
fstr1 = fstr1 + '.%f'
fstr2 = '%S' #'%H:%M:%S.%f'
if m.group(8):
fstr2 = '%M:' + fstr2
if m.group(9):
fstr2 = '%H:' + fstr2
if m.group(11):
fstr2 = fstr2 + '.%f'
start_time = datetime.strptime(m.group(1), fstr1)
end_time = datetime.strptime(m.group(7), fstr2)
if op == ' ':
res = end_time - start_time
elif op == '-':
res = start_time - end_time
else:
res = end_time + timedelta(hours=start_time.hour,minutes=start_time.minute, seconds=start_time.second, microseconds=start_time.microsecond)
res = res - datetime(1900, 1, 1)
#dt = datetime(1900, 1, 1) + res
print(res.total_seconds(),'s')
print(res)
if __name__ == '__main__':
main() |
He already reposted as an issue on Tinyexpr upstream after 4 weeks. Nice!: codeplea/tinyexpr#104 |
I think because Tinyexpr return double value, no time expression will be supported, so I write one using C++, not too long about 200 lines, compile with notepad3. |
The current support of Tinyexpr is a cool feature I am using every day, as calculator.
But time expression calculation like:
I am not find a calculator with that support. This time expressions are useful when working with audio or video.
The text was updated successfully, but these errors were encountered: