diff --git a/.vs/ElevenClock3/FileContentIndex/6fca470e-9146-45de-921b-09d5bc90c67a.vsidx b/.vs/ElevenClock3/FileContentIndex/6fca470e-9146-45de-921b-09d5bc90c67a.vsidx new file mode 100644 index 00000000..ab9d9caa Binary files /dev/null and b/.vs/ElevenClock3/FileContentIndex/6fca470e-9146-45de-921b-09d5bc90c67a.vsidx differ diff --git a/.vs/ElevenClock3/FileContentIndex/ab44692e-81fb-44f0-91a3-94a04ba36292.vsidx b/.vs/ElevenClock3/FileContentIndex/ab44692e-81fb-44f0-91a3-94a04ba36292.vsidx new file mode 100644 index 00000000..28f96ffb Binary files /dev/null and b/.vs/ElevenClock3/FileContentIndex/ab44692e-81fb-44f0-91a3-94a04ba36292.vsidx differ diff --git a/.vs/ElevenClock3/FileContentIndex/ea904282-a526-43e8-a3e9-091a63ef1cbd.vsidx b/.vs/ElevenClock3/FileContentIndex/ea904282-a526-43e8-a3e9-091a63ef1cbd.vsidx new file mode 100644 index 00000000..74831526 Binary files /dev/null and b/.vs/ElevenClock3/FileContentIndex/ea904282-a526-43e8-a3e9-091a63ef1cbd.vsidx differ diff --git a/.vs/ElevenClock3/FileContentIndex/read.lock b/.vs/ElevenClock3/FileContentIndex/read.lock new file mode 100644 index 00000000..e69de29b diff --git a/.vs/ElevenClock3/v17/.wsuo b/.vs/ElevenClock3/v17/.wsuo new file mode 100644 index 00000000..c5782179 Binary files /dev/null and b/.vs/ElevenClock3/v17/.wsuo differ diff --git a/.vs/ProjectSettings.json b/.vs/ProjectSettings.json new file mode 100644 index 00000000..f8b48885 --- /dev/null +++ b/.vs/ProjectSettings.json @@ -0,0 +1,3 @@ +{ + "CurrentProjectSetting": null +} \ No newline at end of file diff --git a/.vs/PythonSettings.json b/.vs/PythonSettings.json new file mode 100644 index 00000000..b9c8fb37 --- /dev/null +++ b/.vs/PythonSettings.json @@ -0,0 +1,3 @@ +{ + "Interpreter": "env\\Scripts\\python.exe" +} \ No newline at end of file diff --git a/.vs/VSWorkspaceState.json b/.vs/VSWorkspaceState.json new file mode 100644 index 00000000..f7a401e0 --- /dev/null +++ b/.vs/VSWorkspaceState.json @@ -0,0 +1,7 @@ +{ + "ExpandedNodes": [ + "" + ], + "SelectedNode": "\\C:\\Users\\arsha\\Source\\Repos\\ElevenClock3", + "PreviewInSolutionExplorer": false +} \ No newline at end of file diff --git a/.vs/slnx.sqlite b/.vs/slnx.sqlite new file mode 100644 index 00000000..eb7c666a Binary files /dev/null and b/.vs/slnx.sqlite differ diff --git a/ElevenClock.iss b/ElevenClock.iss index 059c4aac..5bf5c4cd 100644 --- a/ElevenClock.iss +++ b/ElevenClock.iss @@ -2,7 +2,7 @@ ; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES! #define MyAppName "ElevenClock" -#define MyAppVersion "4.3.2" +#define MyAppVersion "4.3.3" #define MyAppPublisher "Martí Climent" #define MyAppURL "https://marticliment.com/elevenclock" #define MyAppExeName "ElevenClock.exe" diff --git a/elevenclock/__init__.py b/elevenclock/__init__.py index befb8490..7d75b54d 100644 --- a/elevenclock/__init__.py +++ b/elevenclock/__init__.py @@ -1265,7 +1265,8 @@ def updateTextLoop(self) -> None: while True: try: - timeStr = evaluate_expression_string(datetime.datetime.fromtimestamp(time.time()-self.internetTimeOffset).strftime(self.clockFormat.replace("\u200a", "hairsec")).replace("hairsec", HAIRSEC_VAR)) + curFormatClock = self.clockFormat + timeStr = evaluate_expression_string(time.time(),curFormatClock.replace("\u200a", "hairsec"),self.internetTimeOffset).replace("hairsec", HAIRSEC_VAR) if SHOULD_FIX_SECONDS: try: secs = datetime.datetime.fromtimestamp(time.time()-self.internetTimeOffset).strftime("%S") diff --git a/elevenclock/settings.py b/elevenclock/settings.py index 0db8ced4..ed297518 100644 --- a/elevenclock/settings.py +++ b/elevenclock/settings.py @@ -552,7 +552,8 @@ def setCustomFont(v): {_("If you don't understand what is happening, please uncheck the checkbox over the text area")} @@ -3133,8 +3134,9 @@ def updateText(self) -> None: self.preview.setText(_("Nothing to preview")) else: try: - currtext = self.edit.toPlainText() - self.preview.setText(evaluate_expression_string(datetime.datetime.now().strftime(currtext.replace("\u200a", "hairsec")).replace("hairsec", "\u200a"))) + curFormatClock = self.edit.toPlainText() + newText = evaluate_expression_string(time.time(),curFormatClock.replace("\u200a", "hairsec")).replace("hairsec", "\u200a") + self.preview.setText(newText) except Exception as e: self.preview.setText(_("Invalid time format\nPlease follow the\nC 1989 Standards")) report(e) diff --git a/elevenclock/tools.py b/elevenclock/tools.py index 30691501..8ae0a95d 100644 --- a/elevenclock/tools.py +++ b/elevenclock/tools.py @@ -2,6 +2,7 @@ from functools import partial import json import time +import datetime windll.shcore.SetProcessDpiAwareness(c_int(2)) from versions import * @@ -156,19 +157,34 @@ def evaluate_simple_expression(expression: str): # supported expressions are of result += operand elif operator == "-": result -= operand - return result -def evaluate_expression_string(s: str): +def evaluate_expression_string(d, s: str, offset=0): + def evaluate_match_time(match): + expression=extract_sec_from_format(match.group(1)) + return str(datetime.datetime.fromtimestamp(d+int(expression[1])).strftime(expression[0])) def evaluate_match(match): expression = match.group(1) - if re.fullmatch(r'\d+(\s*[\+\-]\s*\d+)*', expression): # a valid expression is of form x +/- y + if re.fullmatch(r'\d+(\s*[\+\-]\s*\d+)*', expression): # a valid expression is of form x +/- y return str(evaluate_simple_expression(expression)) else: return match.group(0) # Return the original text if not a valid expression - return re.sub(r'\{([^}]*)\}', evaluate_match, s) # search for expressions of form {****} and replace using evaluate_match - + time_formated = re.sub(r'\(([^)]*\{sec([+-]\d*)\})\)', evaluate_match_time, s) # a valid expression is of (*{sec+/-N}) + time_formated = datetime.datetime.fromtimestamp(d-offset).strftime(time_formated) + time_formated = re.sub(r'\{([^}]*)\}', evaluate_match, time_formated) # a valid expression is of {*} + return time_formated + +def extract_sec_from_format(expression: str): + extract_sec=re.findall(r'(.*)(\{sec([+-]\d*)\})$', expression) # a valid expression is of {sec+/-N} where N is any integer + result=[] + if extract_sec.__len__()>0 and extract_sec[0][1] != '': + result.append(extract_sec[0][0]) + result.append(extract_sec[0][2]) + else: + result.append(expression) + result.append(0) + return result def getColors() -> list: colors = ['215,226,228', '160,174,183', '101,116,134', '81,92,107', '69,78,94', '41,47,64', '15,18,36', '239,105,80']