Added wxTimePickerCtrl::GetTime() and SetTime().
These methods, taking broken down time representation, avoid the problems arising due to DST complications when using wxDateTime to represent the time as special care needs to be taken in this case to avoid using the date part corresponding to a DST change date at which time is discontinuous. Document the problem with the old functions and use the new ones in the sample. See #14137. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@71004 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -50,9 +50,42 @@ public:
|
||||
/*
|
||||
We also inherit Set/GetValue() methods from the base class which define
|
||||
our public API. Notice that the date portion of the date passed as
|
||||
input is ignored and for the result date it's always today, but only
|
||||
the time part of wxDateTime objects is really significant here.
|
||||
input or received as output is or should be ignored, only the time part
|
||||
of wxDateTime objects is really significant here. Use Set/GetTime()
|
||||
below for possibly simpler interface.
|
||||
*/
|
||||
|
||||
// Set the given time.
|
||||
bool SetTime(int hour, int min, int sec)
|
||||
{
|
||||
// Notice that we should use a date on which DST doesn't change to
|
||||
// avoid any problems with time discontinuity so use a fixed date (on
|
||||
// which nobody changes DST) instead of e.g. today.
|
||||
wxDateTime dt(1, wxDateTime::Jan, 2012, hour, min, sec);
|
||||
if ( !dt.IsValid() )
|
||||
{
|
||||
// No need to assert here, wxDateTime already does it for us.
|
||||
return false;
|
||||
}
|
||||
|
||||
SetValue(dt);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Get the current time components. All pointers must be non-NULL.
|
||||
bool GetTime(int* hour, int* min, int* sec) const
|
||||
{
|
||||
wxCHECK_MSG( hour && min && sec, false,
|
||||
wxS("Time component pointers must be non-NULL") );
|
||||
|
||||
const wxDateTime::Tm tm = GetValue().GetTm();
|
||||
*hour = tm.hour;
|
||||
*min = tm.min;
|
||||
*sec = tm.sec;
|
||||
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
#if defined(__WXMSW__) && !defined(__WXUNIVERSAL__)
|
||||
|
Reference in New Issue
Block a user