]> git.saurik.com Git - wxWidgets.git/blobdiff - include/wx/datetime.inl
Removed unnecessary code from utilsunx.cpp
[wxWidgets.git] / include / wx / datetime.inl
index 9c0dec16a370c2370f240537036bc834c4387829..8d3112b6a43f763484373648389df3075a65d73e 100644 (file)
     #error "This file is only included by wx/datetime.h, don't include it manually!"
 #endif
 
     #error "This file is only included by wx/datetime.h, don't include it manually!"
 #endif
 
+// ----------------------------------------------------------------------------
+// private macros
+// ----------------------------------------------------------------------------
+
 #define MILLISECONDS_PER_DAY 86400000l
 
 #define MILLISECONDS_PER_DAY 86400000l
 
+// some broken compilers (HP-UX CC) refuse to compile the "normal" version, but
+// using a temp variable always might prevent other compilers from optimising
+// it away - hence use of this ugly macro
+#ifndef __HPUX__
+    #define MODIFY_AND_RETURN(op) return wxDateTime(*this).op
+#else
+    #define MODIFY_AND_RETURN(op) wxDateTime dt(*this); dt.op; return dt
+#endif
+
 // ----------------------------------------------------------------------------
 // wxDateTime construction
 // ----------------------------------------------------------------------------
 // ----------------------------------------------------------------------------
 // wxDateTime construction
 // ----------------------------------------------------------------------------
@@ -35,15 +48,21 @@ bool wxDateTime::IsInStdRange() const
 /* static */
 wxDateTime wxDateTime::Now()
 {
 /* static */
 wxDateTime wxDateTime::Now()
 {
-    return wxDateTime(GetTimeNow());
+    return wxDateTime(*GetTmNow());
 }
 
 /* static */
 wxDateTime wxDateTime::Today()
 {
 }
 
 /* static */
 wxDateTime wxDateTime::Today()
 {
-    return wxDateTime((time_t)(86400*(GetTimeNow() / 86400)));
+    struct tm *tm = GetTmNow();
+    tm->tm_hour =
+    tm->tm_min =
+    tm->tm_sec = 0;
+
+    return wxDateTime(*tm);
 }
 
 }
 
+#if (!(defined(__VISAGECPP__) && __IBMCPP__ >= 400))
 wxDateTime& wxDateTime::Set(time_t timet)
 {
     // assign first to avoid long multiplication overflow!
 wxDateTime& wxDateTime::Set(time_t timet)
 {
     // assign first to avoid long multiplication overflow!
@@ -52,16 +71,20 @@ wxDateTime& wxDateTime::Set(time_t timet)
 
     return *this;
 }
 
     return *this;
 }
+#endif
 
 wxDateTime& wxDateTime::SetToCurrent()
 {
 
 wxDateTime& wxDateTime::SetToCurrent()
 {
-    return Set(GetTimeNow());
+    *this = Now();
+    return *this;
 }
 
 }
 
+#if (!(defined(__VISAGECPP__) && __IBMCPP__ >= 400))
 wxDateTime::wxDateTime(time_t timet)
 {
     Set(timet);
 }
 wxDateTime::wxDateTime(time_t timet)
 {
     Set(timet);
 }
+#endif
 
 wxDateTime::wxDateTime(const struct tm& tm)
 {
 
 wxDateTime::wxDateTime(const struct tm& tm)
 {
@@ -133,6 +156,57 @@ bool wxDateTime::SetToLastWeekDay(WeekDay weekday,
     return SetToWeekDay(weekday, -1, month, year);
 }
 
     return SetToWeekDay(weekday, -1, month, year);
 }
 
+wxDateTime wxDateTime::GetWeekDayInSameWeek(WeekDay weekday) const
+{
+    MODIFY_AND_RETURN( SetToWeekDayInSameWeek(weekday) );
+}
+
+wxDateTime wxDateTime::GetNextWeekDay(WeekDay weekday) const
+{
+    MODIFY_AND_RETURN( SetToNextWeekDay(weekday) );
+}
+
+wxDateTime wxDateTime::GetPrevWeekDay(WeekDay weekday) const
+{
+    MODIFY_AND_RETURN( SetToPrevWeekDay(weekday) );
+}
+
+wxDateTime wxDateTime::GetWeekDay(WeekDay weekday,
+                                  int n,
+                                  Month month,
+                                  int year) const
+{
+    wxDateTime dt(*this);
+
+    return dt.SetToWeekDay(weekday, n, month, year) ? dt : wxInvalidDateTime;
+}
+
+wxDateTime wxDateTime::GetLastWeekDay(WeekDay weekday,
+                                      Month month,
+                                      int year)
+{
+    wxDateTime dt(*this);
+
+    return dt.SetToLastWeekDay(weekday, month, year) ? dt : wxInvalidDateTime;
+}
+
+wxDateTime wxDateTime::GetWeek(wxDateTime_t numWeek, WeekDay weekday) const
+{
+    wxDateTime dt(*this);
+
+    return dt.SetToTheWeek(numWeek, weekday) ? dt : wxInvalidDateTime;
+}
+
+wxDateTime wxDateTime::GetLastMonthDay(Month month, int year) const
+{
+    MODIFY_AND_RETURN( SetToLastMonthDay(month, year) );
+}
+
+wxDateTime wxDateTime::GetYearDay(wxDateTime_t yday) const
+{
+    MODIFY_AND_RETURN( SetToYearDay(yday) );
+}
+
 // ----------------------------------------------------------------------------
 // wxDateTime comparison
 // ----------------------------------------------------------------------------
 // ----------------------------------------------------------------------------
 // wxDateTime comparison
 // ----------------------------------------------------------------------------
@@ -279,19 +353,20 @@ wxDateTime& wxDateTime::operator+=(const wxDateSpan& diff)
 // wxDateTime and timezones
 // ----------------------------------------------------------------------------
 
 // wxDateTime and timezones
 // ----------------------------------------------------------------------------
 
-wxDateTime wxDateTime::ToTimezone(const wxDateTime::TimeZone& tz) const
+wxDateTime wxDateTime::ToTimezone(const wxDateTime::TimeZone& tz,
+                                  bool noDST) const
 {
 {
-    return wxDateTime(*this).MakeTimezone(tz);
+    MODIFY_AND_RETURN( MakeTimezone(tz, noDST) );
 }
 
 // ----------------------------------------------------------------------------
 // wxTimeSpan construction
 // ----------------------------------------------------------------------------
 
 }
 
 // ----------------------------------------------------------------------------
 // wxTimeSpan construction
 // ----------------------------------------------------------------------------
 
-wxTimeSpan::wxTimeSpan(int hours, int minutes, int seconds, int milliseconds)
+wxTimeSpan::wxTimeSpan(long hours, long minutes, long seconds, long milliseconds)
 {
     // assign first to avoid precision loss
 {
     // assign first to avoid precision loss
-    m_diff = (long)hours;
+    m_diff = hours;
     m_diff *= 60l;
     m_diff += minutes;
     m_diff *= 60l;
     m_diff *= 60l;
     m_diff += minutes;
     m_diff *= 60l;
@@ -430,3 +505,5 @@ wxDateSpan& wxDateSpan::Neg()
 }
 
 #undef MILLISECONDS_PER_DAY
 }
 
 #undef MILLISECONDS_PER_DAY
+
+#undef MODIFY_AND_RETURN