Project JEDI - Issue Tracker
Mantis Bugtracker

Viewing Issue Simple Details Jump to Notes ] View Advanced ] Issue History ] Print ]
ID Category Severity Reproducibility Date Submitted Last Update
0004399 [JEDI VCL] 00 JVCL Components tweak always 2008-07-09 08:18 2008-08-12 03:47
Reporter ZENsan View Status public  
Assigned To obones
Priority normal Resolution fixed  
Status resolved   Product Version Daily / GIT
Summary 0004399: TJvDBDateTimePicker sets date to NULL
Description When TJvDBDateTimePicker TrimValue = False and mode = time, if user sets time to 0:00:00, them editor sets whole field to NULL, not only time part.
Additional Information
Tags No tags attached.
Attached Files rar file icon Project1.rar [^] (375,559 bytes) 2008-07-15 23:45
zip file icon HowToDo.zip [^] (25,685 bytes) 2008-07-27 01:49
? file icon JvDBDateTimePicker.pas [^] (18,921 bytes) 2008-08-12 02:27

- Relationships

-  Notes
(0014378)
obones (administrator)
2008-07-15 01:00

Please provide the zipped sources of a sample application showing this.
(0014383)
ZENsan (reporter)
2008-07-15 23:46

Simply press Up and Down in Time editor. And date will set to 1899 year.. It works if we set initial value with time. But not works when start value is 0:0:0 for time.
(0014414)
obones (administrator)
2008-07-23 06:36

I'm unable to reproduce this. I used your application, clicked the "up" and "down" button in the time field, the date did not change.
(0014460)
ZENsan (reporter)
2008-07-27 01:49

How it can happen if I launch the Project1.exe and it happens for, but not happens for you.. Maybe I have wrong Windows version?
(0014461)
ZENsan (reporter)
2008-07-27 01:50

I uploaded HowToDO.zip - printscreens of steps I do so that this happens for attached Project1.rar->Project1.exe. And it doesn't happens in the same way for you???
(0014472)
ZENsan (reporter)
2008-08-03 23:43
edited on: 2008-08-04 05:21

JvDBDateTimePicker.pas FIX:

function TJvDBDateTimePicker.IsDateAndTimeField: Boolean;
begin
  with FDataLink do
    Result := (Field <> nil) and
      (Field.DataType in [ftDateTime {$IFDEF COMPILER6_UP}, ftTimeStamp {$ENDIF}]);
end;

procedure TJvDBDateTimePicker.UpdateData(Sender: TObject);
begin
  // update value in datalink with date value in control, not from system
  // DataLink field might be empty

  if not(Assigned(Field) and FDataLink.Editing) then
    Exit;
  if Kind = dtkDate then
    begin
      if Trunc(NullDate) = Trunc(DateTime) then
        if TrimValue or not IsDateAndTimeField then
          Field.Value := Null
        else
          Field.AsDateTime := Frac(DateTime)
      else
        if TrimValue or not IsDateAndTimeField then
          Field.AsDateTime := Trunc(DateTime)
        else
          Field.AsDateTime := DateTime;
    end
  else
    if IsDateAndTimeField then
      begin
        if Frac(NullDate) = Frac(DateTime) then
          if TrimValue then
            Field.Value := Null
          else
            Field.AsDateTime := Trunc(DateTime)
        else
          if TrimValue then
            Field.AsDateTime := Frac(DateTime)
          else
            Field.AsDateTime := DateTime;
      end;
end;

(0014475)
ZENsan (reporter)
2008-08-04 05:23

One moment left, that if Kind is dtkTime and field is not IsDateAndTimeField then I ignore the update...
Maybe there is better solution. But this I think is not bad also.
(0014493)
obones (administrator)
2008-08-12 00:26

I'm seeing it just fine now. Evaluating proposed fix...
(0014494)
obones (administrator)
2008-08-12 00:30

Why all those changes?
I simply replaced

    if Frac(NullDate) = Frac(DateTime) then
      Field.AsDateTime := Trunc(DateTime)

by

    if Frac(NullDate) = Frac(DateTime) then
      if TrimValue then
        Field.Value := Null
      else
        Field.AsDateTime := Trunc(DateTime)

And it solves the issue.
What do you think?
(0014497)
ZENsan (reporter)
2008-08-12 02:13

If it works exactly the same way, then ok.
Does it covers situation when that is not date and time field..?
(0014498)
obones (administrator)
2008-08-12 02:17

I don't know. Can you test that?
(0014499)
ZENsan (reporter)
2008-08-12 02:19

:)

Can you upload the PAS file for that unit?
(0014500)
obones (administrator)
2008-08-12 02:27

Done
(0014501)
ZENsan (reporter)
2008-08-12 02:51

if Kind = dtkDate then
  begin
    if Trunc(NullDate) = Trunc(DateTime) then
      Field.Value := Null
    else
    if IsDateAndTimeField then
      Field.AsDateTime := DateTime
    else
      Field.AsDateTime := Trunc(DateTime);
  end

In your source..
    if Trunc(NullDate) = Trunc(DateTime) then
      Field.Value := Null
will clear the time part if TrimValue is set to true. And this is not correct way.

So I think that this source covers all proprties like TrimValue and also checks for Field datatype (so that it supports time part) so why there is so many checks..

  if (Field = nil) or not FDataLink.Editing then
    Exit;
    
  if Kind = dtkDate then
    begin
      if Trunc(NullDate) = Trunc(DateTime) then
        if TrimValue or not IsDateAndTimeField then
          Field.Value := Null
        else
          Field.AsDateTime := Frac(DateTime)
      else
        if TrimValue or not IsDateAndTimeField then
          Field.AsDateTime := Trunc(DateTime)
        else
          Field.AsDateTime := DateTime;
    end
  else
    if IsDateAndTimeField then
      begin
        if Frac(NullDate) = Frac(DateTime) then
          if TrimValue then
            Field.Value := Null
          else
            Field.AsDateTime := Trunc(DateTime)
        else
          if TrimValue then
            Field.AsDateTime := Frac(DateTime)
          else
            Field.AsDateTime := DateTime;
      end;

And with this code user can understand all the logic of this control.

What you think?
(0014502)
obones (administrator)
2008-08-12 03:46

Yep, that's better. This is now in SVN.

- Issue History
Date Modified Username Field Change
2008-07-09 08:18 ZENsan New Issue
2008-07-15 01:00 obones Note Added: 0014378
2008-07-15 01:00 obones Status new => feedback
2008-07-15 23:45 ZENsan File Added: Project1.rar
2008-07-15 23:46 ZENsan Note Added: 0014383
2008-07-21 00:24 obones Status feedback => acknowledged
2008-07-23 06:36 obones Status acknowledged => resolved
2008-07-23 06:36 obones Resolution open => unable to reproduce
2008-07-23 06:36 obones Assigned To => obones
2008-07-23 06:36 obones Note Added: 0014414
2008-07-27 01:49 ZENsan Status resolved => feedback
2008-07-27 01:49 ZENsan Resolution unable to reproduce => reopened
2008-07-27 01:49 ZENsan Note Added: 0014460
2008-07-27 01:49 ZENsan File Added: HowToDo.zip
2008-07-27 01:50 ZENsan Note Added: 0014461
2008-08-03 23:33 ZENsan Note Added: 0014471
2008-08-03 23:36 ZENsan Note Edited: 0014471
2008-08-03 23:41 ZENsan Note Deleted: 0014471
2008-08-03 23:43 ZENsan Note Added: 0014472
2008-08-03 23:45 ZENsan Note Edited: 0014472
2008-08-03 23:49 ZENsan Note Edited: 0014472
2008-08-03 23:50 ZENsan Note Edited: 0014472
2008-08-04 05:21 ZENsan Note Edited: 0014472
2008-08-04 05:23 ZENsan Note Added: 0014475
2008-08-12 00:26 obones Note Added: 0014493
2008-08-12 00:26 obones Status feedback => confirmed
2008-08-12 00:30 obones Note Added: 0014494
2008-08-12 00:30 obones Status confirmed => feedback
2008-08-12 02:13 ZENsan Note Added: 0014497
2008-08-12 02:17 obones Note Added: 0014498
2008-08-12 02:19 ZENsan Note Added: 0014499
2008-08-12 02:27 obones File Added: JvDBDateTimePicker.pas
2008-08-12 02:27 obones Note Added: 0014500
2008-08-12 02:51 ZENsan Note Added: 0014501
2008-08-12 03:46 obones Status feedback => resolved
2008-08-12 03:46 obones Fixed in Version => Daily / SVN
2008-08-12 03:46 obones Resolution reopened => fixed
2008-08-12 03:46 obones Note Added: 0014502


Mantis 1.1.6[^]
Copyright © 2000 - 2008 Mantis Group
Powered by Mantis Bugtracker