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

(fix) Range for getMonth is now between 1 and 12 #582

Merged
merged 1 commit into from
Mar 19, 2019
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
2 changes: 1 addition & 1 deletion backends/javascript/ergo-runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,7 @@ function dateTimeComponent(part, date) {
case WEEKS:
return date.week();
case MONTHS:
return date.month();
return date.month() + 1; // Shift by one to get 1-12 range on months (Moment uses 0-11)
case QUARTERS:
return date.quarter();
case YEARS:
Expand Down
6 changes: 6 additions & 0 deletions examples/smoke/duration.ergo
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ contract Duration over TemplateModel {
dateTime("2019-01-08")));
enforce(isSame(dateTimeMin([dateTime("2018-01-08"), dateTime("2019-01-08"), dateTime("2011-01-08")]),
dateTime("2011-01-08")));
enforce(getMonth(dateTime("08 Jan 2018 00:00 UT")) = 1);
enforce(getMonth(dateTime("08 May 2018 00:00 UT")) = 5);
enforce(getMonth(dateTime("08 Dec 2018 00:00 UT")) = 12);
enforce(getMonth(dateTime("2018-01-08")) = 1);
enforce(getMonth(dateTime("2018-05-08")) = 5);
enforce(getMonth(dateTime("2018-12-08")) = 12);
return MyResponse{
output: "Duration.test successful"
}
Expand Down
2 changes: 1 addition & 1 deletion packages/ergo-cli/extracted/ergoccore.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/ergo-compiler/extracted/compilercore.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions packages/ergo-compiler/test/scriptmanager.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ describe('ScriptManager', () => {
scriptManager.getLogic().map(x => x.name).should.deep.equal(['test.ergo']);
scriptManager.allFunctionDeclarations().length.should.equal(1);
scriptManager.allFunctionDeclarations().map(x => x.getName()).should.deep.equal(['paymentClause']);
scriptManager.getCompiledScript().getContents().length.should.equal(27672);
scriptManager.getCompiledScript().getContents().length.should.equal(27739);
scriptManager.allFunctionDeclarations().length.should.equal(98);
scriptManager.allFunctionDeclarations().filter(x => x.name === '__init').length.should.equal(1);
expect(scriptManager.hasInit()).to.not.throw;
Expand All @@ -68,8 +68,8 @@ describe('ScriptManager', () => {
const script2 = scriptManager.createScript('test.ergo','.ergo',ergoSample);
scriptManager.addScript(script1);
scriptManager.addScript(script2);
scriptManager.compileLogic().getContents().length.should.equal(27672);
scriptManager.getCompiledScript().getContents().length.should.equal(27672);
scriptManager.compileLogic().getContents().length.should.equal(27739);
scriptManager.getCompiledScript().getContents().length.should.equal(27739);
scriptManager.getAllScripts().length.should.equal(3);
});

Expand Down
28 changes: 14 additions & 14 deletions packages/ergo-compiler/test/templatelogic.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ describe('TemplateLogic', () => {
templateLogic.getInitCall().length.should.equal(63);
(() => templateLogic.getInvokeCall('helloworld')).should.throw('Cannot call invoke explicitely from Cicero');
templateLogic.getDispatchCall().length.should.equal(82);
templateLogic.getScriptManager().getCompiledScript().getContents().length.should.equal(27672);
templateLogic.getScriptManager().getCompiledScript().getContents().length.should.equal(27739);
templateLogic.compileLogicSync(false);
templateLogic.getScriptManager().getCompiledScript().getContents().length.should.equal(27672);
templateLogic.getScriptManager().getCompiledScript().getContents().length.should.equal(27739);
});

it('should fail to load a bogus logic file to the model manager', () => {
Expand All @@ -82,9 +82,9 @@ describe('TemplateLogic', () => {
templateLogic.getInitCall().length.should.equal(63);
(() => templateLogic.getInvokeCall('helloworld')).should.throw('Cannot call invoke explicitely from Cicero');
templateLogic.getDispatchCall().length.should.equal(82);
templateLogic.getScriptManager().getCompiledScript().getContents().length.should.equal(27672);
templateLogic.getScriptManager().getCompiledScript().getContents().length.should.equal(27739);
templateLogic.compileLogicSync(false);
templateLogic.getScriptManager().getCompiledScript().getContents().length.should.equal(27672);
templateLogic.getScriptManager().getCompiledScript().getContents().length.should.equal(27739);
});
});

Expand All @@ -102,16 +102,16 @@ describe('TemplateLogic', () => {
templateLogic.getInitCall().length.should.equal(63);
(() => templateLogic.getInvokeCall('helloworld')).should.throw('Cannot call invoke explicitely from Cicero');
templateLogic.getDispatchCall().length.should.equal(82);
templateLogic.getScriptManager().getCompiledScript().getContents().length.should.equal(27672);
templateLogic.getScriptManager().getCompiledScript().getContents().length.should.equal(27739);
templateLogic.compileLogicSync(false);
templateLogic.getScriptManager().getCompiledScript().getContents().length.should.equal(27672);
templateLogic.getScriptManager().getCompiledScript().getContents().length.should.equal(27739);
});

it('should load a logic file (without extension) to the model manager', () => {
const templateLogic = new TemplateLogic('cicero');
templateLogic.addLogicFile(ergoSample,'test');
templateLogic.compileLogicSync(false);
templateLogic.getScriptManager().getCompiledScript().getContents().length.should.equal(27672);
templateLogic.getScriptManager().getCompiledScript().getContents().length.should.equal(27739);
});

it('should set the contract name', () => {
Expand All @@ -127,15 +127,15 @@ describe('TemplateLogic', () => {
templateLogic.addLogicFile(ergoSample,'test.ergo');
templateLogic.getTarget().should.equal('cicero');
templateLogic.compileLogicSync(false);
templateLogic.getScriptManager().getCompiledScript().getContents().length.should.equal(27672);
templateLogic.getScriptManager().getCompiledScript().getContents().length.should.equal(27739);
templateLogic.setTarget('es6', true);
templateLogic.getTarget().should.equal('es6');
const contractName = 'org.accordproject.helloemit.HelloWorld';
templateLogic.setContractName(contractName);
templateLogic.getInitCall().length.should.equal(123);
templateLogic.getInvokeCall('helloworld').length.should.equal(155);
templateLogic.getDispatchCall().length.should.equal(138);
templateLogic.getScriptManager().getCompiledScript().getContents().length.should.equal(26797);
templateLogic.getScriptManager().getCompiledScript().getContents().length.should.equal(26864);
});

it('should fail to create init and dispatch for ES6 without a contract name', () => {
Expand All @@ -146,30 +146,30 @@ describe('TemplateLogic', () => {
(() => templateLogic.getInitCall()).should.throw('Cannot create init call for target: es6 without a contract name');
(() => templateLogic.getInvokeCall('helloworld')).should.throw('Cannot create invoke call for target: es6 without a contract name');
(() => templateLogic.getDispatchCall()).should.throw('Cannot create dispatch call for target: es6 without a contract name');
templateLogic.getScriptManager().getCompiledScript().getContents().length.should.equal(26797);
templateLogic.getScriptManager().getCompiledScript().getContents().length.should.equal(26864);
});

it('should set the compilation target to ES6 but not recompile the logic', () => {
const templateLogic = new TemplateLogic('cicero');
templateLogic.addLogicFile(ergoSample,'test.ergo');
templateLogic.compileLogicSync(false);
templateLogic.getScriptManager().getCompiledScript().getContents().length.should.equal(27672);
templateLogic.getScriptManager().getCompiledScript().getContents().length.should.equal(27739);
templateLogic.setTarget('es6', false);
templateLogic.getScriptManager().getCompiledScript().getContents().length.should.equal(27672);
templateLogic.getScriptManager().getCompiledScript().getContents().length.should.equal(27739);
});

it('should set the compilation target to ES5', () => {
const templateLogic = new TemplateLogic('cicero');
templateLogic.addLogicFile(ergoSample,'test.ergo');
templateLogic.getTarget().should.equal('cicero');
templateLogic.compileLogicSync(false);
templateLogic.getScriptManager().getCompiledScript().getContents().length.should.equal(27672);
templateLogic.getScriptManager().getCompiledScript().getContents().length.should.equal(27739);
templateLogic.setTarget('es5', true);
templateLogic.getTarget().should.equal('es5');
templateLogic.getInitCall().length.should.equal(53);
templateLogic.getInvokeCall('helloworld').length.should.equal(112);
templateLogic.getDispatchCall().length.should.equal(68);
templateLogic.getScriptManager().getCompiledScript().getContents().length.should.equal(26657);
templateLogic.getScriptManager().getCompiledScript().getContents().length.should.equal(26724);
});

it('should fail to create init code for Java', () => {
Expand Down