V8 Project
v8::base::Win32Time Class Reference
+ Collaboration diagram for v8::base::Win32Time:

Classes

union  TimeStamp
 

Public Member Functions

 Win32Time ()
 
 Win32Time (double jstime)
 
 Win32Time (int year, int mon, int day, int hour, int min, int sec)
 
double ToJSTime ()
 
void SetToCurrentTime ()
 
int64_t LocalOffset (TimezoneCache *cache)
 
int64_t DaylightSavingsOffset (TimezoneCache *cache)
 
char * LocalTimezone (TimezoneCache *cache)
 

Private Member Functions

bool InDST (TimezoneCache *cache)
 
FILETIME & ft ()
 
int64_t & t ()
 

Private Attributes

TimeStamp time_
 

Static Private Attributes

static const int64_t kTimeEpoc = 116444736000000000LL
 
static const int64_t kTimeScaler = 10000
 
static const int64_t kMsPerMinute = 60000
 
static const bool kShortTzNames = false
 

Detailed Description

Definition at line 214 of file platform-win32.cc.

Constructor & Destructor Documentation

◆ Win32Time() [1/3]

v8::base::Win32Time::Win32Time ( )

Definition at line 274 of file platform-win32.cc.

274  {
275  t() = 0;
276 }

References t().

+ Here is the call graph for this function:

◆ Win32Time() [2/3]

v8::base::Win32Time::Win32Time ( double  jstime)
explicit

Definition at line 280 of file platform-win32.cc.

280  {
281  t() = static_cast<int64_t>(jstime) * kTimeScaler + kTimeEpoc;
282 }
static const int64_t kTimeScaler
static const int64_t kTimeEpoc

References kTimeEpoc, kTimeScaler, and t().

+ Here is the call graph for this function:

◆ Win32Time() [3/3]

v8::base::Win32Time::Win32Time ( int  year,
int  mon,
int  day,
int  hour,
int  min,
int  sec 
)

Definition at line 286 of file platform-win32.cc.

286  {
287  SYSTEMTIME st;
288  st.wYear = year;
289  st.wMonth = mon;
290  st.wDay = day;
291  st.wHour = hour;
292  st.wMinute = min;
293  st.wSecond = sec;
294  st.wMilliseconds = 0;
295  SystemTimeToFileTime(&st, &ft());
296 }
static int min(int a, int b)
Definition: liveedit.cc:273

References ft(), and v8::internal::min().

+ Here is the call graph for this function:

Member Function Documentation

◆ DaylightSavingsOffset()

int64_t v8::base::Win32Time::DaylightSavingsOffset ( TimezoneCache cache)

Definition at line 425 of file platform-win32.cc.

425  {
426  return InDST(cache) ? 60 * kMsPerMinute : 0;
427 }
static const int64_t kMsPerMinute
bool InDST(TimezoneCache *cache)

References InDST(), and kMsPerMinute.

+ Here is the call graph for this function:

◆ ft()

FILETIME& v8::base::Win32Time::ft ( )
inlineprivate

Definition at line 254 of file platform-win32.cc.

References v8::base::Win32Time::TimeStamp::ft_, and time_.

Referenced by Win32Time().

+ Here is the caller graph for this function:

◆ InDST()

bool v8::base::Win32Time::InDST ( TimezoneCache cache)
private

Definition at line 400 of file platform-win32.cc.

400  {
401  cache->InitializeIfNeeded();
402 
403  // Determine if DST is in effect at the specified time.
404  bool in_dst = false;
405  if (cache->tzinfo_.StandardDate.wMonth != 0 ||
406  cache->tzinfo_.DaylightDate.wMonth != 0) {
407  // Get the local timezone offset for the timestamp in milliseconds.
408  int64_t offset = LocalOffset(cache);
409 
410  // Compute the offset for DST. The bias parameters in the timezone info
411  // are specified in minutes. These must be converted to milliseconds.
412  int64_t dstofs =
413  -(cache->tzinfo_.Bias + cache->tzinfo_.DaylightBias) * kMsPerMinute;
414 
415  // If the local time offset equals the timezone bias plus the daylight
416  // bias then DST is in effect.
417  in_dst = offset == dstofs;
418  }
419 
420  return in_dst;
421 }
int64_t LocalOffset(TimezoneCache *cache)

References v8::base::TimezoneCache::InitializeIfNeeded(), kMsPerMinute, LocalOffset(), and v8::base::TimezoneCache::tzinfo_.

Referenced by DaylightSavingsOffset(), and LocalTimezone().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ LocalOffset()

int64_t v8::base::Win32Time::LocalOffset ( TimezoneCache cache)

Definition at line 366 of file platform-win32.cc.

366  {
367  cache->InitializeIfNeeded();
368 
369  Win32Time rounded_to_second(*this);
370  rounded_to_second.t() = rounded_to_second.t() / 1000 / kTimeScaler *
371  1000 * kTimeScaler;
372  // Convert to local time using POSIX localtime function.
373  // Windows XP Service Pack 3 made SystemTimeToTzSpecificLocalTime()
374  // very slow. Other browsers use localtime().
375 
376  // Convert from JavaScript milliseconds past 1/1/1970 0:00:00 to
377  // POSIX seconds past 1/1/1970 0:00:00.
378  double unchecked_posix_time = rounded_to_second.ToJSTime() / 1000;
379  if (unchecked_posix_time > INT_MAX || unchecked_posix_time < 0) {
380  return 0;
381  }
382  // Because _USE_32BIT_TIME_T is defined, time_t is a 32-bit int.
383  time_t posix_time = static_cast<time_t>(unchecked_posix_time);
384 
385  // Convert to local time, as struct with fields for day, hour, year, etc.
386  tm posix_local_time_struct;
387  if (localtime_s(&posix_local_time_struct, &posix_time)) return 0;
388 
389  if (posix_local_time_struct.tm_isdst > 0) {
390  return (cache->tzinfo_.Bias + cache->tzinfo_.DaylightBias) * -kMsPerMinute;
391  } else if (posix_local_time_struct.tm_isdst == 0) {
392  return (cache->tzinfo_.Bias + cache->tzinfo_.StandardBias) * -kMsPerMinute;
393  } else {
394  return cache->tzinfo_.Bias * -kMsPerMinute;
395  }
396 }

References v8::base::TimezoneCache::InitializeIfNeeded(), kMsPerMinute, kTimeScaler, t(), ToJSTime(), and v8::base::TimezoneCache::tzinfo_.

Referenced by InDST().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ LocalTimezone()

char * v8::base::Win32Time::LocalTimezone ( TimezoneCache cache)

Definition at line 432 of file platform-win32.cc.

432  {
433  // Return the standard or DST time zone name based on whether daylight
434  // saving is in effect at the given time.
435  return InDST(cache) ? cache->dst_tz_name_ : cache->std_tz_name_;
436 }

References v8::base::TimezoneCache::dst_tz_name_, InDST(), and v8::base::TimezoneCache::std_tz_name_.

+ Here is the call graph for this function:

◆ SetToCurrentTime()

void v8::base::Win32Time::SetToCurrentTime ( )

Definition at line 306 of file platform-win32.cc.

306  {
307  // The default GetSystemTimeAsFileTime has a ~15.5ms resolution.
308  // Because we're fast, we like fast timers which have at least a
309  // 1ms resolution.
310  //
311  // timeGetTime() provides 1ms granularity when combined with
312  // timeBeginPeriod(). If the host application for v8 wants fast
313  // timers, it can use timeBeginPeriod to increase the resolution.
314  //
315  // Using timeGetTime() has a drawback because it is a 32bit value
316  // and hence rolls-over every ~49days.
317  //
318  // To use the clock, we use GetSystemTimeAsFileTime as our base;
319  // and then use timeGetTime to extrapolate current time from the
320  // start time. To deal with rollovers, we resync the clock
321  // any time when more than kMaxClockElapsedTime has passed or
322  // whenever timeGetTime creates a rollover.
323 
324  static bool initialized = false;
325  static TimeStamp init_time;
326  static DWORD init_ticks;
327  static const int64_t kHundredNanosecondsPerSecond = 10000000;
328  static const int64_t kMaxClockElapsedTime =
329  60*kHundredNanosecondsPerSecond; // 1 minute
330 
331  // If we are uninitialized, we need to resync the clock.
332  bool needs_resync = !initialized;
333 
334  // Get the current time.
335  TimeStamp time_now;
336  GetSystemTimeAsFileTime(&time_now.ft_);
337  DWORD ticks_now = timeGetTime();
338 
339  // Check if we need to resync due to clock rollover.
340  needs_resync |= ticks_now < init_ticks;
341 
342  // Check if we need to resync due to elapsed time.
343  needs_resync |= (time_now.t_ - init_time.t_) > kMaxClockElapsedTime;
344 
345  // Check if we need to resync due to backwards time change.
346  needs_resync |= time_now.t_ < init_time.t_;
347 
348  // Resync the clock if necessary.
349  if (needs_resync) {
350  GetSystemTimeAsFileTime(&init_time.ft_);
351  init_ticks = ticks_now = timeGetTime();
352  initialized = true;
353  }
354 
355  // Finally, compute the actual time. Why is this so hard.
356  DWORD elapsed = ticks_now - init_ticks;
357  this->time_.t_ = init_time.t_ + (static_cast<int64_t>(elapsed) * 10000);
358 }
typedef DWORD(__stdcall *DLL_FUNC_TYPE(SymGetOptions))(VOID)

References v8::base::DWORD(), v8::base::Win32Time::TimeStamp::ft_, v8::base::Win32Time::TimeStamp::t_, and time_.

+ Here is the call graph for this function:

◆ t()

int64_t& v8::base::Win32Time::t ( )
inlineprivate

Definition at line 257 of file platform-win32.cc.

257 { return time_.t_; }

References v8::base::Win32Time::TimeStamp::t_, and time_.

Referenced by LocalOffset(), ToJSTime(), and Win32Time().

+ Here is the caller graph for this function:

◆ ToJSTime()

double v8::base::Win32Time::ToJSTime ( )

Definition at line 300 of file platform-win32.cc.

300  {
301  return static_cast<double>((t() - kTimeEpoc) / kTimeScaler);
302 }

References kTimeEpoc, kTimeScaler, and t().

Referenced by LocalOffset().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Member Data Documentation

◆ kMsPerMinute

const int64_t v8::base::Win32Time::kMsPerMinute = 60000
staticprivate

Definition at line 245 of file platform-win32.cc.

Referenced by DaylightSavingsOffset(), InDST(), and LocalOffset().

◆ kShortTzNames

const bool v8::base::Win32Time::kShortTzNames = false
staticprivate

Definition at line 248 of file platform-win32.cc.

◆ kTimeEpoc

const int64_t v8::base::Win32Time::kTimeEpoc = 116444736000000000LL
staticprivate

Definition at line 243 of file platform-win32.cc.

Referenced by ToJSTime(), and Win32Time().

◆ kTimeScaler

const int64_t v8::base::Win32Time::kTimeScaler = 10000
staticprivate

Definition at line 244 of file platform-win32.cc.

Referenced by LocalOffset(), ToJSTime(), and Win32Time().

◆ time_

TimeStamp v8::base::Win32Time::time_
private

Definition at line 269 of file platform-win32.cc.

Referenced by ft(), SetToCurrentTime(), and t().


The documentation for this class was generated from the following file: