简体   繁体   English

无法设置wxDateTime日,月和年

[英]Cannot set wxDateTime day, month and year

I am trying a very simple code for "licence expiry check". 我正在尝试一个非常简单的“许可证到期检查”代码。 However, the following bit is always taking me to the first condition, ie, expired, although I set the month to June. 但是,尽管我将月份设置为6月,但以下情况总是使我处于第一个条件,即过期。 I cannot seem to figure out what the problem is. 我似乎无法弄清楚问题出在哪里。 I would really appreciate some help. 我真的很感谢您的帮助。

LicDMY.LicDate = wxDateTime::Today(); 
LicDMY.TDay = wxDateTime::Today();
LicDMY.LicDate.SetYear(2019);
LicDMY.LicDate.SetMonth(wxDateTime::Jun);
LicDMY.LicDate.SetDay(30);
if(LicDMY.LicDate.IsEarlierThan(LicDMY.TDay)||LicDMY.LicDate.IsEqualTo(LicDMY.TDay))
    message = new wxStaticText(this, wxID_ANY, wxT("Expired! Renew License \n"));
else
    message = new wxStaticText(this, wxID_ANY, wxT("Welcome! \n"));

Calling wxDateTime::SetMonth(wxDateTime::Jun) would make the object invalid when its current day is 31, as it happens on Jan 31, when this question was asked. 调用wxDateTime::SetMonth(wxDateTime::Jun)将使对象在其当前日期为31(例如,在1月31日询问该问题)时无效。 You could exchange the order of SetDay() and SetMonth() calls to make this work or, preferably, just use Set(30, wxDateTime::Jun, 2019) to change the entire date part at once or even write LicDate = wxDateTime(30, wxDateTime::Jun, 2019) which might be more readable. 您可以交换SetDay()SetMonth()调用的顺序以使此工作有效,或者最好使用Set(30, wxDateTime::Jun, 2019)一次更改整个日期部分,甚至写LicDate = wxDateTime(30, wxDateTime::Jun, 2019)可能更具可读性。

Finally, it looks like you are not using debug facilities of wxWidgets (ie compile your code with NDEBUG defined) as otherwise you would have been immediately notified about the problem because you would have got an assertion failure with the message saying that assert "(0 < day) && (day <= GetNumberOfDays(month, year))" failed in Set(): Invalid date in wxDateTime::Set() . 最后,看起来您好像没有使用wxWidgets的调试功能(即使用NDEBUG定义编译代码),否则您将立即收到有关该问题的通知,因为您将收到断言失败,并显示一条assert "(0 < day) && (day <= GetNumberOfDays(month, year))" failed in Set(): Invalid date in wxDateTime::Set() It is strongly recommended that you do use them, this is very helpful during development and will catch a lot of errors in your use of wxWidgets API. 强烈建议您使用它们,这在开发过程中非常有帮助,并且在使用wxWidgets API时会遇到很多错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM