Opened 9 years ago

Closed 9 years ago

Last modified 9 years ago

#13786 closed enhancement (wontfix)

Add define of "zero value" for wxDateTime

Reported by: Silverstorm82 Owned by:
Priority: low Milestone:
Component: base Version: 2.9.3
Keywords: wxDateTime Cc:
Blocked By: Blocking:
Patch: no


wxDateTime(wxLongLong(0)) does not represent 1970-01-01 00:00:00 but some other value depending on the timezone selected on the computer (in my case UTC+1 which results in 1970-01-01 01:00:00).

In connection with the new wxTimePickerCtrl this may be confusing when trying to initialize the control with 00:00:00, which will fail depending on the timezone and result in an initialization with 01:00:00.

Therefore I would suggest a define like

#define wxZeroDateTime wxDateTime(wxLongLong(0)).ToUTC()

in the wxDateTime files to make initializing wxTimePickerCtrl a bit easier.

Right now I am not familiar with the patch system, so I am unable to create a patch for this but as it is only one line code it may be pretty fast to be implemented if accepted by the wxWidgets team.

Attachments (1)

wxZeroDateTime.patch download (472 bytes) - added by Silverstorm82 9 years ago.
wxZeroDateTime patch file

Download all attachments as: .zip

Change History (5)

Changed 9 years ago by Silverstorm82

wxZeroDateTime patch file

comment:1 Changed 9 years ago by Silverstorm82

Added patch file as suggestion.

comment:2 Changed 9 years ago by vadz

  • Resolution set to wontfix
  • Status changed from new to closed

Sorry, I really don't like this. Jan 1 1970 is not a special day at all, why should we have a special constant for it? As for wxTimePickerCtrl, I think you shouldn't use wxDateTime(wxLongLong(0)) to initialize it but wxDateTime::Today() for example.

Perhaps we could also add convenience methods working with (hour, minute, second) triplets to wxTimePickerCtrl, but I don't really see the need to change anything at wxDateTime level.

comment:3 Changed 9 years ago by Silverstorm82

Well, I didn't want to have a special constant for 1970-01-01 but a constant that causes wxTimePickerCtrl initializing to 00:00:00. The date is not important here and that wasn't the idea about the constant but to have an easy way to understand the initialization. wxDateTime::Today() works fine but is harder to understand.

However, I think your idea would be the nicest approach or even a Format() like function. Another possibility may be two seperate classes for dates and times and one that incorporates both. I don't know how plans are about that or if it has been decided to have the combined approach only.

Anyway, thanks for the response and keep up the good work.

comment:4 Changed 9 years ago by vadz

I don't think it's a good idea to add a class for time only, there is not much that can be done with it. But adding a method taking just the time components and constructing wxDateTime for today from them could be useful...

Note: See TracTickets for help on using tickets.