static inline int minimumYearForDST() { // Because of the 2038 issue (see maximumYearForDST) if the current year is // greater than the max year minus 27 (2010), we want to use the max year // minus 27 instead, to ensure there is a range of 28 years that all years // can map to. return std::min(msToYear(jsCurrentTime()), maximumYearForDST() - 27) ; }
/* * Find an equivalent year for the one given, where equivalence is deterined by * the two years having the same leapness and the first day of the year, falling * on the same day of the week. * * This function returns a year between this current year and 2037, however this * function will potentially return incorrect results if the current year is after * 2010, (rdar://problem/5052975), if the year passed in is before 1900 or after * 2100, (rdar://problem/5055038). */ int equivalentYearForDST(int year) { static int minYear = mimimumYearForDST(); static int maxYear = maximumYearForDST(); int difference; if (year > maxYear) difference = minYear - year; else if (year < minYear) difference = maxYear - year; else return year; int quotient = difference / 28; int product = (quotient) * 28; year += product; ASSERT((year >= minYear && year <= maxYear) || (product - year == static_cast<int>(NaN))); return year; }
/* * Find an equivalent year for the one given, where equivalence is deterined by * the two years having the same leapness and the first day of the year, falling * on the same day of the week. * * This function returns a year between this current year and 2037, however this * function will potentially return incorrect results if the current year is after * 2010, (rdar://problem/5052975), if the year passed in is before 1900 or after * 2100, (rdar://problem/5055038). */ int equivalentYearForDST(int year) { // It is ok if the cached year is not the current year as long as the rules // for DST did not change between the two years; if they did the app would need // to be restarted. static int minYear = minimumYearForDST(); int maxYear = maximumYearForDST(); int difference; if (year > maxYear) difference = minYear - year; else if (year < minYear) difference = maxYear - year; else return year; int quotient = difference / 28; int product = (quotient) * 28; year += product; return year; }
/* * Find an equivalent year for the one given, where equivalence is deterined by * the two years having the same leapness and the first day of the year, falling * on the same day of the week. * * This function returns a year between this current year and 2037, however this * function will potentially return incorrect results if the current year is after * 2010, (rdar://problem/5052975), if the year passed in is before 1900 or after * 2100, (rdar://problem/5055038). */ int equivalentYearForDST(int year) { // It is ok if the cached year is not the current year as long as the rules // for DST did not change between the two years; if they did the app would need // to be restarted. static int minYear = minimumYearForDST(); int maxYear = maximumYearForDST(); int difference; if (year > maxYear) difference = minYear - year; else if (year < minYear) difference = maxYear - year; else return year; int quotient = difference / 28; int product = (quotient) * 28; year += product; ASSERT((year >= minYear && year <= maxYear) || (product - year == static_cast<int>(std::numeric_limits<double>::quiet_NaN()))); return year; }