[Gambas-user] Strange problem with Date Time and ValueBox
Richard
richard.j.walker at ...247...
Thu Mar 13 01:27:35 CET 2008
On Wednesday 12 March 2008 00:31:05 Richard wrote:
> On Tuesday 11 March 2008 21:55:51 Richard wrote:
> > On Tuesday 11 March 2008 12:42:44 Benoit Minisini wrote:
> > > On samedi 8 mars 2008, Richard wrote:
> > > > I have a little program which I wrote for the last winter Ashes tour.
> > > > It provides a way to do timer controlled recordings from radio
> > > > programmes streamed by the BBC and played by Helixplayer.
> > > >
> > > > I have tinkered with it from time to time to bloat its feature set
> > > > and keep it up to date with various key changes to the Gambas2
> > > > environment. The current working version is in use recording each
> > > > day's play in the 3 test series under way in New Zealand. It runs on
> > > > Gambas2 v2.0 with a backported bug-fix for the date chooser control
> > > > which Benoit kindly provided.
> > > >
> > > > I have always found plenty to confuse me when handling dates and
> > > > times in Gambas but having converted from my own customised versions
> > > > of the DateBox and TimeBox controls to the new ValueBox control I had
> > > > reviewed the date and time handling code to make sure I am not doing
> > > > any redundant conversions.
> > > >
> > > > Something I changed recently introduced a bug to the
> > > > store-recall-timer-settings process. A date and time entered as
> > > > {02/03/2008 15:45:11} is changed, when it is recalled from a storage
> > > > array, to {02/03/2008 00:41:26}.
> > > >
> > > > A lot of time spent tracing through my over-complex logic eventually
> > > > located the probable "cause" in part of the code which restores a
> > > > previously stored collection of settings. The relevant code snippet
> > > > is:
> > > >
> > > > 'Timer tab controls
> > > > LineRecord.StartDateChooser.Value =
> > > > Date(records[ix].Start_Time) LineRecord.StartDateBox.Value =
> > > > Date(records[ix].Start_Time) 'Do not trigger selected Change events
> > > > LineRecord.INC_autoset
> > > > LineRecord.HourTimeSet.Value = Hour(records[ix].Start_Time)
> > > > LineRecord.MinuteTimeset.Value =
> > > > Minute(records[ix].Start_Time) LineRecord.SecondTimeSet.Value =
> > > > Second(records[ix].Start_Time) 'Re-enable selected Change events
> > > > LineRecord.DEC_autoset
> > > > 'LineRecord.StartTimeBox.Value = Time(records[ix].Start_Time)
> > > > LineRecord.StartTimeBox.Value = (records[ix].Start_Time)
> > > >
> > > > In the last two lines the version commented out is the line which
> > > > introduces the incorrect time. The line below works just fine. The
> > > > records array is an array of objects of Class Recording. The
> > > > Recording.Start_Time property is a Date value with both date and time
> > > > parts.
> > > >
> > > > Until this week the first two lines, and the penultimate, simply
> > > > assigned the whole date/time value to the DateChooser, StartDateBox
> > > > and the StartTimeBox. I decided to make it more "correct" after
> > > > reading about the Date and Time conversion functions. Only the
> > > > Time(date_variable) line is "wrong". Reverting to the old sloppy way
> > > > fixes the problem.
> > > >
> > > > Here's the question: Has anyone come across a similar problem in
> > > > date/time handling? I have tried replicating the problem in
> > > > independent code with no success.
> > > >
> > > >
> > > > Richard
> > >
> > > Can you provide the full source code?
> >
> > Yes, can do, but it isn't pretty. The source archive is currently 640k,
> > but that includes a lot of clutter in the project img folder.
> >
> > > And can you use DEBUG or PRINT
> > > instruction to the prints the value of records[ix].Start_Time before
> > > assigning it?
> >
> > I found the rogue value while stepping through the code using the
> > debugger and the Watch pane.
> >
> > > Regards,
> >
> > I have also tried to replicate the problem in stand-alone code (a test
> > project) which simply does the same logical things with date and time
> > values, but that worked perfectly; just the way you would expect. My
> > guess at this stage is that I have managed to create an inconsistency
> > somewhere. The observation that nobody else has come across the same snag
> > would seem to confirm that the bug is mine all mine!
> >
> > I'll do some more searching now that the latest modifications to the
> > application are working and I'll get back to you if I need more help.
> >
> > Richard
> >
> >
> >
> > -------------------------------------------------------------------------
> > This SF.net email is sponsored by: Microsoft
> > Defy all challenges. Microsoft(R) Visual Studio 2008.
> > http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
> > _______________________________________________
> > Gambas-user mailing list
> > Gambas-user at lists.sourceforge.net
> > https://lists.sourceforge.net/lists/listinfo/gambas-user
>
> OK, I have found another code sequence which works.
>
> I had scattered a few DEBUG statements around sections of code which read
> and write the start date/time value and noticed that where the problem
> value appears, my procedure reads the Recording.Start_Time property lots of
> times.
>
> Apart from any other consideration, this seemed a bit wasteful of processor
> power so I changed the procedure to read the property value once into a
> local variable and then use the local value for extracting Date, Hour,
> Minute, Second and Time values.
>
> This has had the interesting side effect of avoiding the bug. See the code
> snippet below (compared to the same sequence copied in my first message):
>
> 'Timer tab controls
> 'DEBUG ix; ">=";; records[ix].Start_Time;;
> Date(records[ix].Start_Time);; Time(records[ix].Start_Time)
> 'DEBUG CFloat(records[ix].Start_Time);;
> CFloat(Date(records[ix].Start_Time));; CFloat(Time(records[ix].Start_Time))
> StartTime = records[ix].Start_Time
> LineRecord.StartDateChooser.Value = Date(StartTime)
> LineRecord.StartDateBox.Value = Date(StartTime)
> 'Do not trigger selected Change events
> LineRecord.INC_autoset
> LineRecord.HourTimeSet.Value = Hour(StartTime)
> LineRecord.MinuteTimeset.Value = Minute(StartTime)
> LineRecord.SecondTimeSet.value = Second(StartTime)
> 'Re-enable selected Change events
> LineRecord.DEC_autoset
> LineRecord.StartTimeBox.Value = Time(StartTime)
> 'LineRecord.StartTimeBox.Value = (records[ix].Start_Time)
>
> This just gets more and more interesting, but it is late now. I'll explore
> further tomorrow.
>
> Richard
>
> -------------------------------------------------------------------------
> This SF.net email is sponsored by: Microsoft
> Defy all challenges. Microsoft(R) Visual Studio 2008.
> http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
> _______________________________________________
> Gambas-user mailing list
> Gambas-user at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/gambas-user
It has happened again in the same code sequence but with a different
date/time. The time should have been 21:00:00, but the Time() function reads
it as 00:41:26, the same wrong value.
I still think it must be something not quite right with my program rather than
a problem with the Time() function. I have a trimmed down version of the
project - all the original code is present, just some xcf files deleted from
the img folder - which has some tell-tale DEBUG statements in the right place
to show what works and what doesn't. Nevertheless it is still about
230kbytes. Is that too big to post here?
Richard
More information about the User
mailing list