The original symptom was that the javascript function nowToInt() was returning a negative number.
We determined that it was the 32 bit 2s complement representation of the 41 bit epoch time in milliseconds.
I tried a fix and nobody liked it, including me. I'd like input on the right way to approach this.
The current test cases look like this:
Things I observed:
We determined that it was the 32 bit 2s complement representation of the 41 bit epoch time in milliseconds.
I tried a fix and nobody liked it, including me. I'd like input on the right way to approach this.
The current test cases look like this:
Rich (BB code):
> js nowToInt();
Returned: -1680943482
> ash now_to_int();
Returned: 1677653081709
Things I observed:
- The ash function is named now_to_int(), but it is returning a long and Ash allows it.
- Ash doesn't have a Long as a dataType (unless the wiki is out of date...): https://wiki.kolmafia.us/index.php/Data_Types#int
- now_to_int is returning milliseconds. While I don't know if it should return milliseconds, that's what's overflowing. If it was seconds, it would be safe until 2038. As it is, it can only return a long (or larger, but...).
- JavaScript has to go through ValueConverter.asJava() and ValueConverter.fromJava() to get the right value out.
- now_to_int() is defined as having DataType.INT_TYPE, returns a Value, and calls a Calendar function that returns a Long
- ValueConverter.asJava() returns the long value as expected, but it says it's a type int.
- ValueConverter.fromJava() converts it to an Integer and that becomes the 2s complement.
- Nobody loves a polymorphic data type (even if it is predictable).
- It's not an int, so now_to_int() isn't really now_to_int(), it's now_to_long(). It's never been _to_int() if it returns time in milliseconds and int is a 2s complement data type.
- If something other than a time function had a 2.1B value, it would unexpectedly get a type that JavaScript can't coerce into a number. This will cause JS scripts that are currently getting a wrong value to get a data mismatch.
Rich (BB code):
public Value fromJava(Object object, Type typeHint) {
if (object == null) return null;
else if (object instanceof Boolean) {
return DataTypes.makeBooleanValue((Boolean) object);
} else if (object instanceof Float || object instanceof Double) {
return DataTypes.makeFloatValue(((Number) object).floatValue());
} else if (object instanceof Byte
|| object instanceof Short
|| object instanceof Integer
|| object instanceof Long) {
return DataTypes.makeIntValue(((Number) object).intValue());
Last edited: