Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions packages/survey-core/src/functionsfactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ FunctionFactory.Instance.register("age", age);
function dateDiff(params: any[]): any {
if (!Array.isArray(params) || params.length < 2 || !params[0] || !params[1]) return null;
const type = (params.length > 2 ? params[2] : "") || "days";
const isHours = type === "hours" || type === "minutes";
const isHours = type === "hours" || type === "minutes" || type === "seconds";
const dType = isHours ? "days" : type;
let days = dateDiffMonths(params[0], params[1], dType);
if (isHours) {
Expand All @@ -306,7 +306,9 @@ function dateDiff(params: any[]): any {
if (date2.getMinutes() < date1.getMinutes()) {
hours -= 1;
}
return hours * 60 + date2.getMinutes() - date1.getMinutes();
const minutes = hours * 60 + date2.getMinutes() - date1.getMinutes();
if (type === "minutes") return minutes;
return minutes * 60 + date2.getSeconds() - date1.getSeconds();
}
return days;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,13 @@ QUnit.test("Run dateDiff by minutes Bug#10177", function(assert) {
const values = { d1: d1, d2: d2 };
assert.equal(runner.runValues(values), 5, "minutes");
});
QUnit.test("Run dateDiff by seconds #10176", function(assert) {
const runner = new ExpressionRunner("dateDiff({d1}, {d2}, 'seconds')");
const d1 = new Date("2025-07-25T02:13:48");
const d2 = new Date("2025-07-25T02:15:05");
const values = { d1: d1, d2: d2 };
assert.equal(runner.runValues(values), 77, "seconds");
});
QUnit.test("Run dateAdd() for days", function(assert) {
const d1 = new Date("2021-01-01");
const values = { d1: d1 };
Expand Down