How about support time expression?
The current support of Tinyexpr is a cool feature I am using every day, as calculator. But time expression calculation like:
00:32:15-00:16:42=00:15:33
32:15.339-16:42.158=15:33.171
second(15:33.171)=933.171s
I am not find a calculator with that support. This time expressions are useful when working with audio or video.
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!: https://github.com/codeplea/tinyexpr/issues/104
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.
I'm currently using it myself to calculate the length of clipped videos. If anyone here is still interested in this feature, I can submit a PR.