You just want a popup with time values ?
So the date part of the datetime fields should be ignored, right?
Assuming your fieldnames are ‘begin’, ‘end’ and ‘interval’ your code could look like this:
var dValue = new Date(begin),
dEnd = new Date(dValue.getFullYear(),dValue.getMonth(),dValue.getDate(),end.getHours(),end.getMinutes(),0),
aValuelist = new Array(),
dInterval1 = new Date(dValue.getFullYear(),dValue.getMonth(),dValue.getDate(),0,0,0),
dInterval2 = new Date(dValue.getFullYear(),dValue.getMonth(),dValue.getDate(),interval.getHours(),interval.getMinutes(),0),
nInterval = dInterval2-dInterval1;
while ( dValue <= end )
{
aValuelist.push(utils.dateFormat(dValue, 'HH:mm'));
dValue.setTime(dValue.getTime()+nInterval);
}
application.output(aValuelist.join("\n"));// debug
As you see I make sure that since we do work with date objects that all date values (year/month/day) are the same.
Also to get the interval in milliseconds I need to have a date object that starts at midnight and substract that from the interval date object.
This way the date itself won’t have any effect and I can calculate with the milliseconds.
The resulting array you can use directly in the setValuelistItems() function.
This is because you put the (string) value of the valuelist back in a datetime field. Only the time value is provided so it add the default date to it
I assumed you don’t care about the date part because you wanted only to see the time bit.
Maybe you should explain how you want to use this method.
You should realise that formatting property (in this case) is for display purposes only. In the database it will also store the data part.
When you don’t provide it then it will use the date 1970-01-01.
So if you don’t use the date part anyway then there is no issue at all.
When you do need a (current?) date in those fields then you need to work with onDataChange methods on these fields to set the date bit.
I don’t get it. I want to see only a time in that field, if I release the format I see the date and the time.
It is weird, I have 2 fields on that layout, both datetime both with the same valuelist. As soon as I release the formatting on one of them , I don’t see any values on the valuelist any more.
irenem:
I don’t get it. I want to see only a time in that field, if I release the format I see the date and the time.
If you only want to see the time why would you remove the formatting ?
irenem:
It is weird, I have 2 fields on that layout, both datetime both with the same valuelist. As soon as I release the formatting on one of them , I don’t see any values on the valuelist any more. :shock:
I don’t know how it exactly works internally but I can only assume that Servoy ‘knows’ what type of data this field can accept. And just a time is not a valid datetime value. So it doesn’t show the valuelist values.
Maybe one of the Servoyans can shed more light on this.
But I am confused. Why is this a problem when you are only interested in the time values ?
Or is this more a quest of ‘why is this working the way it works’ ?
Here are 2 screenshots of a valuelist with (string) time values as you would get from the method I posted in this thread.
Top field has displaytype Combobox with a valuelist attached. Also the formatting HH:mm is applied.
You see that the valuelist shows the time values and the combobox does too.
Underneath that combobox you see the same field without formatting.
Servoy Developer
Version 3.5.3-build 516
Java version 1.6.0_04-b12-45-optimized (Mac OS X)
and
Java version 1.5.0_13-119 (Mac OS X)
Mac OS X 10.5.2