GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix · toolgood/ToolGood.Algorithm@77ecbbc

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • JavaScript
    • src/CalculationLogic
      • CalculationLogicEngine.js
    • tests
      • CalculationLogicTest.js
  • csharp
    • ToolGood.Algorithm.Test/CalculationLogic
      • CalculationLogicTest.cs
    • ToolGood.Algorithm/CalculationLogic
      • CalculationLogicEngine.cs
  • java/toolgood.algorithm/src
    • main/java/toolgood/algorithm/calculationlogic
      • CalculationLogicEngine.java
    • test/java/toolgood/algorithm/calculationlogic
      • CalculationLogicTest.java
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎JavaScript/src/CalculationLogic/CalculationLogicEngine.js‎

Copy file name to clipboardExpand all lines: JavaScript/src/CalculationLogic/CalculationLogicEngine.js
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { AlgorithmEngineEx } from '../AlgorithmEngineEx.js';
22
import { AlgorithmEngineHelper } from '../AlgorithmEngineHelper.js';
33
import { OperandType } from '../Enums/OperandType.js';
4+
import { MyDate } from '../Internals/MyDate.js';
45
import { CalculationLogicType } from './CalculationLogicType.js';
56
import { CalculationLogicInfo } from './CalculationLogicInfo.js';
67

@@ -46,6 +47,7 @@ export class CalculationLogicEngine {
4647
*/
4748
InitValue(key, value, layer = 0, remark = null) {
4849
if (typeof layer === 'string') { remark = layer; layer = 0; }
50+
if (value instanceof Date) { value = new MyDate(value); }
4951
this._engine.AddParameter(key, value);
5052
if (this._useCalculationLogicInfo) {
5153
this._initValueInfos.push(new CalculationLogicInfo({
@@ -161,6 +163,7 @@ export class CalculationLogicEngine {
161163
*/
162164
SetValue(key, value, layer = 0, remark = null) {
163165
if (typeof layer === 'string') { remark = layer; layer = 0; }
166+
if (value instanceof Date) { value = new MyDate(value); }
164167
this._engine.AddParameter(key, value);
165168
if (this._useCalculationLogicInfo) {
166169
this._calculationLogicInfos.push(new CalculationLogicInfo({
@@ -209,12 +212,14 @@ export class CalculationLogicEngine {
209212
_initExp(value) {
210213
if (typeof value === 'string') return value;
211214
if (typeof value === 'boolean') return value ? 'True' : 'False';
215+
if (value instanceof MyDate) return '"' + value.toString() + '"';
212216
return String(value);
213217
}
214218

215219
_valueExp(value) {
216220
if (typeof value === 'string') return '"' + value.replace(/"/g, '\\"') + '"';
217221
if (typeof value === 'boolean') return value ? 'True' : 'False';
222+
if (value instanceof MyDate) return '"' + value.toString() + '"';
218223
return String(value);
219224
}
220225

Collapse file

‎JavaScript/tests/CalculationLogicTest.js‎

Copy file name to clipboardExpand all lines: JavaScript/tests/CalculationLogicTest.js
+75Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,27 @@ function testInitValue_CanBeUsedInCondition() {
7171
assert.strictEqual(logic.CheckCondition('a>b'), false);
7272
}
7373

74+
function testInitValue_DateTime() {
75+
const logic = createEngine();
76+
logic.InitValue('dt', new Date(2026, 7, 31, 12, 0, 0));
77+
assert.strictEqual(logic.ToInfoString(), '[初始] dt="2026-08-31 12:00:00";\n');
78+
}
79+
80+
function testInitValue_DateTime_LayerRemark() {
81+
// InitValue 的层级与备注不参与信息输出
82+
const logic = createEngine();
83+
logic.InitValue('dt', new Date(2026, 7, 31, 12, 0, 0), 2, '备注');
84+
assert.strictEqual(logic.ToInfoString(), '[初始] dt="2026-08-31 12:00:00";\n');
85+
}
86+
87+
function testInitValue_DateTime_CanBeUsedInCondition() {
88+
const logic = createEngine();
89+
logic.InitValue('dt', new Date(2026, 7, 31, 12, 0, 0));
90+
assert.strictEqual(logic.CheckCondition('YEAR(dt)=2026'), true);
91+
assert.strictEqual(logic.CheckCondition('MONTH(dt)=8'), true);
92+
assert.strictEqual(logic.CheckCondition("dt>DATEVALUE('2026-08-30')"), true);
93+
}
94+
7495
// #endregion
7596

7697
// #region CheckCondition 测试
@@ -219,6 +240,26 @@ function testSetValue_LayerRemark() {
219240
assert.strictEqual(logic.ToInfoString(), '[赋值] i = 100 // 备注\n');
220241
}
221242

243+
function testSetValue_DateTime() {
244+
const logic = createEngine();
245+
logic.SetValue('dt', new Date(2026, 7, 31, 12, 0, 0));
246+
assert.strictEqual(logic.ToInfoString(), '[赋值] dt = "2026-08-31 12:00:00"\n');
247+
}
248+
249+
function testSetValue_DateTime_LayerRemark() {
250+
const logic = createEngine();
251+
logic.SetValue('dt', new Date(2026, 7, 31, 12, 0, 0), 1, '备注');
252+
assert.strictEqual(logic.ToInfoString(), '[赋值] dt = "2026-08-31 12:00:00" // 备注\n');
253+
}
254+
255+
function testSetValue_DateTime_CanBeUsedInCondition() {
256+
const logic = createEngine();
257+
logic.SetValue('dt', new Date(2026, 7, 31, 12, 0, 0));
258+
assert.strictEqual(logic.CheckCondition('YEAR(dt)=2026'), true);
259+
assert.strictEqual(logic.CheckCondition('MONTH(dt)=8'), true);
260+
assert.strictEqual(logic.CheckCondition("dt>DATEVALUE('2026-08-30')"), true);
261+
}
262+
222263
// #endregion
223264

224265
// #region GetValue 测试
@@ -267,6 +308,24 @@ function testGetValue_InitValue_Bool() {
267308
assert.strictEqual(operand.BooleanValue, true);
268309
}
269310

311+
function testGetValue_InitValue_DateTime() {
312+
const logic = createEngine();
313+
logic.InitValue('dt', new Date(2026, 7, 31, 12, 0, 0));
314+
const operand = logic.GetValue('dt');
315+
assert.strictEqual(operand.IsDate, true);
316+
assert.strictEqual(operand.Type, OperandType.DATE);
317+
assert.strictEqual(operand.DateValue.toString(), '2026-08-31 12:00:00');
318+
}
319+
320+
function testGetValue_SetValue_DateTime() {
321+
const logic = createEngine();
322+
logic.SetValue('dt', new Date(2026, 7, 31, 12, 0, 0));
323+
const operand = logic.GetValue('dt');
324+
assert.strictEqual(operand.IsDate, true);
325+
assert.strictEqual(operand.Type, OperandType.DATE);
326+
assert.strictEqual(operand.DateValue.toString(), '2026-08-31 12:00:00');
327+
}
328+
270329
function testGetValue_SetValue() {
271330
const logic = createEngine();
272331
logic.SetValue('v', 'text');
@@ -383,6 +442,9 @@ function runAllTests() {
383442
testInitValue_Bool();
384443
testInitValue_LayerRemark();
385444
testInitValue_CanBeUsedInCondition();
445+
testInitValue_DateTime();
446+
testInitValue_DateTime_LayerRemark();
447+
testInitValue_DateTime_CanBeUsedInCondition();
386448
testCheckCondition_True();
387449
testCheckCondition_False();
388450
testCheckCondition_LayerRemark();
@@ -399,11 +461,16 @@ function runAllTests() {
399461
testSetValue_Double();
400462
testSetValue_Bool();
401463
testSetValue_LayerRemark();
464+
testSetValue_DateTime();
465+
testSetValue_DateTime_LayerRemark();
466+
testSetValue_DateTime_CanBeUsedInCondition();
402467
testGetValue_InitValue_Int();
403468
testGetValue_InitValue_String();
404469
testGetValue_InitValue_Decimal();
405470
testGetValue_InitValue_Double();
406471
testGetValue_InitValue_Bool();
472+
testGetValue_InitValue_DateTime();
473+
testGetValue_SetValue_DateTime();
407474
testGetValue_SetValue();
408475
testGetValue_SetFormula();
409476
testGetValue_AfterSetFormulaOverwrite();
@@ -433,6 +500,9 @@ export {
433500
testInitValue_Bool,
434501
testInitValue_LayerRemark,
435502
testInitValue_CanBeUsedInCondition,
503+
testInitValue_DateTime,
504+
testInitValue_DateTime_LayerRemark,
505+
testInitValue_DateTime_CanBeUsedInCondition,
436506
testCheckCondition_True,
437507
testCheckCondition_False,
438508
testCheckCondition_LayerRemark,
@@ -449,11 +519,16 @@ export {
449519
testSetValue_Double,
450520
testSetValue_Bool,
451521
testSetValue_LayerRemark,
522+
testSetValue_DateTime,
523+
testSetValue_DateTime_LayerRemark,
524+
testSetValue_DateTime_CanBeUsedInCondition,
452525
testGetValue_InitValue_Int,
453526
testGetValue_InitValue_String,
454527
testGetValue_InitValue_Decimal,
455528
testGetValue_InitValue_Double,
456529
testGetValue_InitValue_Bool,
530+
testGetValue_InitValue_DateTime,
531+
testGetValue_SetValue_DateTime,
457532
testGetValue_SetValue,
458533
testGetValue_SetFormula,
459534
testGetValue_AfterSetFormulaOverwrite,
Collapse file

‎csharp/ToolGood.Algorithm.Test/CalculationLogic/CalculationLogicTest.cs‎

Copy file name to clipboardExpand all lines: csharp/ToolGood.Algorithm.Test/CalculationLogic/CalculationLogicTest.cs
+75Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,33 @@ public void InitValue_CanBeUsedInCondition_Test()
119119
Assert.IsFalse(logic.CheckCondition("a>b"));
120120
}
121121

122+
[Test]
123+
public void InitValue_DateTime_Test()
124+
{
125+
var logic = CreateEngine();
126+
logic.InitValue("dt", new DateTime(2026, 8, 31, 12, 0, 0));
127+
Assert.AreEqual("[初始] dt=\"2026-08-31 12:00:00\";\n", NormalizeLine(logic.ToInfoString()));
128+
}
129+
130+
[Test]
131+
public void InitValue_DateTime_LayerRemark_Test()
132+
{
133+
// InitValue 的层级与备注不参与信息输出
134+
var logic = CreateEngine();
135+
logic.InitValue("dt", new DateTime(2026, 8, 31, 12, 0, 0), 2, "备注");
136+
Assert.AreEqual("[初始] dt=\"2026-08-31 12:00:00\";\n", NormalizeLine(logic.ToInfoString()));
137+
}
138+
139+
[Test]
140+
public void InitValue_DateTime_CanBeUsedInCondition_Test()
141+
{
142+
var logic = CreateEngine();
143+
logic.InitValue("dt", new DateTime(2026, 8, 31, 12, 0, 0));
144+
Assert.IsTrue(logic.CheckCondition("YEAR(dt)=2026"));
145+
Assert.IsTrue(logic.CheckCondition("MONTH(dt)=8"));
146+
Assert.IsTrue(logic.CheckCondition("dt>DATEVALUE('2026-08-30')"));
147+
}
148+
122149
#endregion
123150

124151
#region CheckCondition 测试
@@ -280,6 +307,32 @@ public void SetValue_LayerRemark_Test()
280307
Assert.AreEqual("[赋值] i = 100 // 备注\n", NormalizeLine(logic.ToInfoString()));
281308
}
282309

310+
[Test]
311+
public void SetValue_DateTime_Test()
312+
{
313+
var logic = CreateEngine();
314+
logic.SetValue("dt", new DateTime(2026, 8, 31, 12, 0, 0));
315+
Assert.AreEqual("[赋值] dt = \"2026-08-31 12:00:00\"\n", NormalizeLine(logic.ToInfoString()));
316+
}
317+
318+
[Test]
319+
public void SetValue_DateTime_LayerRemark_Test()
320+
{
321+
var logic = CreateEngine();
322+
logic.SetValue("dt", new DateTime(2026, 8, 31, 12, 0, 0), 1, "备注");
323+
Assert.AreEqual("[赋值] dt = \"2026-08-31 12:00:00\" // 备注\n", NormalizeLine(logic.ToInfoString()));
324+
}
325+
326+
[Test]
327+
public void SetValue_DateTime_CanBeUsedInCondition_Test()
328+
{
329+
var logic = CreateEngine();
330+
logic.SetValue("dt", new DateTime(2026, 8, 31, 12, 0, 0));
331+
Assert.IsTrue(logic.CheckCondition("YEAR(dt)=2026"));
332+
Assert.IsTrue(logic.CheckCondition("MONTH(dt)=8"));
333+
Assert.IsTrue(logic.CheckCondition("dt>DATEVALUE('2026-08-30')"));
334+
}
335+
283336
#endregion
284337

285338
#region GetValue 测试
@@ -337,6 +390,28 @@ public void GetValue_InitValue_Bool_Test()
337390
Assert.IsTrue(operand.BooleanValue);
338391
}
339392

393+
[Test]
394+
public void GetValue_InitValue_DateTime_Test()
395+
{
396+
var logic = CreateEngine();
397+
logic.InitValue("dt", new DateTime(2026, 8, 31, 12, 0, 0));
398+
var operand = logic.GetValue("dt");
399+
Assert.IsTrue(operand.IsDate);
400+
Assert.AreEqual(OperandType.DATE, operand.Type);
401+
Assert.AreEqual(new DateTime(2026, 8, 31, 12, 0, 0), operand.DateValue.ToDateTime());
402+
}
403+
404+
[Test]
405+
public void GetValue_SetValue_DateTime_Test()
406+
{
407+
var logic = CreateEngine();
408+
logic.SetValue("dt", new DateTime(2026, 8, 31, 12, 0, 0));
409+
var operand = logic.GetValue("dt");
410+
Assert.IsTrue(operand.IsDate);
411+
Assert.AreEqual(OperandType.DATE, operand.Type);
412+
Assert.AreEqual(new DateTime(2026, 8, 31, 12, 0, 0), operand.DateValue.ToDateTime());
413+
}
414+
340415
[Test]
341416
public void GetValue_SetValue_Test()
342417
{
Collapse file

‎csharp/ToolGood.Algorithm/CalculationLogic/CalculationLogicEngine.cs‎

Copy file name to clipboardExpand all lines: csharp/ToolGood.Algorithm/CalculationLogic/CalculationLogicEngine.cs
+82Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,47 @@ public void InitValue(string key, int value, int layer, string remark)
248248
InitValueCore(key, value, () => value.ToString(), layer, remark);
249249
}
250250

251+
/// <summary>
252+
/// 初始化值
253+
/// </summary>
254+
/// <param name="key"></param>
255+
/// <param name="value"></param>
256+
public void InitValue(string key, DateTime value)
257+
{
258+
InitValue(key, value, 0, null);
259+
}
260+
/// <summary>
261+
/// 初始化值
262+
/// </summary>
263+
/// <param name="key"></param>
264+
/// <param name="value"></param>
265+
/// <param name="layer"></param>
266+
public void InitValue(string key, DateTime value, int layer)
267+
{
268+
InitValue(key, value, layer, null);
269+
}
270+
/// <summary>
271+
/// 初始化值
272+
/// </summary>
273+
/// <param name="key"></param>
274+
/// <param name="value"></param>
275+
/// <param name="remark"></param>
276+
public void InitValue(string key, DateTime value, string remark)
277+
{
278+
InitValue(key, value, 0, remark);
279+
}
280+
/// <summary>
281+
/// 初始化值
282+
/// </summary>
283+
/// <param name="key"></param>
284+
/// <param name="value"></param>
285+
/// <param name="layer"></param>
286+
/// <param name="remark"></param>
287+
public void InitValue(string key, DateTime value, int layer, string remark)
288+
{
289+
InitValueCore(key, value, () => $"\"{value.ToString("yyyy-MM-dd HH:mm:ss")}\"", layer, remark);
290+
}
291+
251292
private void InitValueCore(string key, Operand value, Func<string> expFactory, int layer, string remark)
252293
{
253294
_engine.AddParameter(key, value);
@@ -578,6 +619,47 @@ public void SetValue(string key, int exp, int layer, string remark)
578619
SetValueCore(key, exp, () => exp.ToString(), layer, remark);
579620
}
580621

622+
/// <summary>
623+
/// 设置值
624+
/// </summary>
625+
/// <param name="key"></param>
626+
/// <param name="exp"></param>
627+
public void SetValue(string key, DateTime exp)
628+
{
629+
SetValue(key, exp, 0, null);
630+
}
631+
/// <summary>
632+
/// 设置值
633+
/// </summary>
634+
/// <param name="key"></param>
635+
/// <param name="exp"></param>
636+
/// <param name="layer"></param>
637+
public void SetValue(string key, DateTime exp, int layer)
638+
{
639+
SetValue(key, exp, layer, null);
640+
}
641+
/// <summary>
642+
/// 设置值
643+
/// </summary>
644+
/// <param name="key"></param>
645+
/// <param name="exp"></param>
646+
/// <param name="remark"></param>
647+
public void SetValue(string key, DateTime exp, string remark)
648+
{
649+
SetValue(key, exp, 0, remark);
650+
}
651+
/// <summary>
652+
/// 设置值
653+
/// </summary>
654+
/// <param name="key"></param>
655+
/// <param name="exp"></param>
656+
/// <param name="layer"></param>
657+
/// <param name="remark"></param>
658+
public void SetValue(string key, DateTime exp, int layer, string remark)
659+
{
660+
SetValueCore(key, exp, () => $"\"{exp.ToString("yyyy-MM-dd HH:mm:ss")}\"", layer, remark);
661+
}
662+
581663
private void SetValueCore(string key, Operand value, Func<string> expFactory, int layer, string remark)
582664
{
583665
_engine.AddParameter(key, value);

0 commit comments

Comments
0 (0)
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.