Skip to content

Commit 3840047

Browse files
authored
Add TimeUnitValue property (#4926)
1 parent cd07dc4 commit 3840047

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

src/foam/lang/types.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1554,3 +1554,44 @@ foam.CLASS({
15541554
}
15551555
]
15561556
})
1557+
1558+
foam.CLASS({
1559+
package: 'foam.lang',
1560+
name: 'TimeUnitValue',
1561+
extends: 'Int',
1562+
properties: [
1563+
{
1564+
class: 'String',
1565+
name: 'unitPropName',
1566+
value: 'timeUnit'
1567+
},
1568+
{
1569+
name: 'unitPropValueToString',
1570+
value: async function(x, val, unitProp) {
1571+
if ( unitProp && foam.time.TimeUnit.isInstance(unitProp) ) {
1572+
return `${val} ${unitProp.plural}`;
1573+
}
1574+
return val;
1575+
}
1576+
}
1577+
],
1578+
1579+
methods: [
1580+
function installInClass(cls) {
1581+
this.SUPER(cls);
1582+
1583+
var name = this.name;
1584+
var Name = foam.String.capitalize(name);
1585+
1586+
var unitPropName = this.unitPropName;
1587+
var UnitPropName = foam.String.capitalize(unitPropName);
1588+
1589+
cls.installAxiom(foam.lang.Method.create({
1590+
name: `get${Name}Ms`,
1591+
type: 'Long',
1592+
code: function() { return this[name] * this[unitPropName].conversionFactorMs; },
1593+
javaCode: `return get${Name}() * get${UnitPropName}().getConversionFactorMs();`
1594+
}));
1595+
}
1596+
]
1597+
});

0 commit comments

Comments
 (0)