mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 834988 - Invert the meaning of LocalUTCDifferenceSeconds and rename it to UTCToLocalStandardOffsetSeconds. This gives it the same sign/semantics (if different units) as the -8 in UTC-8, and it makes it consistent with ES5's LocalTZA concept. Also add an interface comment with two examples of its behavior. r=dmandelin
--HG-- extra : rebase_source : 3e56a9fcc590c6b42c2782bd30431db8f3464825
This commit is contained in:
parent
022804a80d
commit
7f65bf94ef
@ -38,8 +38,22 @@ ComputeUTCTime(time_t t, struct tm *ptm)
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
* Compute the offset in seconds from the current UTC time to the current local
|
||||
* standard time (i.e. not including any offset due to DST).
|
||||
*
|
||||
* Examples:
|
||||
*
|
||||
* Suppose we are in California, USA on January 1, 2013 at 04:00 PST (UTC-8, no
|
||||
* DST in effect), corresponding to 12:00 UTC. This function would then return
|
||||
* -8 * SecondsPerHour, or -28800.
|
||||
*
|
||||
* Or suppose we are in Berlin, Germany on July 1, 2013 at 17:00 CEST (UTC+2,
|
||||
* DST in effect), corresponding to 15:00 UTC. This function would then return
|
||||
* +1 * SecondsPerHour, or +3600.
|
||||
*/
|
||||
static int32_t
|
||||
LocalUTCDifferenceSeconds()
|
||||
UTCToLocalStandardOffsetSeconds()
|
||||
{
|
||||
using js::SecondsPerDay;
|
||||
using js::SecondsPerHour;
|
||||
@ -96,24 +110,24 @@ LocalUTCDifferenceSeconds()
|
||||
int utc_secs = utc.tm_hour * SecondsPerHour + utc.tm_min * SecondsPerMinute;
|
||||
int local_secs = local.tm_hour * SecondsPerHour + local.tm_min * SecondsPerMinute;
|
||||
|
||||
// Callers expect the negative difference of the offset from local time
|
||||
// and UTC.
|
||||
|
||||
// Same-day? Just subtract the seconds counts.
|
||||
if (utc.tm_mday == local.tm_mday)
|
||||
return utc_secs - local_secs;
|
||||
return local_secs - utc_secs;
|
||||
|
||||
// Local date comes after UTC (offset in the positive range).
|
||||
// If we have more UTC seconds, move local seconds into the UTC seconds'
|
||||
// frame of reference and then subtract.
|
||||
if (utc_secs > local_secs)
|
||||
return utc_secs - (SecondsPerDay + local_secs);
|
||||
return (SecondsPerDay + local_secs) - utc_secs;
|
||||
|
||||
// Local date comes before UTC (offset in the negative range).
|
||||
return (utc_secs + SecondsPerDay) - local_secs;
|
||||
// Otherwise we have more local seconds, so move the UTC seconds into the
|
||||
// local seconds' frame of reference and then subtract.
|
||||
return local_secs - (utc_secs + SecondsPerDay);
|
||||
}
|
||||
|
||||
void
|
||||
js::DateTimeInfo::updateTimeZoneAdjustment()
|
||||
{
|
||||
double newTZA = -(LocalUTCDifferenceSeconds() * msPerSecond);
|
||||
double newTZA = UTCToLocalStandardOffsetSeconds() * msPerSecond;
|
||||
if (newTZA == localTZA_)
|
||||
return;
|
||||
|
||||
@ -153,11 +167,9 @@ js::DateTimeInfo::computeDSTOffsetMilliseconds(int64_t localTimeSeconds)
|
||||
MOZ_ASSERT(localTimeSeconds <= MaxUnixTimeT);
|
||||
|
||||
#if defined(XP_WIN)
|
||||
/* Windows does not follow POSIX. Updates to the
|
||||
* TZ environment variable are not reflected
|
||||
* immediately on that platform as they are
|
||||
* on UNIX systems without this call.
|
||||
*/
|
||||
// Windows does not follow POSIX. Updates to the TZ environment variable
|
||||
// are not reflected immediately on that platform as they are on UNIX
|
||||
// systems without this call.
|
||||
_tzset();
|
||||
#endif
|
||||
|
||||
@ -165,11 +177,10 @@ js::DateTimeInfo::computeDSTOffsetMilliseconds(int64_t localTimeSeconds)
|
||||
if (!ComputeLocalTime(static_cast<time_t>(localTimeSeconds), &tm))
|
||||
return 0;
|
||||
|
||||
int32_t base = LocalUTCDifferenceSeconds();
|
||||
int32_t utcToLocalOffsetSeconds = UTCToLocalStandardOffsetSeconds();
|
||||
|
||||
int32_t dayoff = int32_t((localTimeSeconds - base) % (SecondsPerHour * 24));
|
||||
int32_t tmoff = tm.tm_sec + (tm.tm_min * SecondsPerMinute) +
|
||||
(tm.tm_hour * SecondsPerHour);
|
||||
int32_t dayoff = int32_t((localTimeSeconds + utcToLocalOffsetSeconds) % SecondsPerDay);
|
||||
int32_t tmoff = tm.tm_sec + (tm.tm_min * SecondsPerMinute) + (tm.tm_hour * SecondsPerHour);
|
||||
|
||||
int32_t diff = tmoff - dayoff;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user