Time changes

Hi,

I noticed the following problem. It is a serious problem for time registration systems.

I have 3 fields:
Registration date format dd/MM/yyyy
Time start format HH:mm
Time end format HH:mm

After entering the registration date, user must enter the time start field.

Since time-start field is of type HH:mm, I see in the debugger the following when entering 06:00 as time: Thu Jan 01 06:00:00 CET 1970
Before writing the value to the database I want to put the registration date into this field to replace 01/01/1970

After doing the following code:

		var _time = new Date(registration_time_start)
		_time.setFullYear(registration_date.getFullYear())	
		_time.setMonth(registration_date.getMonth())

I see that the time_start field has been changed to: Tue Sep 01 07:00:00 CEST 2009

Of course that is not what I want! :( :( :(

To make time-start en time-end fully datetime fields is not an option for the customer, because I know that could solve this problem.
I need a solution that puts the correct datetime in my field.

How should this be done without time changes?

Martin

Hi martin,

I would use the following code:

var _starttime = new Date(registration_date.getFullYear(),
            registration_date.getMonth(),
            registration_date.getDate(),
            registration_time_start.getHours(),
            registration_time_start.getMinutes(),
            registration_time_start.getSeconds());

var _endtime = new Date(registration_date.getFullYear(),
            registration_date.getMonth(),
            registration_date.getDate(),
            registration_time_end.getHours(),
            registration_time_end.getMinutes(),
            registration_time_end.getSeconds());

Hope this helps.

Hi Robert,

That is what I thought, but unfortunately that doesn’t work correct:

On my screen I enter:

registration_date = 10/09/2009
registration_time_start = 08:00
registration_time_end = 08:20

registration_time_start.getHours() returns 8 like expected.

Now I use the following coding:

var _time = new Date(registration_date.getFullYear(),
            registration_date.getMonth(),
            registration_date.getDate(),
            registration_time_start.getHours(),
            registration_time_start.getMinutes(),
            0);

And the variable _time shows: Thu Sep 10 09:00:00 CEST 2009

When I use 01/01/2009 as date, then the correct time is shown (Thu Jan 01 08:00:00 CET 2009)
So it has something to do with the summertime.

Martin

I’ve created a workaround, but I can’t imagine that Servoy intended to make it that difficult for us:

		var _hh = utils.numberFormat(registration_time_start.getHours(), '00')
		var _mm = utils.numberFormat(registration_time_start.getMinutes(), '00')
		var _month = utils.numberFormat(registration_date.getMonth() + 1, '00')
		var _day = utils.numberFormat(registration_date.getDate(), '00')
		
		var _string = _day + '/' + _month + '/' + registration_date.getFullYear() + ' ' + _hh + ':' + _mm
		var _time = utils.dateFormat(_string, 'dd/MM/yyyy HH:mm')

thats javascript not really servoy.
Thats how it works because of daylight saving time

What you could do is create first a string of the time stuff and then parse it back with the right format string
that should also work.