Skip to content
This repository has been archived by the owner on Sep 7, 2023. It is now read-only.

Fix: min/max on dates #509

Merged
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
18 changes: 14 additions & 4 deletions backends/javascript/ergo-runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -582,18 +582,20 @@ const minDateTime = moment("0001-01-01 00:00:00");
const maxDateTime = moment("3268-01-21 23:59:59");

function dateTimeMax(v) {
if (v.length === 0) {
var v1 = mustBeDateArray(v);
if (v1.length === 0) {
return minDateTime;
} else {
return moment.max(v);
return moment.max(v1);
}
}

function dateTimeMin(v) {
if (v.length === 0) {
var v1 = mustBeDateArray(v);
if (v1.length === 0) {
return maxDateTime;
} else {
return moment.min(v);
return moment.min(v1);
}
}

Expand Down Expand Up @@ -698,6 +700,14 @@ function mustBeDate(date) {
}
}

function mustBeDateArray(dateArray) {
var newDateArray = [];
for (var i=0; i<dateArray.length; i++) {
newDateArray.push(mustBeDate(dateArray[i]));
}
return newDateArray;
}

function mustBeDuration(d) {
if (typeof d == "string") {
return moment.duration(d);
Expand Down
15 changes: 10 additions & 5 deletions examples/smoke/duration1.ergo
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,21 @@ define concept A{ a : Integer }
define concept C{ contract : String }
define concept R{ output1: DateTime, output2: DateTime, output3: Duration, test: Boolean }

define transaction MyRequest {
}
define concept TemplateModel {
}

contract Duration over TemplateModel {
clause test(request : MyRequest) : R {
let d1 = parse("2018-01-30");
let d2 = parse("17 May 2018 13:53:33 EST");
let d1 = dateTime("2018-01-30");
let d2 = dateTime("17 May 2018 13:53:33 EST");
return R{
output1: d1,
output2: d2,
output3: diffWithUnit(d1, d2, "weeks"),
test: isSame(add(parse("2018-01-02"), Duration{amount:1, unit: "days"}),
add(parse("2018-01-01"), Duration{amount:2, unit: "days"}))
output3: diffDurationAs(d1, d2, "weeks"),
test: isSame(addDuration(dateTime("2018-01-02"), Duration{amount:1, unit: "days"}),
addDuration(dateTime("2018-01-01"), Duration{amount:2, unit: "days"}))
}
}
}
12 changes: 6 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/ergo-cli/lib/ergoc-lib.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/ergo-cli/lib/ergotop-lib.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/ergo-compiler/lib/ergo-core.js

Large diffs are not rendered by default.