V8 Project
v8::internal::DateCache Class Reference

#include <date.h>

+ Collaboration diagram for v8::internal::DateCache:

Classes

struct  DST
 

Public Member Functions

 DateCache ()
 
virtual ~DateCache ()
 
void ResetDateCache ()
 
int Weekday (int days)
 
bool IsLeap (int year)
 
int LocalOffsetInMs ()
 
const char * LocalTimezone (int64_t time_ms)
 
int TimezoneOffset (int64_t time_ms)
 
int64_t ToLocal (int64_t time_ms)
 
int64_t ToUTC (int64_t time_ms)
 
int64_t EquivalentTime (int64_t time_ms)
 
int EquivalentYear (int year)
 
void YearMonthDayFromDays (int days, int *year, int *month, int *day)
 
int DaysFromYearMonth (int year, int month)
 
Smistamp ()
 
void * stamp_address ()
 
virtual int GetDaylightSavingsOffsetFromOS (int64_t time_sec)
 
virtual int GetLocalOffsetFromOS ()
 

Static Public Member Functions

static int DaysFromTime (int64_t time_ms)
 
static int TimeInDay (int64_t time_ms, int days)
 

Static Public Attributes

static const int kMsPerMin = 60 * 1000
 
static const int kSecPerDay = 24 * 60 * 60
 
static const int64_t kMsPerDay = kSecPerDay * 1000
 
static const int kMaxEpochTimeInSec = kMaxInt
 
static const int64_t kMaxEpochTimeInMs
 
static const int64_t kMaxTimeInMs
 
static const int64_t kMaxTimeBeforeUTCInMs
 
static const int kInvalidLocalOffsetInMs = kMaxInt
 
static const int kInvalidStamp = -1
 

Private Member Functions

int DaylightSavingsOffsetInMs (int64_t time_ms)
 
void ProbeDST (int time_sec)
 
DSTLeastRecentlyUsedDST (DST *skip)
 
void ExtendTheAfterSegment (int time_sec, int offset_ms)
 
void ClearSegment (DST *segment)
 
bool InvalidSegment (DST *segment)
 

Private Attributes

Smistamp_
 
DST dst_ [kDSTSize]
 
int dst_usage_counter_
 
DSTbefore_
 
DSTafter_
 
int local_offset_ms_
 
bool ymd_valid_
 
int ymd_days_
 
int ymd_year_
 
int ymd_month_
 
int ymd_day_
 
base::TimezoneCachetz_cache_
 

Static Private Attributes

static const int kDefaultDSTDeltaInSec = 19 * kSecPerDay
 
static const int kDSTSize = 32
 

Detailed Description

Definition at line 16 of file date.h.

Constructor & Destructor Documentation

◆ DateCache()

v8::internal::DateCache::DateCache ( )
inline

Definition at line 42 of file date.h.

44  }
static TimezoneCache * CreateTimezoneCache()
void ResetDateCache()
Definition: date.cc:27
base::TimezoneCache * tz_cache_
Definition: date.h:246

References ResetDateCache().

+ Here is the call graph for this function:

◆ ~DateCache()

virtual v8::internal::DateCache::~DateCache ( )
inlinevirtual

Definition at line 46 of file date.h.

46  {
48  tz_cache_ = NULL;
49  }
static void DisposeTimezoneCache(TimezoneCache *cache)
enable harmony numeric enable harmony object literal extensions Optimize object Array DOM strings and string trace pretenuring decisions of HAllocate instructions Enables optimizations which favor memory size over execution speed maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining trace the tracking of allocation sites deoptimize every n garbage collections perform array bounds checks elimination analyze liveness of environment slots and zap dead values flushes the cache of optimized code for closures on every GC allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms do not emit check maps for constant values that have a leaf deoptimize the optimized code if the layout of the maps changes enable context specialization in TurboFan execution budget before interrupt is triggered max percentage of megamorphic generic ICs to allow optimization enable use of SAHF instruction if enable use of VFP3 instructions if available enable use of NEON instructions if enable use of SDIV and UDIV instructions if enable use of MLS instructions if enable loading bit constant by means of movw movt instruction enable unaligned accesses for enable use of d16 d31 registers on ARM this requires VFP3 force all emitted branches to be in long enable alignment of csp to bytes on platforms which prefer the register to always be NULL

References v8::base::OS::DisposeTimezoneCache(), NULL, and tz_cache_.

+ Here is the call graph for this function:

Member Function Documentation

◆ ClearSegment()

void v8::internal::DateCache::ClearSegment ( DST segment)
inlineprivate

Definition at line 47 of file date.cc.

47  {
48  segment->start_sec = kMaxEpochTimeInSec;
49  segment->end_sec = -kMaxEpochTimeInSec;
50  segment->offset_ms = 0;
51  segment->last_used = 0;
52 }
static const int kMaxEpochTimeInSec
Definition: date.h:23

References v8::internal::DateCache::DST::end_sec, kMaxEpochTimeInSec, v8::internal::DateCache::DST::last_used, v8::internal::DateCache::DST::offset_ms, and v8::internal::DateCache::DST::start_sec.

Referenced by DaylightSavingsOffsetInMs(), LeastRecentlyUsedDST(), and ResetDateCache().

+ Here is the caller graph for this function:

◆ DaylightSavingsOffsetInMs()

int v8::internal::DateCache::DaylightSavingsOffsetInMs ( int64_t  time_ms)
private

Definition at line 200 of file date.cc.

200  {
201  int time_sec = (time_ms >= 0 && time_ms <= kMaxEpochTimeInMs)
202  ? static_cast<int>(time_ms / 1000)
203  : static_cast<int>(EquivalentTime(time_ms) / 1000);
204 
205  // Invalidate cache if the usage counter is close to overflow.
206  // Note that dst_usage_counter is incremented less than ten times
207  // in this function.
208  if (dst_usage_counter_ >= kMaxInt - 10) {
209  dst_usage_counter_ = 0;
210  for (int i = 0; i < kDSTSize; ++i) {
211  ClearSegment(&dst_[i]);
212  }
213  }
214 
215  // Optimistic fast check.
216  if (before_->start_sec <= time_sec &&
217  time_sec <= before_->end_sec) {
218  // Cache hit.
220  return before_->offset_ms;
221  }
222 
223  ProbeDST(time_sec);
224 
225  DCHECK(InvalidSegment(before_) || before_->start_sec <= time_sec);
226  DCHECK(InvalidSegment(after_) || time_sec < after_->start_sec);
227 
228  if (InvalidSegment(before_)) {
229  // Cache miss.
230  before_->start_sec = time_sec;
231  before_->end_sec = time_sec;
234  return before_->offset_ms;
235  }
236 
237  if (time_sec <= before_->end_sec) {
238  // Cache hit.
240  return before_->offset_ms;
241  }
242 
243  if (time_sec > before_->end_sec + kDefaultDSTDeltaInSec) {
244  // If the before_ segment ends too early, then just
245  // query for the offset of the time_sec
246  int offset_ms = GetDaylightSavingsOffsetFromOS(time_sec);
247  ExtendTheAfterSegment(time_sec, offset_ms);
248  // This swap helps the optimistic fast check in subsequent invocations.
249  DST* temp = before_;
250  before_ = after_;
251  after_ = temp;
252  return offset_ms;
253  }
254 
255  // Now the time_sec is between
256  // before_->end_sec and before_->end_sec + default DST delta.
257  // Update the usage counter of before_ since it is going to be used.
259 
260  // Check if after_ segment is invalid or starts too late.
261  // Note that start_sec of invalid segments is kMaxEpochTimeInSec.
262  if (before_->end_sec + kDefaultDSTDeltaInSec <= after_->start_sec) {
263  int new_after_start_sec = before_->end_sec + kDefaultDSTDeltaInSec;
264  int new_offset_ms = GetDaylightSavingsOffsetFromOS(new_after_start_sec);
265  ExtendTheAfterSegment(new_after_start_sec, new_offset_ms);
266  } else {
268  // Update the usage counter of after_ since it is going to be used.
270  }
271 
272  // Now the time_sec is between before_->end_sec and after_->start_sec.
273  // Only one daylight savings offset change can occur in this interval.
274 
275  if (before_->offset_ms == after_->offset_ms) {
276  // Merge two segments if they have the same offset.
279  return before_->offset_ms;
280  }
281 
282  // Binary search for daylight savings offset change point,
283  // but give up if we don't find it in four iterations.
284  for (int i = 4; i >= 0; --i) {
285  int delta = after_->start_sec - before_->end_sec;
286  int middle_sec = (i == 0) ? time_sec : before_->end_sec + delta / 2;
287  int offset_ms = GetDaylightSavingsOffsetFromOS(middle_sec);
288  if (before_->offset_ms == offset_ms) {
289  before_->end_sec = middle_sec;
290  if (time_sec <= before_->end_sec) {
291  return offset_ms;
292  }
293  } else {
294  DCHECK(after_->offset_ms == offset_ms);
295  after_->start_sec = middle_sec;
296  if (time_sec >= after_->start_sec) {
297  // This swap helps the optimistic fast check in subsequent invocations.
298  DST* temp = before_;
299  before_ = after_;
300  after_ = temp;
301  return offset_ms;
302  }
303  }
304  }
305  UNREACHABLE();
306  return 0;
307 }
virtual int GetDaylightSavingsOffsetFromOS(int64_t time_sec)
Definition: date.h:171
void ExtendTheAfterSegment(int time_sec, int offset_ms)
Definition: date.cc:180
bool InvalidSegment(DST *segment)
Definition: date.h:225
static const int kDefaultDSTDeltaInSec
Definition: date.h:189
static const int64_t kMaxEpochTimeInMs
Definition: date.h:24
void ProbeDST(int time_sec)
Definition: date.cc:310
DST dst_[kDSTSize]
Definition: date.h:232
static const int kDSTSize
Definition: date.h:192
void ClearSegment(DST *segment)
Definition: date.cc:47
int64_t EquivalentTime(int64_t time_ms)
Definition: date.h:134
#define UNREACHABLE()
Definition: logging.h:30
#define DCHECK(condition)
Definition: logging.h:205
const int kMaxInt
Definition: globals.h:109

References after_, before_, ClearSegment(), DCHECK, dst_, dst_usage_counter_, v8::internal::DateCache::DST::end_sec, EquivalentTime(), ExtendTheAfterSegment(), GetDaylightSavingsOffsetFromOS(), InvalidSegment(), kDefaultDSTDeltaInSec, kDSTSize, kMaxEpochTimeInMs, v8::internal::kMaxInt, v8::internal::DateCache::DST::last_used, v8::internal::DateCache::DST::offset_ms, ProbeDST(), v8::internal::DateCache::DST::start_sec, and UNREACHABLE.

Referenced by ToLocal(), and ToUTC().

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

◆ DaysFromTime()

static int v8::internal::DateCache::DaysFromTime ( int64_t  time_ms)
inlinestatic

Definition at line 57 of file date.h.

57  {
58  if (time_ms < 0) time_ms -= (kMsPerDay - 1);
59  return static_cast<int>(time_ms / kMsPerDay);
60  }
static const int64_t kMsPerDay
Definition: date.h:20

References kMsPerDay.

Referenced by v8::internal::JSDate::DoGetField(), EquivalentTime(), v8::internal::JSDate::GetUTCField(), and v8::internal::JSDate::SetCachedFields().

+ Here is the caller graph for this function:

◆ DaysFromYearMonth()

int v8::internal::DateCache::DaysFromYearMonth ( int  year,
int  month 
)

Definition at line 136 of file date.cc.

136  {
137  static const int day_from_month[] = {0, 31, 59, 90, 120, 151,
138  181, 212, 243, 273, 304, 334};
139  static const int day_from_month_leap[] = {0, 31, 60, 91, 121, 152,
140  182, 213, 244, 274, 305, 335};
141 
142  year += month / 12;
143  month %= 12;
144  if (month < 0) {
145  year--;
146  month += 12;
147  }
148 
149  DCHECK(month >= 0);
150  DCHECK(month < 12);
151 
152  // year_delta is an arbitrary number such that:
153  // a) year_delta = -1 (mod 400)
154  // b) year + year_delta > 0 for years in the range defined by
155  // ECMA 262 - 15.9.1.1, i.e. upto 100,000,000 days on either side of
156  // Jan 1 1970. This is required so that we don't run into integer
157  // division of negative numbers.
158  // c) there shouldn't be an overflow for 32-bit integers in the following
159  // operations.
160  static const int year_delta = 399999;
161  static const int base_day = 365 * (1970 + year_delta) +
162  (1970 + year_delta) / 4 -
163  (1970 + year_delta) / 100 +
164  (1970 + year_delta) / 400;
165 
166  int year1 = year + year_delta;
167  int day_from_year = 365 * year1 +
168  year1 / 4 -
169  year1 / 100 +
170  year1 / 400 -
171  base_day;
172 
173  if ((year % 4 != 0) || (year % 100 == 0 && year % 400 != 0)) {
174  return day_from_year + day_from_month[month];
175  }
176  return day_from_year + day_from_month_leap[month];
177 }

References DCHECK.

Referenced by EquivalentTime(), EquivalentYear(), and YearMonthDayFromDays().

+ Here is the caller graph for this function:

◆ EquivalentTime()

int64_t v8::internal::DateCache::EquivalentTime ( int64_t  time_ms)
inline

Definition at line 134 of file date.h.

134  {
135  int days = DaysFromTime(time_ms);
136  int time_within_day_ms = static_cast<int>(time_ms - days * kMsPerDay);
137  int year, month, day;
138  YearMonthDayFromDays(days, &year, &month, &day);
139  int new_days = DaysFromYearMonth(EquivalentYear(year), month) + day - 1;
140  return static_cast<int64_t>(new_days) * kMsPerDay + time_within_day_ms;
141  }
int EquivalentYear(int year)
Definition: date.h:147
int DaysFromYearMonth(int year, int month)
Definition: date.cc:136
void YearMonthDayFromDays(int days, int *year, int *month, int *day)
Definition: date.cc:55
static int DaysFromTime(int64_t time_ms)
Definition: date.h:57

References DaysFromTime(), DaysFromYearMonth(), EquivalentYear(), kMsPerDay, and YearMonthDayFromDays().

Referenced by DaylightSavingsOffsetInMs(), and LocalTimezone().

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

◆ EquivalentYear()

int v8::internal::DateCache::EquivalentYear ( int  year)
inline

Definition at line 147 of file date.h.

147  {
148  int week_day = Weekday(DaysFromYearMonth(year, 0));
149  int recent_year = (IsLeap(year) ? 1956 : 1967) + (week_day * 12) % 28;
150  // Find the year in the range 2008..2037 that is equivalent mod 28.
151  // Add 3*28 to give a positive argument to the modulus operator.
152  return 2008 + (recent_year + 3 * 28 - 2008) % 28;
153  }
bool IsLeap(int year)
Definition: date.h:78
int Weekday(int days)
Definition: date.h:72

References DaysFromYearMonth(), IsLeap(), and Weekday().

Referenced by EquivalentTime().

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

◆ ExtendTheAfterSegment()

void v8::internal::DateCache::ExtendTheAfterSegment ( int  time_sec,
int  offset_ms 
)
inlineprivate

Definition at line 180 of file date.cc.

180  {
181  if (after_->offset_ms == offset_ms &&
182  after_->start_sec <= time_sec + kDefaultDSTDeltaInSec &&
183  time_sec <= after_->end_sec) {
184  // Extend the after_ segment.
185  after_->start_sec = time_sec;
186  } else {
187  // The after_ segment is either invalid or starts too late.
188  if (after_->start_sec <= after_->end_sec) {
189  // If the after_ segment is valid, replace it with a new segment.
191  }
192  after_->start_sec = time_sec;
193  after_->end_sec = time_sec;
194  after_->offset_ms = offset_ms;
196  }
197 }
DST * LeastRecentlyUsedDST(DST *skip)
Definition: date.cc:350

References after_, before_, dst_usage_counter_, v8::internal::DateCache::DST::end_sec, kDefaultDSTDeltaInSec, v8::internal::DateCache::DST::last_used, LeastRecentlyUsedDST(), v8::internal::DateCache::DST::offset_ms, and v8::internal::DateCache::DST::start_sec.

Referenced by DaylightSavingsOffsetInMs().

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

◆ GetDaylightSavingsOffsetFromOS()

virtual int v8::internal::DateCache::GetDaylightSavingsOffsetFromOS ( int64_t  time_sec)
inlinevirtual

Definition at line 171 of file date.h.

171  {
172  double time_ms = static_cast<double>(time_sec * 1000);
173  return static_cast<int>(
175  }
static double DaylightSavingsOffset(double time, TimezoneCache *cache)

References v8::base::OS::DaylightSavingsOffset(), and tz_cache_.

Referenced by DaylightSavingsOffsetInMs().

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

◆ GetLocalOffsetFromOS()

virtual int v8::internal::DateCache::GetLocalOffsetFromOS ( )
inlinevirtual

Definition at line 177 of file date.h.

177  {
178  double offset = base::OS::LocalTimeOffset(tz_cache_);
180  return static_cast<int>(offset);
181  }
static double LocalTimeOffset(TimezoneCache *cache)
static const int kInvalidLocalOffsetInMs
Definition: date.h:37

References DCHECK, kInvalidLocalOffsetInMs, v8::base::OS::LocalTimeOffset(), and tz_cache_.

Referenced by LocalOffsetInMs().

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

◆ InvalidSegment()

bool v8::internal::DateCache::InvalidSegment ( DST segment)
inlineprivate

Definition at line 225 of file date.h.

225  {
226  return segment->start_sec > segment->end_sec;
227  }

References v8::internal::DateCache::DST::end_sec, and v8::internal::DateCache::DST::start_sec.

Referenced by DaylightSavingsOffsetInMs(), and ProbeDST().

+ Here is the caller graph for this function:

◆ IsLeap()

bool v8::internal::DateCache::IsLeap ( int  year)
inline

Definition at line 78 of file date.h.

78  {
79  return year % 4 == 0 && (year % 100 != 0 || year % 400 == 0);
80  }

Referenced by EquivalentYear().

+ Here is the caller graph for this function:

◆ LeastRecentlyUsedDST()

DateCache::DST * v8::internal::DateCache::LeastRecentlyUsedDST ( DST skip)
private

Definition at line 350 of file date.cc.

350  {
351  DST* result = NULL;
352  for (int i = 0; i < kDSTSize; ++i) {
353  if (&dst_[i] == skip) continue;
354  if (result == NULL || result->last_used > dst_[i].last_used) {
355  result = &dst_[i];
356  }
357  }
358  ClearSegment(result);
359  return result;
360 }

References ClearSegment(), dst_, kDSTSize, v8::internal::DateCache::DST::last_used, and NULL.

Referenced by ExtendTheAfterSegment(), and ProbeDST().

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

◆ LocalOffsetInMs()

int v8::internal::DateCache::LocalOffsetInMs ( )
inline

Definition at line 84 of file date.h.

84  {
87  }
88  return local_offset_ms_;
89  }
virtual int GetLocalOffsetFromOS()
Definition: date.h:177

References GetLocalOffsetFromOS(), kInvalidLocalOffsetInMs, and local_offset_ms_.

Referenced by ToLocal(), and ToUTC().

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

◆ LocalTimezone()

const char* v8::internal::DateCache::LocalTimezone ( int64_t  time_ms)
inline

Definition at line 92 of file date.h.

92  {
93  if (time_ms < 0 || time_ms > kMaxEpochTimeInMs) {
94  time_ms = EquivalentTime(time_ms);
95  }
96  return base::OS::LocalTimezone(static_cast<double>(time_ms), tz_cache_);
97  }
static const char * LocalTimezone(double time, TimezoneCache *cache)

References EquivalentTime(), kMaxEpochTimeInMs, v8::base::OS::LocalTimezone(), and tz_cache_.

+ Here is the call graph for this function:

◆ ProbeDST()

void v8::internal::DateCache::ProbeDST ( int  time_sec)
private

Definition at line 310 of file date.cc.

310  {
311  DST* before = NULL;
312  DST* after = NULL;
313  DCHECK(before_ != after_);
314 
315  for (int i = 0; i < kDSTSize; ++i) {
316  if (dst_[i].start_sec <= time_sec) {
317  if (before == NULL || before->start_sec < dst_[i].start_sec) {
318  before = &dst_[i];
319  }
320  } else if (time_sec < dst_[i].end_sec) {
321  if (after == NULL || after->end_sec > dst_[i].end_sec) {
322  after = &dst_[i];
323  }
324  }
325  }
326 
327  // If before or after segments were not found,
328  // then set them to any invalid segment.
329  if (before == NULL) {
330  before = InvalidSegment(before_) ? before_ : LeastRecentlyUsedDST(after);
331  }
332  if (after == NULL) {
333  after = InvalidSegment(after_) && before != after_
334  ? after_ : LeastRecentlyUsedDST(before);
335  }
336 
337  DCHECK(before != NULL);
338  DCHECK(after != NULL);
339  DCHECK(before != after);
340  DCHECK(InvalidSegment(before) || before->start_sec <= time_sec);
341  DCHECK(InvalidSegment(after) || time_sec < after->start_sec);
342  DCHECK(InvalidSegment(before) || InvalidSegment(after) ||
343  before->end_sec < after->start_sec);
344 
345  before_ = before;
346  after_ = after;
347 }

References after_, before_, DCHECK, dst_, v8::internal::DateCache::DST::end_sec, InvalidSegment(), kDSTSize, LeastRecentlyUsedDST(), NULL, and v8::internal::DateCache::DST::start_sec.

Referenced by DaylightSavingsOffsetInMs().

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

◆ ResetDateCache()

void v8::internal::DateCache::ResetDateCache ( )

Definition at line 27 of file date.cc.

27  {
28  static const int kMaxStamp = Smi::kMaxValue;
29  if (stamp_->value() >= kMaxStamp) {
30  stamp_ = Smi::FromInt(0);
31  } else {
32  stamp_ = Smi::FromInt(stamp_->value() + 1);
33  }
35  for (int i = 0; i < kDSTSize; ++i) {
36  ClearSegment(&dst_[i]);
37  }
39  before_ = &dst_[0];
40  after_ = &dst_[1];
42  ymd_valid_ = false;
44 }
static void ClearTimezoneCache(TimezoneCache *cache)
static const int kInvalidStamp
Definition: date.h:40
static const int kMaxValue
Definition: objects.h:1272
int value() const
Definition: objects-inl.h:1316
static Smi * FromInt(int value)
Definition: objects-inl.h:1321

References after_, before_, ClearSegment(), v8::base::OS::ClearTimezoneCache(), DCHECK, dst_, dst_usage_counter_, v8::internal::Smi::FromInt(), kDSTSize, kInvalidLocalOffsetInMs, kInvalidStamp, v8::internal::Smi::kMaxValue, local_offset_ms_, stamp_, tz_cache_, v8::internal::Smi::value(), and ymd_valid_.

Referenced by DateCache(), and v8::Date::DateTimeConfigurationChangeNotification().

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

◆ stamp()

Smi* v8::internal::DateCache::stamp ( )
inline

Definition at line 167 of file date.h.

167 { return stamp_; }

References stamp_.

Referenced by v8::internal::JSDate::DoGetField(), and v8::internal::JSDate::SetCachedFields().

+ Here is the caller graph for this function:

◆ stamp_address()

void* v8::internal::DateCache::stamp_address ( )
inline

Definition at line 168 of file date.h.

168 { return &stamp_; }

References stamp_.

◆ TimeInDay()

static int v8::internal::DateCache::TimeInDay ( int64_t  time_ms,
int  days 
)
inlinestatic

Definition at line 65 of file date.h.

65  {
66  return static_cast<int>(time_ms - days * kMsPerDay);
67  }

References kMsPerDay.

Referenced by v8::internal::JSDate::DoGetField(), v8::internal::JSDate::GetUTCField(), and v8::internal::JSDate::SetCachedFields().

+ Here is the caller graph for this function:

◆ TimezoneOffset()

int v8::internal::DateCache::TimezoneOffset ( int64_t  time_ms)
inline

Definition at line 100 of file date.h.

100  {
101  int64_t local_ms = ToLocal(time_ms);
102  return static_cast<int>((time_ms - local_ms) / kMsPerMin);
103  }
static const int kMsPerMin
Definition: date.h:18
int64_t ToLocal(int64_t time_ms)
Definition: date.h:110

References kMsPerMin, and ToLocal().

Referenced by v8::internal::JSDate::GetUTCField().

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

◆ ToLocal()

int64_t v8::internal::DateCache::ToLocal ( int64_t  time_ms)
inline

Definition at line 110 of file date.h.

110  {
111  time_ms += LocalOffsetInMs();
112  return time_ms + DaylightSavingsOffsetInMs(time_ms);
113  }
int LocalOffsetInMs()
Definition: date.h:84
int DaylightSavingsOffsetInMs(int64_t time_ms)
Definition: date.cc:200

References DaylightSavingsOffsetInMs(), and LocalOffsetInMs().

Referenced by v8::internal::JSDate::DoGetField(), and TimezoneOffset().

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

◆ ToUTC()

int64_t v8::internal::DateCache::ToUTC ( int64_t  time_ms)
inline

Definition at line 120 of file date.h.

120  {
121  return time_ms - LocalOffsetInMs() - DaylightSavingsOffsetInMs(time_ms);
122  }

References DaylightSavingsOffsetInMs(), and LocalOffsetInMs().

Referenced by v8::internal::RUNTIME_FUNCTION().

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

◆ Weekday()

int v8::internal::DateCache::Weekday ( int  days)
inline

Definition at line 72 of file date.h.

72  {
73  int result = (days + 4) % 7;
74  return result >= 0 ? result : result + 7;
75  }

Referenced by EquivalentYear(), v8::internal::JSDate::GetUTCField(), and v8::internal::JSDate::SetCachedFields().

+ Here is the caller graph for this function:

◆ YearMonthDayFromDays()

void v8::internal::DateCache::YearMonthDayFromDays ( int  days,
int year,
int month,
int day 
)

Definition at line 55 of file date.cc.

56  {
57  if (ymd_valid_) {
58  // Check conservatively if the given 'days' has
59  // the same year and month as the cached 'days'.
60  int new_day = ymd_day_ + (days - ymd_days_);
61  if (new_day >= 1 && new_day <= 28) {
62  ymd_day_ = new_day;
63  ymd_days_ = days;
64  *year = ymd_year_;
65  *month = ymd_month_;
66  *day = new_day;
67  return;
68  }
69  }
70  int save_days = days;
71 
72  days += kDaysOffset;
73  *year = 400 * (days / kDaysIn400Years) - kYearsOffset;
74  days %= kDaysIn400Years;
75 
76  DCHECK(DaysFromYearMonth(*year, 0) + days == save_days);
77 
78  days--;
79  int yd1 = days / kDaysIn100Years;
80  days %= kDaysIn100Years;
81  *year += 100 * yd1;
82 
83  days++;
84  int yd2 = days / kDaysIn4Years;
85  days %= kDaysIn4Years;
86  *year += 4 * yd2;
87 
88  days--;
89  int yd3 = days / 365;
90  days %= 365;
91  *year += yd3;
92 
93 
94  bool is_leap = (!yd1 || yd2) && !yd3;
95 
96  DCHECK(days >= -1);
97  DCHECK(is_leap || (days >= 0));
98  DCHECK((days < 365) || (is_leap && (days < 366)));
99  DCHECK(is_leap == ((*year % 4 == 0) && (*year % 100 || (*year % 400 == 0))));
100  DCHECK(is_leap || ((DaysFromYearMonth(*year, 0) + days) == save_days));
101  DCHECK(!is_leap || ((DaysFromYearMonth(*year, 0) + days + 1) == save_days));
102 
103  days += is_leap;
104 
105  // Check if the date is after February.
106  if (days >= 31 + 28 + is_leap) {
107  days -= 31 + 28 + is_leap;
108  // Find the date starting from March.
109  for (int i = 2; i < 12; i++) {
110  if (days < kDaysInMonths[i]) {
111  *month = i;
112  *day = days + 1;
113  break;
114  }
115  days -= kDaysInMonths[i];
116  }
117  } else {
118  // Check January and February.
119  if (days < 31) {
120  *month = 0;
121  *day = days + 1;
122  } else {
123  *month = 1;
124  *day = days - 31 + 1;
125  }
126  }
127  DCHECK(DaysFromYearMonth(*year, *month) + *day - 1 == save_days);
128  ymd_valid_ = true;
129  ymd_year_ = *year;
130  ymd_month_ = *month;
131  ymd_day_ = *day;
132  ymd_days_ = save_days;
133 }
static const int kDaysOffset
Definition: date.cc:20
static const char kDaysInMonths[]
Definition: date.cc:23
static const int kDaysIn4Years
Definition: date.cc:16
static const int kDaysIn100Years
Definition: date.cc:17
static const int kYearsOffset
Definition: date.cc:22
static const int kDaysIn400Years
Definition: date.cc:18

References DaysFromYearMonth(), DCHECK, v8::internal::kDaysIn100Years, v8::internal::kDaysIn400Years, v8::internal::kDaysIn4Years, v8::internal::kDaysInMonths, v8::internal::kDaysOffset, v8::internal::kYearsOffset, ymd_day_, ymd_days_, ymd_month_, ymd_valid_, and ymd_year_.

Referenced by EquivalentTime(), v8::internal::JSDate::GetUTCField(), and v8::internal::JSDate::SetCachedFields().

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

Member Data Documentation

◆ after_

DST* v8::internal::DateCache::after_
private

Definition at line 235 of file date.h.

Referenced by DaylightSavingsOffsetInMs(), ExtendTheAfterSegment(), ProbeDST(), and ResetDateCache().

◆ before_

DST* v8::internal::DateCache::before_
private

Definition at line 234 of file date.h.

Referenced by DaylightSavingsOffsetInMs(), ExtendTheAfterSegment(), ProbeDST(), and ResetDateCache().

◆ dst_

DST v8::internal::DateCache::dst_[kDSTSize]
private

Definition at line 232 of file date.h.

Referenced by DaylightSavingsOffsetInMs(), LeastRecentlyUsedDST(), ProbeDST(), and ResetDateCache().

◆ dst_usage_counter_

int v8::internal::DateCache::dst_usage_counter_
private

Definition at line 233 of file date.h.

Referenced by DaylightSavingsOffsetInMs(), ExtendTheAfterSegment(), and ResetDateCache().

◆ kDefaultDSTDeltaInSec

const int v8::internal::DateCache::kDefaultDSTDeltaInSec = 19 * kSecPerDay
staticprivate

Definition at line 189 of file date.h.

Referenced by DaylightSavingsOffsetInMs(), and ExtendTheAfterSegment().

◆ kDSTSize

const int v8::internal::DateCache::kDSTSize = 32
staticprivate

Definition at line 192 of file date.h.

Referenced by DaylightSavingsOffsetInMs(), LeastRecentlyUsedDST(), ProbeDST(), and ResetDateCache().

◆ kInvalidLocalOffsetInMs

const int v8::internal::DateCache::kInvalidLocalOffsetInMs = kMaxInt
static

Definition at line 37 of file date.h.

Referenced by GetLocalOffsetFromOS(), LocalOffsetInMs(), and ResetDateCache().

◆ kInvalidStamp

const int v8::internal::DateCache::kInvalidStamp = -1
static

Definition at line 40 of file date.h.

Referenced by ResetDateCache(), and v8::internal::JSDate::SetValue().

◆ kMaxEpochTimeInMs

const int64_t v8::internal::DateCache::kMaxEpochTimeInMs
static
Initial value:
=
static_cast<int64_t>(kMaxInt) * 1000

Definition at line 24 of file date.h.

Referenced by DaylightSavingsOffsetInMs(), and LocalTimezone().

◆ kMaxEpochTimeInSec

const int v8::internal::DateCache::kMaxEpochTimeInSec = kMaxInt
static

Definition at line 23 of file date.h.

Referenced by ClearSegment().

◆ kMaxTimeBeforeUTCInMs

const int64_t v8::internal::DateCache::kMaxTimeBeforeUTCInMs
static
Initial value:
=
static const int64_t kMaxTimeInMs
Definition: date.h:28

Definition at line 33 of file date.h.

Referenced by v8::internal::RUNTIME_FUNCTION().

◆ kMaxTimeInMs

const int64_t v8::internal::DateCache::kMaxTimeInMs
static
Initial value:
=
static_cast<int64_t>(864000000) * 10000000

Definition at line 28 of file date.h.

Referenced by v8::internal::RUNTIME_FUNCTION().

◆ kMsPerDay

const int64_t v8::internal::DateCache::kMsPerDay = kSecPerDay * 1000
static

Definition at line 20 of file date.h.

Referenced by DaysFromTime(), EquivalentTime(), and TimeInDay().

◆ kMsPerMin

const int v8::internal::DateCache::kMsPerMin = 60 * 1000
static

Definition at line 18 of file date.h.

Referenced by TimezoneOffset().

◆ kSecPerDay

const int v8::internal::DateCache::kSecPerDay = 24 * 60 * 60
static

Definition at line 19 of file date.h.

◆ local_offset_ms_

int v8::internal::DateCache::local_offset_ms_
private

Definition at line 237 of file date.h.

Referenced by LocalOffsetInMs(), and ResetDateCache().

◆ stamp_

Smi* v8::internal::DateCache::stamp_
private

Definition at line 229 of file date.h.

Referenced by ResetDateCache(), stamp(), and stamp_address().

◆ tz_cache_

base::TimezoneCache* v8::internal::DateCache::tz_cache_
private

◆ ymd_day_

int v8::internal::DateCache::ymd_day_
private

Definition at line 244 of file date.h.

Referenced by YearMonthDayFromDays().

◆ ymd_days_

int v8::internal::DateCache::ymd_days_
private

Definition at line 241 of file date.h.

Referenced by YearMonthDayFromDays().

◆ ymd_month_

int v8::internal::DateCache::ymd_month_
private

Definition at line 243 of file date.h.

Referenced by YearMonthDayFromDays().

◆ ymd_valid_

bool v8::internal::DateCache::ymd_valid_
private

Definition at line 240 of file date.h.

Referenced by ResetDateCache(), and YearMonthDayFromDays().

◆ ymd_year_

int v8::internal::DateCache::ymd_year_
private

Definition at line 242 of file date.h.

Referenced by YearMonthDayFromDays().


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