]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/datetime.cpp
wxTLW::SetLeft/RightMenu of smart phones documented.
[wxWidgets.git] / src / common / datetime.cpp
index 4aec62ea5c346203c21417633083a77d4ec6d20b..c8f8b2aea594b0d27ea827801f36b7f6596b510d 100644 (file)
@@ -1646,19 +1646,49 @@ wxDateTime& wxDateTime::Add(const wxDateSpan& diff)
 // Weekday and monthday stuff
 // ----------------------------------------------------------------------------
 
-bool wxDateTime::SetToTheWeek(wxDateTime_t numWeek,
-                              WeekDay weekday,
-                              WeekFlags flags)
+// convert Sun, Mon, ..., Sat into 6, 0, ..., 5
+static inline int ConvertWeekDayToMondayBase(int wd)
+{
+    return wd == wxDateTime::Sun ? 6 : wd - 1;
+}
+
+/* static */
+wxDateTime
+wxDateTime::SetToWeekOfYear(int year, wxDateTime_t numWeek, WeekDay wd)
 {
     wxASSERT_MSG( numWeek > 0,
                   _T("invalid week number: weeks are counted from 1") );
 
-    int year = GetYear();
+    // Jan 4 always lies in the 1st week of the year
+    wxDateTime dt(4, Jan, year);
+    dt.SetToWeekDayInSameWeek(wd);
+    dt += wxDateSpan::Weeks(numWeek - 1);
+
+    return dt;
+}
 
+// use a separate function to avoid warnings about using deprecated
+// SetToTheWeek in GetWeek below
+static wxDateTime
+SetToTheWeek(int year,
+             wxDateTime::wxDateTime_t numWeek,
+             wxDateTime::WeekDay weekday,
+             wxDateTime::WeekFlags flags)
+{
     // Jan 4 always lies in the 1st week of the year
-    Set(4, Jan, year);
-    SetToWeekDayInSameWeek(weekday, flags) += wxDateSpan::Weeks(numWeek - 1);
+    wxDateTime dt(4, wxDateTime::Jan, year);
+    dt.SetToWeekDayInSameWeek(weekday, flags);
+    dt += wxDateSpan::Weeks(numWeek - 1);
 
+    return dt;
+}
+
+bool wxDateTime::SetToTheWeek(wxDateTime_t numWeek,
+                              WeekDay weekday,
+                              WeekFlags flags)
+{
+    int year = GetYear();
+    *this = ::SetToTheWeek(year, numWeek, weekday, flags);
     if ( GetYear() != year )
     {
         // oops... numWeek was too big
@@ -1668,6 +1698,13 @@ bool wxDateTime::SetToTheWeek(wxDateTime_t numWeek,
     return true;
 }
 
+wxDateTime wxDateTime::GetWeek(wxDateTime_t numWeek,
+                               WeekDay weekday,
+                               WeekFlags flags) const
+{
+    return ::SetToTheWeek(GetYear(), numWeek, weekday, flags);
+}
+
 wxDateTime& wxDateTime::SetToLastMonthDay(Month month,
                                           int year)
 {
@@ -1844,12 +1881,6 @@ wxDateTime::wxDateTime_t wxDateTime::GetDayOfYear(const TimeZone& tz) const
     return GetDayOfYearFromTm(GetTm(tz));
 }
 
-// convert Sun, Mon, ..., Sat into 6, 0, ..., 5
-static inline int ConvertWeekDayToMondayBase(int wd)
-{
-    return wd == wxDateTime::Sun ? 6 : wd - 1;
-}
-
 wxDateTime::wxDateTime_t
 wxDateTime::GetWeekOfYear(wxDateTime::WeekFlags flags, const TimeZone& tz) const
 {