Recent

Author Topic: [Solved] DateTimePicker is showing 30/12/1899 instead of NULL!  (Read 8376 times)

JD

  • Hero Member
  • *****
  • Posts: 1848
Hi there everyone,

I have a problem that turned up rather suddenly. I have a project with several forms in it. I use the TDatetimePicker component in this project and before any of the forms is displayed, I set the date values on the form to the null date.
 
Code: Pascal  [Select][+][-]
  1. TDateTimePicker(Components[i]).Date := NullDate;
  2.  

Everything has been working fine until yesterday night. On one of the forms, this is not working any more and the dates on the form are being displayed as 30/12/1899!  :o  :o

What could be the reason for this?

Cheers,

JD
« Last Edit: May 09, 2018, 11:16:10 am by JD »
Windows - Lazarus 2.1/FPC 3.2 (built using fpcupdeluxe),
Linux Mint - Lazarus 2.1/FPC 3.2 (built using fpcupdeluxe)

mORMot; Zeos 8; SQLite, PostgreSQL & MariaDB; VirtualTreeView

Thaddy

  • Hero Member
  • *****
  • Posts: 14373
  • Sensorship about opinions does not belong here.
Re: DateTimePicker is showing 30/12/1899 instead of NULL!
« Reply #1 on: May 09, 2018, 09:42:23 am »
Delphi/Windows compatibility. 30/12/1899 = TDateTime(0).
And yes, there is a bug in there that now features as convention. It is not a Pascal bug.
What the DOS/Windows engineers tried to do was make it 1900/1/1/ 00:00:00 or 1899/12/31 23:59:59:999 so you can blame that on Bill Gates himself, or CP/M engineers...
I forgot which one..... :)
Code: Pascal  [Select][+][-]
  1. uses sysutils;
  2. begin
  3.  writeln(DateTimeToStr(0));
  4. end.
Unix time starts at 1970/1/1/00:00:00, btw.
Quote
Everything has been working fine until yesterday night
That's something I don't believe......This has always been the case.
Date property is of type TDateTime. It doesn't know nil. With some massage you can do this, though:
Code: Pascal  [Select][+][-]
  1. uses sysutils,dateutils;
  2. begin
  3.  writeln(DateTimeToStr(DateTimeToUnix(0)));
  4. end.
This will display 0-0-0.
The actual value, however is -2209161600
« Last Edit: May 09, 2018, 10:02:30 am by Thaddy »
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.

Zoran

  • Hero Member
  • *****
  • Posts: 1830
    • http://wiki.lazarus.freepascal.org/User:Zoran
Re: DateTimePicker is showing 30/12/1899 instead of NULL!
« Reply #2 on: May 09, 2018, 10:00:34 am »
Everything has been working fine until yesterday night. On one of the forms, this is not working any more and the dates on the form are being displayed as 30/12/1899!  :o  :o

Did you by any chance add EditBtn unit to uses list last night? That unit has the constant of same name.
Please try with adding unit prefix to the NullDate constant:
Code: Pascal  [Select][+][-]
  1. TDateTimePicker(Components[i]).Date := DateTimePicker.NullDate;

Thaddy

  • Hero Member
  • *****
  • Posts: 14373
  • Sensorship about opinions does not belong here.
Re: DateTimePicker is showing 30/12/1899 instead of NULL!
« Reply #3 on: May 09, 2018, 10:04:50 am »
Did you by any chance add EditBtn unit to uses list last night? That unit has the constant of same name.
That needs a fix, that would be a bug in EditBtn. (Sheer stupid bug, btw). Plz file bug report against Editbtn if this is the case.
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.

Zoran

  • Hero Member
  • *****
  • Posts: 1830
    • http://wiki.lazarus.freepascal.org/User:Zoran
Re: DateTimePicker is showing 30/12/1899 instead of NULL!
« Reply #4 on: May 09, 2018, 10:42:04 am »
Did you by any chance add EditBtn unit to uses list last night? That unit has the constant of same name.
That needs a fix, that would be a bug in EditBtn. (Sheer stupid bug, btw). Plz file bug report against Editbtn if this is the case.

Thaddy, EditBtn had this constant named NullDate before I created DateTimePicker. And there it has unfortunate value zero (which is in my opinion wrong decision -- 30. 12. 1899. should be a valid date like any other, although internally represented by zero value). See http://lazarus-ccr.sourceforge.net/docs/lcl/editbtn/nulldate.html

However, I do not think it is a bug, it's the way it is designed.
It was my fault to name the constant the same as an already existing one (I missed its existance).

Anyway, in DateTimePicker, 30. 12. 1899. (zero) is pefectly regular value, not considered null, and there is NullDate constant, declared with value which is outside of DateTime range (in the sense defined in SysUtils with MinDateTime and MaxDateTime constants).
To test for Null value, TDateTimePicker.DateIsNull method should be used, or IsNullDate function, also declared in DateTimePicker unit.

JD

  • Hero Member
  • *****
  • Posts: 1848
Re: DateTimePicker is showing 30/12/1899 instead of NULL!
« Reply #5 on: May 09, 2018, 11:15:50 am »
Everything has been working fine until yesterday night. On one of the forms, this is not working any more and the dates on the form are being displayed as 30/12/1899!  :o  :o

Did you by any chance add EditBtn unit to uses list last night? That unit has the constant of same name.
Please try with adding unit prefix to the NullDate constant:
Code: Pascal  [Select][+][-]
  1. TDateTimePicker(Components[i]).Date := DateTimePicker.NullDate;

YES!!! You are a genius. I would never have figured that one out. I removed the EditBtn from the uses list and the form is now back to normal. Thanks a million for all your contributions.  :D

JD
Windows - Lazarus 2.1/FPC 3.2 (built using fpcupdeluxe),
Linux Mint - Lazarus 2.1/FPC 3.2 (built using fpcupdeluxe)

mORMot; Zeos 8; SQLite, PostgreSQL & MariaDB; VirtualTreeView

Thaddy

  • Hero Member
  • *****
  • Posts: 14373
  • Sensorship about opinions does not belong here.
Re: [Solved] DateTimePicker is showing 30/12/1899 instead of NULL!
« Reply #6 on: May 09, 2018, 11:25:40 am »
Zoran, even if you created TDateTimePicker after EditBtn was created, it is still a bug in TEditBtn imho.
The author should have been aware of what you and I described. There are conventions for 0 dates in both Linux and Windows. He/she should have adhered to that.
A Linux and Windows compatible solution is in my above replies. But still not the year zero...., just UNIX year zero. Anyway that would display 0-0-0 00:00:00 in a conformant way.
Code: Pascal  [Select][+][-]
  1. UnixToDateTime(-2209161600)
« Last Edit: May 09, 2018, 11:29:18 am by Thaddy »
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.

Thaddy

  • Hero Member
  • *****
  • Posts: 14373
  • Sensorship about opinions does not belong here.
Re: [Solved] DateTimePicker is showing 30/12/1899 instead of NULL!
« Reply #7 on: May 09, 2018, 12:26:08 pm »
Note that function name is hilarious  :D :D :D :D :D Convert the whole of  Unix to TDateTime??  8-) 8-) 8-)
(Given the range of TDateTime, this *should* be possible, btw, as a high level representation of the kernel functions...<silly mode  ::) :-[>)
« Last Edit: May 09, 2018, 12:31:03 pm by Thaddy »
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.

 

TinyPortal © 2005-2018