class static */
| 1942 | // to do all the right stuff, as long as we call them properly! |
| 1943 | |
| 1944 | /* class static */ void |
| 1945 | XMPUtils::SetTimeZone ( XMP_DateTime * xmpTime ) |
| 1946 | { |
| 1947 | XMP_Assert ( xmpTime != 0 ); // ! Enforced by wrapper. |
| 1948 | |
| 1949 | if ( (xmpTime->tzSign != 0) || (xmpTime->tzHour != 0) || (xmpTime->tzMinute != 0) ) { |
| 1950 | XMP_Throw ( "SetTimeZone can only be used on \"zoneless\" times", kXMPErr_BadParam ); |
| 1951 | } |
| 1952 | |
| 1953 | // Create ansi_tt form of the input time. Need the ansi_tm form to make the ansi_tt form. |
| 1954 | |
| 1955 | ansi_tt ttTime; |
| 1956 | ansi_tm tmLocal, tmUTC; |
| 1957 | |
| 1958 | if ( (xmpTime->year == 0) && (xmpTime->month == 0) && (xmpTime->day == 0) ) { |
| 1959 | ansi_tt now = ansi_time(0); |
| 1960 | if ( now == -1 ) XMP_Throw ( "Failure from ANSI C time function", kXMPErr_ExternalFailure ); |
| 1961 | ansi_localtime ( &now, &tmLocal ); |
| 1962 | } else { |
| 1963 | if (xmpTime->year < std::numeric_limits<decltype(tmLocal.tm_year)>::min() + 1900) { |
| 1964 | XMP_Throw ( "Invalid year", kXMPErr_BadParam); |
| 1965 | } else if (xmpTime->year > std::numeric_limits<decltype(tmLocal.tm_year)>::max()) { |
| 1966 | XMP_Throw ( "Invalid year", kXMPErr_BadParam); |
| 1967 | } else { |
| 1968 | tmLocal.tm_year = xmpTime->year - 1900; |
| 1969 | } |
| 1970 | tmLocal.tm_mon = xmpTime->month - 1; |
| 1971 | tmLocal.tm_mday = xmpTime->day; |
| 1972 | } |
| 1973 | |
| 1974 | tmLocal.tm_hour = xmpTime->hour; |
| 1975 | tmLocal.tm_min = xmpTime->minute; |
| 1976 | tmLocal.tm_sec = xmpTime->second; |
| 1977 | tmLocal.tm_isdst = -1; // Don't know if daylight time is in effect. |
| 1978 | |
| 1979 | ttTime = ansi_mktime ( &tmLocal ); |
| 1980 | if ( ttTime == -1 ) XMP_Throw ( "Failure from ANSI C mktime function", kXMPErr_ExternalFailure ); |
| 1981 | |
| 1982 | // Convert back to a localized ansi_tm time and get the corresponding UTC ansi_tm time. |
| 1983 | |
| 1984 | ansi_localtime ( &ttTime, &tmLocal ); |
| 1985 | ansi_gmtime ( &ttTime, &tmUTC ); |
| 1986 | |
| 1987 | // Get the offset direction and amount. |
| 1988 | |
| 1989 | ansi_tm tmx = tmLocal; // ! Note that mktime updates the ansi_tm parameter, messing up difftime! |
| 1990 | ansi_tm tmy = tmUTC; |
| 1991 | tmx.tm_isdst = tmy.tm_isdst = 0; |
| 1992 | ansi_tt ttx = ansi_mktime ( &tmx ); |
| 1993 | ansi_tt tty = ansi_mktime ( &tmy ); |
| 1994 | double diffSecs; |
| 1995 | |
| 1996 | if ( (ttx != -1) && (tty != -1) ) { |
| 1997 | diffSecs = ansi_difftime ( ttx, tty ); |
| 1998 | } else { |
| 1999 | #if XMP_MacBuild |
| 2000 | // Looks like Apple's mktime is buggy - see W1140533. But the offset is visible. |
| 2001 | diffSecs = tmLocal.tm_gmtoff; |
nothing calls this directly
no test coverage detected