Skip to content

Commit

Permalink
Added functionality for adding seconds to the clock format field.
Browse files Browse the repository at this point in the history
  • Loading branch information
arshanskiyav committed Nov 6, 2023
1 parent 6bd0e05 commit 0c45a2a
Show file tree
Hide file tree
Showing 13 changed files with 42 additions and 10 deletions.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Empty file.
Binary file added .vs/ElevenClock3/v17/.wsuo
Binary file not shown.
3 changes: 3 additions & 0 deletions .vs/ProjectSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"CurrentProjectSetting": null
}
3 changes: 3 additions & 0 deletions .vs/PythonSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"Interpreter": "env\\Scripts\\python.exe"
}
7 changes: 7 additions & 0 deletions .vs/VSWorkspaceState.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"ExpandedNodes": [
""
],
"SelectedNode": "\\C:\\Users\\arsha\\Source\\Repos\\ElevenClock3",
"PreviewInSolutionExplorer": false
}
Binary file added .vs/slnx.sqlite
Binary file not shown.
2 changes: 1 addition & 1 deletion ElevenClock.iss
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
3 changes: 2 additions & 1 deletion elevenclock/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
8 changes: 5 additions & 3 deletions elevenclock/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,8 @@ def setCustomFont(v):
<ul>
<li>{_("Any text can be placed here. To place items such as date and time, please use the 1989 C standard. Check the format codes on the following link:")} <a href="https://strftime.org" style="color:{f"rgb({getColors()[2 if isWindowDark() else 4]})"}">{_("Python date and time formats")}</a>
<li>{_("To disable the zero-padding effect, add a # in between the % and the code: non-zero-padded hours would be %#H, and zero-padded hours would be %H")}</li>
<li>{_("Use the nonation {%H+1} to specify offsets. Replace %H with the desired value and +1 for a positive or negative number (+n or -n, respectively, for a <i>n</i> offset), representing the offset.")}</li>
<li>{_("Use the notation {%H+1} to specify offsets. Replace %H with the desired value and +1 for a positive or negative number (+n or -n, respectively, for a <i>n</i> offset), representing the offset.")}</li>
<li>{_("Use the notation (%H {sec+1}) on the end of string to specify offset in seconds. For example, to add an hour and view in format HH:MM use (%H:%M {sec+3600}), and to decrease an hour use (%H:%M {sec-3600}).")}</li>
<li>{_('You can use HTML tags to set bold, italics or change the color of a piece of text through the &#60;span style="color: red"&#62;&#60;/span&#62; tag')}</li>
<li>{_("Click on Apply to apply and preview the format")}</li></ul>
{_("If you don't understand what is happening, please uncheck the checkbox over the text area")}
Expand Down Expand Up @@ -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)
Expand Down
26 changes: 21 additions & 5 deletions elevenclock/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from functools import partial
import json
import time
import datetime
windll.shcore.SetProcessDpiAwareness(c_int(2))

from versions import *
Expand Down Expand Up @@ -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']
Expand Down

0 comments on commit 0c45a2a

Please sign in to comment.