+// get the number of days in the given month of the given year
+static inline
+wxDateTime::wxDateTime_t GetNumOfDaysInMonth(int year, wxDateTime::Month month)
+{
+ // the number of days in month in Julian/Gregorian calendar: the first line
+ // is for normal years, the second one is for the leap ones
+ static wxDateTime::wxDateTime_t daysInMonth[2][MONTHS_IN_YEAR] =
+ {
+ { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },
+ { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }
+ };
+
+ return daysInMonth[wxDateTime::IsLeapYear(year)][month];
+}
+
+// ensure that the timezone variable is set by calling localtime
+static int GetTimeZone()
+{
+ // set to TRUE when the timezone is set
+ static bool s_timezoneSet = FALSE;
+
+ wxCRIT_SECT_LOCKER(lock, gs_critsectTimezone);
+
+ if ( !s_timezoneSet )
+ {
+ // just call localtime() instead of figuring out whether this system
+ // supports tzset(), _tzset() or something else
+ time_t t;
+ (void)localtime(&t);
+
+ s_timezoneSet = TRUE;
+ }
+
+ return (int)timezone;
+}
+
+// return the integral part of the JDN for the midnight of the given date (to
+// get the real JDN you need to add 0.5, this is, in fact, JDN of the
+// noon of the previous day)
+static long GetTruncatedJDN(wxDateTime::wxDateTime_t day,
+ wxDateTime::Month mon,
+ int year)
+{
+ // CREDIT: code below is by Scott E. Lee (but bugs are mine)
+
+ // check the date validity
+ wxASSERT_MSG(
+ (year > JDN_0_YEAR) ||
+ ((year == JDN_0_YEAR) && (mon > JDN_0_MONTH)) ||
+ ((year == JDN_0_YEAR) && (mon == JDN_0_MONTH) && (day >= JDN_0_DAY)),
+ _T("date out of range - can't convert to JDN")
+ );
+
+ // make the year positive to avoid problems with negative numbers division
+ year += 4800;
+
+ // months are counted from March here
+ int month;
+ if ( mon >= wxDateTime::Mar )
+ {
+ month = mon - 2;
+ }
+ else
+ {
+ month = mon + 10;
+ year--;
+ }
+
+ // now we can simply add all the contributions together
+ return ((year / 100) * DAYS_PER_400_YEARS) / 4
+ + ((year % 100) * DAYS_PER_4_YEARS) / 4
+ + (month * DAYS_PER_5_MONTHS + 2) / 5
+ + day
+ - JDN_OFFSET;
+}
+