xTuple.com xTupleU Blog & News Customer Support

QT Script 5

Here is a piece of code I have to break down a date string

if ( expired_date != null)
{
var ex_year = expired_date.toString().substring(0,4);
var ex_month = expired_date.toString().substring(4,2);
var ex_day = expired_date.toString().substring(6,2);
}

now here is the returned values from debugger and I did not make this up

qsdb> expired_date
20190410
qsdb> expired_date.toString().substring(0,4)
2019
qsdb> expired_date.toString().substring(4,2)
19
qsdb> expired_date.toString().substring(6,2)
1904

To put it gently, I am confused

using xTuple 5 and windows client

I apologize , the function substring goes start and end not start and length,

A reason to read the the documentation

I touched my nose with both hands and stood on each foot and confirmed I am not stoned…

qsdb> .eval expired_date.toString().trim().substring(0,8)
20190410
qsdb> .eval expired_date.toString().trim().substring(0,4)
2019
qsdb> .eval expired_date.toString().trim().substring(4,5)
0
qsdb> .eval expired_date.toString().trim().substring(4,6)
04
qsdb> .eval expired_date.toString().trim().substring(7,8)
0
qsdb> .eval expired_date.toString().trim().substring(6,8)
10

I have no idea what is going on here

It seems that QT takes the start value and adds one and uses the actual end value

so substring(4,5) = substring(5,5) which is zero

QString doesn’t provide a substring method, you are using JavaScript’s substring which may lead to some confusion. From here:

This method extracts the characters in a string between "start" and "end", not including "end" itself.

QString does provide indexOf() and lastIndexOf() and a few others if you did want to venture into that side of things.

Thank you David

I was was using this link here for QT 5

Ahh yeah, that doc doesn’t specify that it doesn’t include the end character, also that is technically for QML, and the scripting environment is using QtScript, but that link doesn’t really say much either. If I recall QtScript is ECMAScript 3.