1
1
mirror of https://github.com/KenanZhu/AutoLibrary.git synced 2026-06-17 23:13:03 +08:00

fix(ALAutoScript*Dialog): 统一编排窗口生成的 Lua 函数名与 ASEngine 运行时一致

- date_add → dateadd, time_add → timeadd
- CURRENT_DATE() → datenow(), CURRENT_TIME() → timenow()
- 编辑窗口 Date/Time 字面量按钮模板同步更新为 date()/time() 格式

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
2026-05-27 20:25:19 +08:00
parent eb8da498a2
commit f7167c13f4
4 changed files with 30 additions and 27 deletions
+4 -4
View File
@@ -329,8 +329,8 @@ class ALAutoScriptEditDialog(QDialog):
] ]
self.addButtonsToGrid(literalLayout, bool_buttons, 0, 0, 3) self.addButtonsToGrid(literalLayout, bool_buttons, 0, 0, 3)
dateTimeButtons = [ dateTimeButtons = [
("日期", '"2099-01-01"'), ("日期", 'date(2026, 1, 1)'),
("时间", '"00:00"'), ("时间", 'time(0, 0)'),
] ]
self.addButtonsToGrid(literalLayout, dateTimeButtons, 1, 0, 3) self.addButtonsToGrid(literalLayout, dateTimeButtons, 1, 0, 3)
hintButtons = [ hintButtons = [
@@ -358,8 +358,8 @@ class ALAutoScriptEditDialog(QDialog):
funcButtons = [ funcButtons = [
("datenow()", "datenow()", "返回当前日期的 Unix 时间戳"), ("datenow()", "datenow()", "返回当前日期的 Unix 时间戳"),
("timenow()", "timenow()", "返回当前时间在一天中的分钟数"), ("timenow()", "timenow()", "返回当前时间在一天中的分钟数"),
("dateadd(d, n)", "dateadd(, )", "日期偏移: dateadd(日期时间戳, 天数)"), ("dateadd(day, n)", "dateadd(, )", "日期偏移: dateadd(日期时间戳, 天数)"),
("timeadd(t, n)", "timeadd(, )", "时间偏移: timeadd(分钟数, 分钟数)"), ("timeadd(time, n)", "timeadd(, )", "时间偏移: timeadd(分钟数, 分钟数)"),
] ]
for i, (text, template, tooltip) in enumerate(funcButtons): for i, (text, template, tooltip) in enumerate(funcButtons):
btn = QPushButton(text) btn = QPushButton(text)
@@ -203,7 +203,6 @@ class ConditionalBlock(QGroupBox):
] ]
if not condTexts: if not condTexts:
condTexts = ["true"] condTexts = ["true"]
if len(condTexts) == 1: if len(condTexts) == 1:
combined = condTexts[0] combined = condTexts[0]
else: else:
+13 -13
View File
@@ -90,7 +90,7 @@ DATE_OFFSET_OPTIONS = [
("", "days"), ("", "days"),
("", "weeks"), ("", "weeks"),
# NOTE: "月" and "年" use fixed day counts (30 / 365), not calendar months/years, # NOTE: "月" and "年" use fixed day counts (30 / 365), not calendar months/years,
# because date_add() works with second-level offsets (n * 86400). # because dateadd() works with second-level offsets (n * 86400).
("", "months"), ("", "months"),
("", "years"), ("", "years"),
] ]
@@ -423,7 +423,7 @@ def encodeValueStr(
Encode a raw widget value as a Lua expression. Encode a raw widget value as a Lua expression.
Arithmetic expressions (A + B) are passed through for numeric types; Arithmetic expressions (A + B) are passed through for numeric types;
Date/Time arithmetic is translated to ``date_add()`` / ``time_add()`` calls. Date/Time arithmetic is translated to ``dateadd()`` / ``timeadd()`` calls.
""" """
if var_type in ("Date", "Time"): if var_type in ("Date", "Time"):
@@ -464,24 +464,24 @@ def encodeDateOrTime(
right = m_arith.group(3).strip() right = m_arith.group(3).strip()
operand = right if sign == "+" else f"-{right}" operand = right if sign == "+" else f"-{right}"
if left == "CURRENT_DATE": if left == "CURRENT_DATE":
return f"date_add(CURRENT_DATE(), {operand})" return f"dateadd(datenow(), {operand})"
if left == "CURRENT_TIME": if left == "CURRENT_TIME":
return f"time_add(CURRENT_TIME(), {operand})" return f"timeadd(timenow(), {operand})"
if var_type == "Date": if var_type == "Date":
return f"date_add({left}, {operand})" return f"dateadd({left}, {operand})"
if var_type == "Time": if var_type == "Time":
return f"time_add({left}, {operand})" return f"timeadd({left}, {operand})"
return f"{left} {sign} {right}" return f"{left} {sign} {right}"
if up == "CURRENT_DATE": if up == "CURRENT_DATE":
return "CURRENT_DATE()" return "datenow()"
if up == "CURRENT_TIME": if up == "CURRENT_TIME":
return "CURRENT_TIME()" return "timenow()"
_REL_MAP = { _REL_MAP = {
"前天": "date_add(CURRENT_DATE(), -2)", "前天": "dateadd(datenow(), -2)",
"昨天": "date_add(CURRENT_DATE(), -1)", "昨天": "dateadd(datenow(), -1)",
"今天": "CURRENT_DATE()", "今天": "datenow()",
"明天": "date_add(CURRENT_DATE(), 1)", "明天": "dateadd(datenow(), 1)",
"后天": "date_add(CURRENT_DATE(), 2)", "后天": "dateadd(datenow(), 2)",
} }
if s in _REL_MAP: if s in _REL_MAP:
return _REL_MAP[s] return _REL_MAP[s]
+13 -9
View File
@@ -178,9 +178,11 @@ class ConditionRowFrame(QFrame):
if not data: if not data:
return "" return ""
name, vartype = data name, vartype = data
# CURRENT_DATE / CURRENT_TIME are Lua functions — call them, not reference them # CURRENT_DATE / CURRENT_TIME map to datenow() / timenow()
if name in ("CURRENT_DATE", "CURRENT_TIME"): if name == "CURRENT_DATE":
name = f"{name}()" name = "datenow()"
elif name == "CURRENT_TIME":
name = "timenow()"
opSym = self.opCombo.currentData() opSym = self.opCombo.currentData()
if self._rawRhsExpr: if self._rawRhsExpr:
return f"{name} {opSym} {self._rawRhsExpr}" return f"{name} {opSym} {self._rawRhsExpr}"
@@ -189,8 +191,10 @@ class ConditionRowFrame(QFrame):
rd = self.rhsVarCombo.currentData() rd = self.rhsVarCombo.currentData()
if rd: if rd:
rhsName = rd[0] rhsName = rd[0]
if rhsName in ("CURRENT_DATE", "CURRENT_TIME"): if rhsName == "CURRENT_DATE":
rhsName = f"{rhsName}()" rhsName = "datenow()"
elif rhsName == "CURRENT_TIME":
rhsName = "timenow()"
return f"{name} {opSym} {rhsName}" return f"{name} {opSym} {rhsName}"
rhsText = self.rhsVarCombo.currentText().strip() rhsText = self.rhsVarCombo.currentText().strip()
if rhsText: if rhsText:
@@ -384,18 +388,18 @@ class ActionStepFrame(QFrame):
elif op == "add": elif op == "add":
if vartype == "Date" and hasattr(self.valueStack.currentWidget(), "getOffsetDays"): if vartype == "Date" and hasattr(self.valueStack.currentWidget(), "getOffsetDays"):
days = self.valueStack.currentWidget().getOffsetDays() days = self.valueStack.currentWidget().getOffsetDays()
return f" {target} = date_add({target}, {days})" return f" {target} = dateadd({target}, {days})"
if vartype == "Time" and hasattr(self.valueStack.currentWidget(), "getOffsetHours"): if vartype == "Time" and hasattr(self.valueStack.currentWidget(), "getOffsetHours"):
hours = self.valueStack.currentWidget().getOffsetHours() hours = self.valueStack.currentWidget().getOffsetHours()
return f" {target} = time_add({target}, {hours})" return f" {target} = timeadd({target}, {hours})"
return f" {target} = {target} + {rawVal}" return f" {target} = {target} + {rawVal}"
elif op == "sub": elif op == "sub":
if vartype == "Date" and hasattr(self.valueStack.currentWidget(), "getOffsetDays"): if vartype == "Date" and hasattr(self.valueStack.currentWidget(), "getOffsetDays"):
days = self.valueStack.currentWidget().getOffsetDays() days = self.valueStack.currentWidget().getOffsetDays()
return f" {target} = date_add({target}, -{days})" return f" {target} = dateadd({target}, -{days})"
if vartype == "Time" and hasattr(self.valueStack.currentWidget(), "getOffsetHours"): if vartype == "Time" and hasattr(self.valueStack.currentWidget(), "getOffsetHours"):
hours = self.valueStack.currentWidget().getOffsetHours() hours = self.valueStack.currentWidget().getOffsetHours()
return f" {target} = time_add({target}, -{hours})" return f" {target} = timeadd({target}, -{hours})"
return f" {target} = {target} - {rawVal}" return f" {target} = {target} - {rawVal}"
return "" return ""