Time problem

I have 3 datetime fields: begin, end and interval

I would like to build a valuelist eg.

begin = 08:30
end = 17:00
interval = 00:30 (30 minutes)

valuelist:
08:30
09:00
09:30 etc.

No matter what I try I can’t increase the begin time.

Can somebody please help? :?

this is a little too little information.

Do the other 2 fields work?

Are you using formatting on all three?
What datatype do you use on the fields?

Hi Irene,

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.

Hope this helps.

Hi Robert,

thanks, it surely helped, the application output is exactly what I had in mind. But for some reasons the format of the valuelist is not the same.

Although the field is formatted as HH:mm, the valuelist shows the unformatted values (1970-01-01 08:30:00:0).

Is there an other way to format valuelists?

Hi Irene,

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.

Hi Robert,

the idea is to let the user chose the hours and the interval he wants to see an reproduce that in all value lists.

So I would like a valuelist only with the time.

Hi Irene,

And where will you be using this valuelist ? I mean where are you gonna store these times ?
Datetime fields ?

it is a datetime field but it is formatted as HH:mm

Hi Irene,

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.

Hope this helps.

Hi Robert,

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. :shock:

Do you get it ?.. I don’t

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’ ?

Hi Robert,

The original problem is still the same.

Although the field is formatted as HH:mm, the valuelist shows the unformatted values (1970-01-01 08:30:00:0).

I try desperately to show only the time in the value lists, so I’m playing around with the formats. But nothing seems to help.

The second question is more a “is this normal?” Sins I have upgraded my OS to OSX Leopard Sevoy does strange things.

Hi Irene,

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

Isn’t this what you want ?

Than you thank you thank you, this is exactly what I want.

I didn’t think about combobox because the field should be editable, but I will duplicate the field and make it a combobox.